emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] seeking good practices for writing about org using org


From: Cook, Malcolm
Subject: Re: [O] seeking good practices for writing about org using org
Date: Thu, 4 Aug 2016 20:56:18 +0000

Hi Charles,

 

> On Wed, 3 Aug 2016, Cook, Malcolm wrote:

>

 > > Thanks.  Much closer.  Still some issues.  Mind taking another

> > gander....  (hoping the attached jpeg of the webpage rendered comes

> > through as an attachment)....

> >

> > If my emacs buffer holds...

> > ----------------------------------------------

> > #+BEGIN_SRC org :exports both :results value ascii

>

 > ...............................................^^^^^

>

 > what is the `ascii' doing?

>

 > Can you provide a link to documentation in the manual or a

> docstring describing its function?

 

I cannot!  I learned this from reading the code.  In ob-org.el we find provision for this  as well as `html' and `latex'

 

(defun org-babel-execute:org (body params)

  "Execute a block of Org code with.

This function is called by `org-babel-execute-src-block'."

  (let ((result-params (split-string (or (cdr (assoc :results params)) "")))

                (body (org-babel-expand-body:org

                       (replace-regexp-in-string "^," "" body) params)))

    (cond

     ((member "latex" result-params)

      (org-export-string-as (concat "#+Title: \n" body) 'latex t))

     ((member "html" result-params) (org-export-string-as  body 'html t))

     ((member "ascii" result-params) (org-export-string-as body 'ascii t))

     (t body)

     )))

 

 

This is all undocumented.  I think it is a 'nod in the direction' of what I am trying to accomplish, allowing to see as "results" the org markup transcoded into the markup of a backend.  See below for my hack extension on this idea.

 

>

 > Why don't you have 'replace' in the :results args?

 

Oops.  Of course.  While trying to understand all this, I had done this to similar effect instead:

 

(setq  org-babel-default-header-args:org nil) ; fix bug? NOT silent

 

 

> >

> > ,* Acknowledgments

>

 > This bit behaves as you might expect in plain text export, markdown, and

> latex export:

>

 > >  [[mailto:address@hidden][my wife]]

>

 > but in html it does create `<a href="">

>

 > That is because of what `org-babel-exp-code-template' leads

> `org-html-src-block' to do. You might try dropping `%lang' from the

> template, but a better solution is to rewrite `org-html-src-block' and

> create a derived exporter.

>

 >

 > >

> > ,* Chapter one

> >

> > Fa la la ls

> >

> > ,* Chapter two

> >

> > La di di

> >

> > ,* Finally, here is a table of contents!

> >

> > ,#+TOC:

>

 > What does this idiom do?

>

 > Precisely, where does the documentation say what

>

 > #+TOC:

>

 > read as "<hash> <plus> T O C <colon> <newline>"

>

 > should create??

 

I though (apparently incorrectly) it was the same as `#+TOC: headlines 2' which does contrive to relocate a Table of Contents to that location.

 

> ---

>

 > Re your next post, I suggest spending some time reading

>

 > (info "(org) results")

>

 > to grasp what the various options actually do. It is probably a good idea

> to execute src blocks to see the RESULTS before you try to export them.

>

 > Reading

>

 > (info "(org) wrap")

>

 > might also help and certainly a quick breeze thru

>

 > (info "(org) Specific header arguments")

>

 > to remind yourself of what all the possibilities are is something I have

> to do from time to time.

 

Thanks for these suggestions.  I have had better results after doing so.

 

I played with extending org-babel-execute:org to allow including MULTIPLE transcoded markdown results using screwy variant syntax of `:results  +ascii +html +latex` with some success.

 

For example, `:results +ascii +latex’ exported html which renders as:

 

 

I now think perhaps I want additional options on a source block allowing to be included in the exported RESULTS:

  1) transcoded markdown, appropriately escaped for the current backend

  1) the source block itself (including the #+BEGIN/END directives)  (as distinct from :results code, which omits the directives)

 

Injecting this kind of logic into org-babel-execute:org  as I did is mis-placing the logic and only muddles further my thinking about this.

 

FWIW - here is the re-definition, if you care to play with or critique it.

 

(defun org-babel-execute:org (body params)

  "Execute a block of Org code with.

This function is called by `org-babel-execute-src-block'."

  (let* ((result-params (split-string (or (cdr (assoc :results params)) "")))

                (body (org-babel-expand-body:org

                                (replace-regexp-in-string "^," "" body) params))

                (val (cond

                       ((member "latex" result-params)

                                (org-export-string-as (concat "#+Title: \n" body) 'latex t))

                       ((member "html" result-params) (org-export-string-as  body 'html t))

                       ((member "ascii" result-params) (org-export-string-as body 'ascii t))

                       (t body)

                       )))

    ;; HACK: output protected versions of each of latex,html,ascii,md transcoded markup as requested with +{latex,html,ascii,md} in header-args

    (when (member "+latex" result-params)

      (setq val (format "#+BEGIN_EXAMPLE\n%s\n#+END_EXAMPLE\n%s" (org-export-string-as  body 'latex t) val)))

    (when (member "+html" result-params)

      (setq val (format "#+BEGIN_EXAMPLE\n%s\n#+END_EXAMPLE\n%s" (org-export-string-as  body 'html t) val)))

    (when (member "+ascii" result-params)

      (setq val (format "#+BEGIN_EXAMPLE\n%s\n#+END_EXAMPLE\n%s" (org-export-string-as  body 'ascii t) val)))

    (when (member "+md" result-params)

      (setq val (format "#+BEGIN_EXAMPLE\n%s\n#+END_EXAMPLE\n%s" (org-export-string-as  body 'md t) val)))

    val)

)

 

Cheers,

 

Malcolm

 

>

 > HTH,

>

 > Chuck


reply via email to

[Prev in Thread] Current Thread [Next in Thread]