emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] :noweb header argument


From: Thomas S. Dye
Subject: Re: [O] :noweb header argument
Date: Sat, 14 Jan 2012 13:06:13 -1000

Eric Schulte <address@hidden> writes:

>>>> As I recall this was originally implemented and then later removed because
>>>> it was causing more confusion and problems than it was worth. I hope it
>>>> hasn't crossed the line of existence more than once. At some point it
>>>> should be placed behind a user-customizable variable, preferably something
>>>> like `org-babel-export-code-format' which defaults to something like
>>>> "%code" but could be augmented to something like "Block Name: *%name*\n
>>>> %code". It is not immediately clear if such a variable should have
>>>> different values for different export backends or (likely preferable)
>>>> should expand into Org-mode text *before* export.
>>>
>>> I think you're right about getting this done early in the process. I've been
>>> thinking only about LaTeX export because that is my immediate goal--not a
>>> good design perspective.
>>>
>
> I've just pushed up a minor code change which makes customization of the
> format of exported code blocks possible.  I've added a new customization
> variable named `org-babel-exp-code-template' which can be used to
> specify the text which replaces code block bodies during export.  The
> default value of this variable specifies the existing export behavior.
> The attached Org-mode file demonstrates this variable in action.
>
>
> #+Title: Custom code block export formats
>
> - Example code block
>   #+Name: foo
>   #+BEGIN_SRC sh :bar baz
>     echo qux
>   #+END_SRC
>
> - Evaluate this block to export (shows the export of the name).
>   #+Name: do-export-name
>   #+BEGIN_SRC emacs-lisp :results silent
>     (let ((org-babel-exp-code-template
>            "\n=%name=:\n#+BEGIN_SRC %lang%flags\n%body\n#+END_SRC"))
>       (org-export-as-html nil))
>   #+END_SRC
>
> - Evaluate this block to export (shows the export of header arguments).
>   #+Name: do-export-header-arguments
>   #+BEGIN_SRC emacs-lisp :results silent
>     (let ((org-babel-exp-code-template
>            "Header arguments for =%name=.
>     | header  | value    |
>     |---------+----------|
>     | bar     | %bar     |
>     | results | %results |\n#+BEGIN_SRC %lang%flags\n%body\n#+END_SRC"))
>       (org-export-as-html nil))
>   #+END_SRC
>
>
> I imagine that this variable would likely be customized on a
> file-by-file basis using "file local variables".
>
>>>
>>> Perhaps I could help by specifying what I'm trying to do? I'd like to write
>>> an article or book about particular statistical analyses. I want this also
>>> to be a piece of reproducible research so readers of the book can follow
>>> along and perhaps analyze data of their own. I'd like to write a code block
>>> once and then use it in the following ways: 1) evaluate and return the
>>> results of analyses; 2) export as a floating listing so I can refer to it in
>>> discussions of implementation; and 3) tangle to a source code file that can
>>> be used as the basis for a package that can be used outside of Org mode.
>>>
>
> Sounds like a very cool project.  If this will be public I would love to
> link to it from [1] when it is complete.
>
>>>
>>> 1) is easy with #+call: With the :wrap header argument that we've
>>> partially implemented, I can mark the results off in whatever environment I
>>> like, which is a wonderful bit of flexibility. Different kinds of results
>>> can be presented distinctively.
>>>
>>> 2) is partially there--the code itself is handled nicely by minted and
>>> I'm able to make it look as good as I want. What I'm lacking now is an easy
>>> way to identify the code block. Seb's suggestion that the header lines be
>>> included is one way, though Eric F.'s point about the special characters
>>> tripping up LaTeX is well taken. It might be some work to get an
>>> intermediate representation that can be exported to all the targets. My
>>> alternate idea, which is to wrap the code block in an environment to which I
>>> can attach a caption and a label, is the LaTeX approach and might not work
>>> as well for other export targets.
>
> This new solution replaces the code block with Org-mode text before
> export.  This should be the most flexible as arbitrary #+HTML and
> #+LATEX lines can be used in Org-mode.
>
> Best,
>
> Footnotes: 
> [1]  http://orgmode.org/worg/org-contrib/babel/uses.html

Hi Eric,

Many thanks.  This works like a charm.  It is deeply satisfying to find
my code block names in the book's "List of listings".

I really appreciate your attention to these details.

All the best,
Tom


-- 
Thomas S. Dye
http://www.tsdye.com



reply via email to

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