* [babel] Including TikZ diagrams as figures in export
@ 2011-02-20 23:03 Jeffrey Horn
2011-02-21 1:56 ` Erik Iverson
0 siblings, 1 reply; 7+ messages in thread
From: Jeffrey Horn @ 2011-02-20 23:03 UTC (permalink / raw
To: Org-mode ml
Hey orgsters,
I'm having a hard time fitting TikZ into my workflow. I spent a little time learning TikZ recently and have all the diagrams working in a tex file.
Now, I'd like to integrate them into an org document. I'd like:
1) To use babel to handle the TikZ source
2) To wrap the resulting drawing in a figure environment for automatic numbering and centering
3) To be able to refer to the figure elsewhere in the document
4) (optional) To be able to seamlessly export to both LaTeX and HTML
I don't really care about 4 right now, but the others are frustrating me a bit. I expected this would do what I wanted:
#+caption: This is a figure.
#+label: fig:ref
#+begin_src latex
<<TikZ source goes here>>
#+end_src
No dice. I get all sorts of unresolved references, no figures, no centering. I'm guess the exporter doesn't know how to integrate TikZ graphics with the #+caption and #+label options. I could create a separate file for holding my diagrams and use babel to spit them out as files, or just use LaTeX and forget about org, but I'd rather not.
So I googled around, thought I had an answer, then tried this:
#+source: a-name
#+begin_src latex
<<TikZ source goes here>>
#+end_src
#+caption: This is a figure.
#+label: fig:ref
#+begin_src emacs-lisp :var path=a-name :results latex
(format "input{%s}" path) #+end_src
I'm not getting what I expect. What do I need to do differently?
And somewhat unrelated, is ":results" now deprecated in favor of ":exports"? What about ":file"? I'm sufficiently new to babel that these all seem like they could be taken care of with a single header argument with many options...
Thanks for the help!
--
Jeffrey Horn
http://www.failuretorefrain.com/jeff/
Sent with Sparrow
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [babel] Including TikZ diagrams as figures in export
2011-02-20 23:03 [babel] Including TikZ diagrams as figures in export Jeffrey Horn
@ 2011-02-21 1:56 ` Erik Iverson
2011-02-21 15:11 ` Jeff Horn
2011-02-21 16:44 ` Andreas Leha
0 siblings, 2 replies; 7+ messages in thread
From: Erik Iverson @ 2011-02-21 1:56 UTC (permalink / raw
To: Jeffrey Horn; +Cc: Org-mode ml
Jeffrey,
> Now, I'd like to integrate them into an org document. I'd like:
> 1) To use babel to handle the TikZ source
This is possible.
> 2) To wrap the resulting drawing in a figure environment for automatic numbering and centering
See http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html and
search for "tikz" for an example. I think you do need to use the :file argument
for this to have org-mode take care of it automatically.
Alternatively, you could just include *all* the latex you want, including
constructing your own figure environment and caption and refs, in the latex
code block.
> 3) To be able to refer to the figure elsewhere in the document
Should be possible with either approach above.
> 4) (optional) To be able to seamlessly export to both LaTeX and HTML
So should the HTML exporter generate a PNG file then, as opposed to PDF?
This is possible, but requires some 'conditional' elisp code in your :file
source block argument. I think I can help if that's indeed what you want.
> And somewhat unrelated, is ":results" now deprecated in favor of ":exports"? What about ":file"? I'm sufficiently new to babel that these all seem like they could be taken care of with a single header argument with many options...
Not deprecated at all according to my understanding:
:results determines how the results are collected from a process. So, in R, we
might want the standard output ':results output' or we might just want the last
value returned by the code block, ':results value'. This determines what is
inserted into the org-mode buffer or the export stream when the code block
is evaluated.
:exports determines if the code and/or the results will be inserted upon
exporting. *If* the results are inserted, then :results will determine how.
:file is useful for code blocks that generate graphical output, such as tikz.
This will divert the output into the named file, and exporting will insert
that file. In the org-mode buffer, a link will be inserted. If a png file is
generated, it can even be displayed inline in the org-mode buffer if you turn
on that functionality.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [babel] Including TikZ diagrams as figures in export
2011-02-21 1:56 ` Erik Iverson
@ 2011-02-21 15:11 ` Jeff Horn
2011-02-21 16:57 ` Eric Schulte
2011-02-21 16:44 ` Andreas Leha
1 sibling, 1 reply; 7+ messages in thread
From: Jeff Horn @ 2011-02-21 15:11 UTC (permalink / raw
To: Erik Iverson; +Cc: Org-mode ml
On Sun, Feb 20, 2011 at 8:56 PM, Erik Iverson <eriki@ccbr.umn.edu> wrote:
> See http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html
> and search for "tikz" for an example. I think you do need to use the :file
> argument
> for this to have org-mode take care of it automatically.
Thanks for the link. I was glad to find out I could include a TikZ
library in the code block instead of the LaTeX header!
> Alternatively, you could just include *all* the latex you want, including
> constructing your own figure environment and caption and refs, in the latex
> code block.
This is the workaround I've used thus far. I don't like it very much,
since it is fragile w.r.t. HTML export.
>> 4) (optional) To be able to seamlessly export to both LaTeX and HTML
>
> So should the HTML exporter generate a PNG file then, as opposed to PDF?
> This is possible, but requires some 'conditional' elisp code in your :file
> source block argument. I think I can help if that's indeed what you want.
This would be handy information to have, but definitely not a top
priority ATM. (That is, if you're busy, feel free to put this on low
priority!)
>> And somewhat unrelated, is ":results" now deprecated in favor of
>> ":exports"? What about ":file"? I'm sufficiently new to babel that these all
>> seem like they could be taken care of with a single header argument with
>> many options...
>
> Not deprecated at all according to my understanding:
>
> :results determines how the results are collected from a process. So, in R,
> we
> might want the standard output ':results output' or we might just want the
> last
> value returned by the code block, ':results value'. This determines what is
> inserted into the org-mode buffer or the export stream when the code block
> is evaluated.
>
> :exports determines if the code and/or the results will be inserted upon
> exporting. *If* the results are inserted, then :results will determine how.
>
> :file is useful for code blocks that generate graphical output, such as
> tikz.
> This will divert the output into the named file, and exporting will insert
> that file. In the org-mode buffer, a link will be inserted. If a png file
> is
> generated, it can even be displayed inline in the org-mode buffer if you
> turn
> on that functionality.
This was also extremely helpful in clarifying my thinking. I
particularly liked the interplay between exports/results. I need more
practice, and more time with the docs. :)
Jeff
--
Jeffrey Horn
http://www.failuretorefrain.com/jeff/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [babel] Including TikZ diagrams as figures in export
2011-02-21 1:56 ` Erik Iverson
2011-02-21 15:11 ` Jeff Horn
@ 2011-02-21 16:44 ` Andreas Leha
2011-02-21 19:29 ` Jeff Horn
1 sibling, 1 reply; 7+ messages in thread
From: Andreas Leha @ 2011-02-21 16:44 UTC (permalink / raw
To: Erik Iverson, emacs-orgmode
[-- Attachment #1.1.1: Type: text/plain, Size: 2730 bytes --]
Hi Jeffrey,
the attached sample file works for me.
The html is only sub-optimal, though, as it just includes a link to a
pdf file.
Cheers,
Andreas
Am 21.02.2011 02:56, schrieb Erik Iverson:
> Jeffrey,
>
>> Now, I'd like to integrate them into an org document. I'd like:
>> 1) To use babel to handle the TikZ source
>
> This is possible.
>
>> 2) To wrap the resulting drawing in a figure environment for
>> automatic numbering and centering
>
> See
> http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html
> and search for "tikz" for an example. I think you do need to use the
> :file argument
> for this to have org-mode take care of it automatically.
>
> Alternatively, you could just include *all* the latex you want, including
> constructing your own figure environment and caption and refs, in the
> latex
> code block.
>
>> 3) To be able to refer to the figure elsewhere in the document
>
> Should be possible with either approach above.
>
>> 4) (optional) To be able to seamlessly export to both LaTeX and HTML
>
> So should the HTML exporter generate a PNG file then, as opposed to PDF?
> This is possible, but requires some 'conditional' elisp code in your
> :file
> source block argument. I think I can help if that's indeed what you
> want.
>
>> And somewhat unrelated, is ":results" now deprecated in favor of
>> ":exports"? What about ":file"? I'm sufficiently new to babel that
>> these all seem like they could be taken care of with a single header
>> argument with many options...
>
> Not deprecated at all according to my understanding:
>
> :results determines how the results are collected from a process. So,
> in R, we
> might want the standard output ':results output' or we might just want
> the last
> value returned by the code block, ':results value'. This determines
> what is
> inserted into the org-mode buffer or the export stream when the code
> block
> is evaluated.
>
> :exports determines if the code and/or the results will be inserted upon
> exporting. *If* the results are inserted, then :results will determine
> how.
>
> :file is useful for code blocks that generate graphical output, such
> as tikz.
> This will divert the output into the named file, and exporting will
> insert
> that file. In the org-mode buffer, a link will be inserted. If a png
> file is
> generated, it can even be displayed inline in the org-mode buffer if
> you turn
> on that functionality.
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
[-- Attachment #1.1.2: tikz_sample.org --]
[-- Type: text/plain, Size: 1083 bytes --]
#+LATEX_HEADER: \usepackage{tikz}
* Tikz Sample
In figure \ref{fig:tikz_sample} you can see something.
#+srcname: tikz_sample
#+begin_src latex :exports (if (eq backend 'latex) "none" "results") :file tikz_sample.pdf :headers '("\\usepackage{tikz}")
\usetikzlibrary{arrows}
\tikzstyle{int}=[draw, fill=blue!20, minimum size=2em]
\tikzstyle{init} = [pin edge={to-,thin,black}]
\begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
\node [int, pin={[init]above:$v_0$}] (a) {$\frac{1}{s}$};
\node (b) [left of=a,node distance=2cm, coordinate] {a};
\node [int, pin={[init]above:$p_0$}] (c) [right of=a] {$\frac{1}{s}$};
\node [coordinate] (end) [right of=c, node distance=2cm]{};
\path[->] (b) edge node {$a$} (a);
\path[->] (a) edge node {$v$} (c);
\draw[->] (c) edge node {$p$} (end) ;
\end{tikzpicture}
#+end_src
#+begin_src latex :noweb yes
\begin{figure}
\centering
<<tikz_sample>>
\caption[Tikz]{Tikz}\label{fig:tikz_sample}
\end{figure}
#+end_src
[-- Attachment #1.2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 6432 bytes --]
[-- Attachment #2: Type: text/plain, Size: 201 bytes --]
_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [babel] Including TikZ diagrams as figures in export
2011-02-21 15:11 ` Jeff Horn
@ 2011-02-21 16:57 ` Eric Schulte
2011-02-21 19:27 ` Jeff Horn
0 siblings, 1 reply; 7+ messages in thread
From: Eric Schulte @ 2011-02-21 16:57 UTC (permalink / raw
To: Jeff Horn; +Cc: Org-mode ml
Jeff Horn <jrhorn424@gmail.com> writes:
> On Sun, Feb 20, 2011 at 8:56 PM, Erik Iverson <eriki@ccbr.umn.edu> wrote:
>> See http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html
>> and search for "tikz" for an example. I think you do need to use the :file
>> argument
>> for this to have org-mode take care of it automatically.
>
> Thanks for the link. I was glad to find out I could include a TikZ
> library in the code block instead of the LaTeX header!
>
>> Alternatively, you could just include *all* the latex you want, including
>> constructing your own figure environment and caption and refs, in the latex
>> code block.
>
> This is the workaround I've used thus far. I don't like it very much,
> since it is fragile w.r.t. HTML export.
>
I agree this is not ideal. The solution here is for the Org-mode
exporter to recognize blocks as figure-wrapable items. This would solve
the above, as well as make it possible to reference exported source
code, verbatim environments, quotes, etc...
I haven't looked at the org exporter to see how large of a change this
would be, however I'll put this on my growing TODO list.
>
>>> 4) (optional) To be able to seamlessly export to both LaTeX and HTML
>>
>> So should the HTML exporter generate a PNG file then, as opposed to PDF?
>> This is possible, but requires some 'conditional' elisp code in your :file
>> source block argument. I think I can help if that's indeed what you want.
>
> This would be handy information to have, but definitely not a top
> priority ATM. (That is, if you're busy, feel free to put this on low
> priority!)
>
>>> And somewhat unrelated, is ":results" now deprecated in favor of
>>> ":exports"? What about ":file"? I'm sufficiently new to babel that these all
>>> seem like they could be taken care of with a single header argument with
>>> many options...
>>
>> Not deprecated at all according to my understanding:
>>
:results is not deprecated, the Org manual maintains an up-to-date list
of code block header arguments.
http://orgmode.org/manual/Working-With-Source-Code.html
Cheers -- Eric
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [babel] Including TikZ diagrams as figures in export
2011-02-21 16:57 ` Eric Schulte
@ 2011-02-21 19:27 ` Jeff Horn
0 siblings, 0 replies; 7+ messages in thread
From: Jeff Horn @ 2011-02-21 19:27 UTC (permalink / raw
To: Eric Schulte; +Cc: Org-mode ml
On Mon, Feb 21, 2011 at 11:57 AM, Eric Schulte <schulte.eric@gmail.com> wrote:
> :results is not deprecated, the Org manual maintains an up-to-date list
> of code block header arguments.
> http://orgmode.org/manual/Working-With-Source-Code.html
Thanks for your eternal patience, with regard to me RTFM. Google
search for org mode are a reflex now, since Worg usually has specific
use examples (sometimes good blog posts turn up, too). But searching
for "org mode babel" usually makes my head spin.
I really dig literate research, but am mostly ignorant of the
techniques, so its hard for to know what to search "for". But, headers
are an example where I could have easily found the answer if I read
the manual.
--
Jeffrey Horn
http://www.failuretorefrain.com/jeff/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [babel] Including TikZ diagrams as figures in export
2011-02-21 16:44 ` Andreas Leha
@ 2011-02-21 19:29 ` Jeff Horn
0 siblings, 0 replies; 7+ messages in thread
From: Jeff Horn @ 2011-02-21 19:29 UTC (permalink / raw
To: Andreas Leha; +Cc: emacs-orgmode
Andreas,
Thanks for the example. I particularly like the use of the noweb to
make the blocks work together. I'll adopt this technique until the
exporter is modified (no rush, Eric!). This is a great workable
solution.
Jeff
On Mon, Feb 21, 2011 at 11:44 AM, Andreas Leha
<andreas.leha@med.uni-goettingen.de> wrote:
> Hi Jeffrey,
>
> the attached sample file works for me.
>
> The html is only sub-optimal, though, as it just includes a link to a
> pdf file.
>
> Cheers,
> Andreas
>
>
>
> Am 21.02.2011 02:56, schrieb Erik Iverson:
>> Jeffrey,
>>
>>> Now, I'd like to integrate them into an org document. I'd like:
>>> 1) To use babel to handle the TikZ source
>>
>> This is possible.
>>
>>> 2) To wrap the resulting drawing in a figure environment for
>>> automatic numbering and centering
>>
>> See
>> http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html
>> and search for "tikz" for an example. I think you do need to use the
>> :file argument
>> for this to have org-mode take care of it automatically.
>>
>> Alternatively, you could just include *all* the latex you want, including
>> constructing your own figure environment and caption and refs, in the
>> latex
>> code block.
>>
>>> 3) To be able to refer to the figure elsewhere in the document
>>
>> Should be possible with either approach above.
>>
>>> 4) (optional) To be able to seamlessly export to both LaTeX and HTML
>>
>> So should the HTML exporter generate a PNG file then, as opposed to PDF?
>> This is possible, but requires some 'conditional' elisp code in your
>> :file
>> source block argument. I think I can help if that's indeed what you
>> want.
>>
>>> And somewhat unrelated, is ":results" now deprecated in favor of
>>> ":exports"? What about ":file"? I'm sufficiently new to babel that
>>> these all seem like they could be taken care of with a single header
>>> argument with many options...
>>
>> Not deprecated at all according to my understanding:
>>
>> :results determines how the results are collected from a process. So,
>> in R, we
>> might want the standard output ':results output' or we might just want
>> the last
>> value returned by the code block, ':results value'. This determines
>> what is
>> inserted into the org-mode buffer or the export stream when the code
>> block
>> is evaluated.
>>
>> :exports determines if the code and/or the results will be inserted upon
>> exporting. *If* the results are inserted, then :results will determine
>> how.
>>
>> :file is useful for code blocks that generate graphical output, such
>> as tikz.
>> This will divert the output into the named file, and exporting will
>> insert
>> that file. In the org-mode buffer, a link will be inserted. If a png
>> file is
>> generated, it can even be displayed inline in the org-mode buffer if
>> you turn
>> on that functionality.
>>
>>
>> _______________________________________________
>> Emacs-orgmode mailing list
>> Please use `Reply All' to send replies to the list.
>> Emacs-orgmode@gnu.org
>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>
>
--
Jeffrey Horn
http://www.failuretorefrain.com/jeff/
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-02-21 19:30 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-20 23:03 [babel] Including TikZ diagrams as figures in export Jeffrey Horn
2011-02-21 1:56 ` Erik Iverson
2011-02-21 15:11 ` Jeff Horn
2011-02-21 16:57 ` Eric Schulte
2011-02-21 19:27 ` Jeff Horn
2011-02-21 16:44 ` Andreas Leha
2011-02-21 19:29 ` Jeff Horn
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.