emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Problems with LaTeX source block
@ 2013-07-15  8:34 Julien Cubizolles
  2013-07-15  8:57 ` Andreas Leha
  0 siblings, 1 reply; 9+ messages in thread
From: Julien Cubizolles @ 2013-07-15  8:34 UTC (permalink / raw)
  To: emacs-orgmode

I'm struggling with LaTeX source blocks and am not sure anymore if one
can use the :results file header.

I have a csv file to be processed by tikz to get a png picture displayed
in my org buffer. 

Here is what I tried 

#+NAME: python-tikz
#+header: :results file :file py2tikz_sin.png
#+header: :fit yes :headers '("\\usepackage{tikz,pgfplots}")
#+BEGIN_SRC latex :exports results
  \begin{tikzpicture}
    \begin{axis}
      \addplot  table {sin_py2csv.csv};
    \end{axis}
  \end{tikzpicture}
'py2tikz_sin.png'
#+END_SRC

#+RESULTS: python-tikz
#+BEGIN_LaTeX
[[file:py2tikz_sin.png]]
#+END_LaTeX

Two problems with that: the py2tikz_sin.png file isn't produced (the
latex code is correct though) and I was under the impression that the
:results file header should give a #RESULTS without the LaTeX block
(it's what I get for python blocks anyway).

The data is produced by python (I can get python-babel to work !) and I
could get a png directly through python-babel but latex-babel should be
able to do it, right ?

Julien.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Problems with LaTeX source block
  2013-07-15  8:34 Problems with LaTeX source block Julien Cubizolles
@ 2013-07-15  8:57 ` Andreas Leha
  2013-07-15 10:24   ` Julien Cubizolles
  2013-07-16  7:57   ` Julien Cubizolles
  0 siblings, 2 replies; 9+ messages in thread
From: Andreas Leha @ 2013-07-15  8:57 UTC (permalink / raw)
  To: emacs-orgmode

Hi Julien,

Julien Cubizolles <j.cubizolles@free.fr> writes:

> I'm struggling with LaTeX source blocks and am not sure anymore if one
> can use the :results file header.
>
> I have a csv file to be processed by tikz to get a png picture displayed
> in my org buffer. 
>
> Here is what I tried 
>
> #+NAME: python-tikz
> #+header: :results file :file py2tikz_sin.png
> #+header: :fit yes :headers '("\\usepackage{tikz,pgfplots}")
> #+BEGIN_SRC latex :exports results
>   \begin{tikzpicture}
>     \begin{axis}
>       \addplot  table {sin_py2csv.csv};
>     \end{axis}
>   \end{tikzpicture}
> 'py2tikz_sin.png'
> #+END_SRC
>
> #+RESULTS: python-tikz
> #+BEGIN_LaTeX
> [[file:py2tikz_sin.png]]
> #+END_LaTeX
>
> Two problems with that: the py2tikz_sin.png file isn't produced (the
> latex code is correct though) and I was under the impression that the
> :results file header should give a #RESULTS without the LaTeX block
> (it's what I get for python blocks anyway).
>
> The data is produced by python (I can get python-babel to work !) and I
> could get a png directly through python-babel but latex-babel should be
> able to do it, right ?
>
> Julien.

try that instead

--8<---------------cut here---------------start------------->8---
#+NAME: python-tikz
#+header: :results raw :file py2tikz_sin.png
#+header: :imagemagick yes :fit yes :headers '("\\usepackage{tikz,pgfplots}")
#+BEGIN_SRC latex :exports results
  \begin{tikzpicture}
    \node[red!50!black] (a) {A};
    \node (b) [right of=a] {B};
    \draw[->] (a) -- (b);
  \end{tikzpicture}
#+END_SRC
--8<---------------cut here---------------end--------------->8---

for problem one:  you are missing the :imagemagick yes header argument,
which is necessary to do the latex->png conversion.  Also, the filename
is inserted for you and is, thus, not part of the latex block.

for problem two:  :results raw solves that, although I agree,
that :results file should work here.

Regards,
Andreas

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Problems with LaTeX source block
  2013-07-15  8:57 ` Andreas Leha
@ 2013-07-15 10:24   ` Julien Cubizolles
  2013-07-15 21:06     ` Andreas Leha
  2013-07-16  7:57   ` Julien Cubizolles
  1 sibling, 1 reply; 9+ messages in thread
From: Julien Cubizolles @ 2013-07-15 10:24 UTC (permalink / raw)
  To: emacs-orgmode

Hi Andreas

Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:

> try that instead
>
> #+NAME: python-tikz
> #+header: :results raw :file py2tikz_sin.png
> #+header: :imagemagick yes :fit yes :headers '("\\usepackage{tikz,pgfplots}")
> #+BEGIN_SRC latex :exports results
>   \begin{tikzpicture}
>     \node[red!50!black] (a) {A};
>     \node (b) [right of=a] {B};
>     \draw[->] (a) -- (b);
>   \end{tikzpicture}
> #+END_SRC



> for problem one:  you are missing the :imagemagick yes header argument,
> which is necessary to do the latex->png conversion.  Also, the filename
> is inserted for you and is, thus, not part of the latex block.

Thanks for clarifying it, in the worg page:
--8<---------------cut here---------------start------------->8---
The standard :file header argument associated with a LaTeX source code
block by itself can take the name of either a Portable Network Graphics
(png) or a Portable Document Format (pdf) file. File names for other
bitmap file types can be supplied in conjunction with the :imagemagick
header argument, described below.
--8<---------------cut here---------------end--------------->8---
the "other bitmap file types" led me to believe that imagemagick was not
needed for png.

> for problem two: :results raw solves that, although I agree that
> :results file should work here.

If it were to work, what would be the difference ? Would I need to add a 
command in the LaTeX code to print the name of the file I want to link
to ?

Thanks for your precious help. I'm always amazed at the responsiveness
and helpfulness of this list.

Julien, eager to contribute but still not very useful.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Problems with LaTeX source block
  2013-07-15 10:24   ` Julien Cubizolles
@ 2013-07-15 21:06     ` Andreas Leha
  0 siblings, 0 replies; 9+ messages in thread
From: Andreas Leha @ 2013-07-15 21:06 UTC (permalink / raw)
  To: emacs-orgmode

Hi Julien,

Julien Cubizolles <j.cubizolles@free.fr> writes:

> Hi Andreas
>
> Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
>
>> try that instead
>>
>> #+NAME: python-tikz
>> #+header: :results raw :file py2tikz_sin.png
>> #+header: :imagemagick yes :fit yes :headers '("\\usepackage{tikz,pgfplots}")
>> #+BEGIN_SRC latex :exports results
>>   \begin{tikzpicture}
>>     \node[red!50!black] (a) {A};
>>     \node (b) [right of=a] {B};
>>     \draw[->] (a) -- (b);
>>   \end{tikzpicture}
>> #+END_SRC
>
>
>
>> for problem one:  you are missing the :imagemagick yes header argument,
>> which is necessary to do the latex->png conversion.  Also, the filename
>> is inserted for you and is, thus, not part of the latex block.
>
> Thanks for clarifying it, in the worg page:
> The standard :file header argument associated with a LaTeX source code
> block by itself can take the name of either a Portable Network Graphics
> (png) or a Portable Document Format (pdf) file. File names for other
> bitmap file types can be supplied in conjunction with the :imagemagick
> header argument, described below.
> the "other bitmap file types" led me to believe that imagemagick was not
> needed for png.

Indeed, I forgot about that possibility.  I think that was introduced to
support much simpler 'formulas' -- the same way that latex snippets are
supported.  But still, it should work, I guess, with tikz code as well.

As to my understanding, if you do not explicitly specify
the :imagemagick header, internally (org-create-formula-image ) is
called which might run through dvipng -- depending on your setting of
org-latex-create-formula-image-program.  I guess, that you have set this
to dvipng.  In that case tikz is going to fail as it does not work with
'plain' latex.

But interestingly, I do not see the \usepackage{tikz} in the generated
/tmp/....tex file at all when the :imagemagick yes header argument is
missing.  So there is an issue there as well.

At this point I hope, that more knowledgeable people chime in and
clarify, whether there is some intentional limitation on latex blocks
without the :imagemagick yes header argument.


>
>> for problem two: :results raw solves that, although I agree that
>> :results file should work here.
>
> If it were to work, what would be the difference ? Would I need to add a 
> command in the LaTeX code to print the name of the file I want to link
> to ?
>

I actually expected the behaviour that we see with 'raw' to be the same
with 'file' -- without any change to the code of the latex block.

Regards,
Andreas

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Problems with LaTeX source block
  2013-07-15  8:57 ` Andreas Leha
  2013-07-15 10:24   ` Julien Cubizolles
@ 2013-07-16  7:57   ` Julien Cubizolles
  2013-07-16  8:03     ` Andreas Leha
  2013-07-16 11:09     ` Eric S Fraga
  1 sibling, 2 replies; 9+ messages in thread
From: Julien Cubizolles @ 2013-07-16  7:57 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode

Hi Andreas, I forgot to send the following remarks in my previous
post.

I encounter a problem with pgfplots. The following works, and produces a
png with a white background
#+NAME: python-tikz
#+header: :results raw :file py2tikz_sin.png
#+header: :imagemagick yes :fit yes :headers '("\\usepackage{tikz,pgfplots}")
#+BEGIN_SRC latex :exports results
    \begin{tikzpicture}
      \begin{axis}
        \draw [green,->] (0,0) -- (2,2) -- (3,1);
      \end{axis}
    \end{tikzpicture}
#+END_SRC

However, the following produces a png with only the axis displayed (but
the boundaries are wrong), the data points don't appear. Strangely, the
png produced is transparent: the background is the one of the Emacs buffer.

#+NAME: python-tikz
#+header: :results raw :file py2tikz_sin.png
#+header: :imagemagick yes :fit yes :headers '("\\usepackage{tikz,pgfplots}")
#+BEGIN_SRC latex :exports results
    \begin{tikzpicture}
      \begin{axis}
        \addplot [red,only lines] table {sin_py2csv.csv};
      \end{axis}
    \end{tikzpicture}
#+END_SRC

The temp latex file seems ok (pdflatex produces a correct picture). I
couldn't find the command line for imagemagick conversion to png to test
it though.

Julien. 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Problems with LaTeX source block
  2013-07-16  7:57   ` Julien Cubizolles
@ 2013-07-16  8:03     ` Andreas Leha
  2013-07-16 14:57       ` Julien Cubizolles
  2013-07-16 11:09     ` Eric S Fraga
  1 sibling, 1 reply; 9+ messages in thread
From: Andreas Leha @ 2013-07-16  8:03 UTC (permalink / raw)
  To: emacs-orgmode

Hi Julien,

Julien Cubizolles <j.cubizolles@free.fr> writes:

> Hi Andreas, I forgot to send the following remarks in my previous
> post.
>
> I encounter a problem with pgfplots. The following works, and produces a
> png with a white background
> #+NAME: python-tikz
> #+header: :results raw :file py2tikz_sin.png
> #+header: :imagemagick yes :fit yes :headers '("\\usepackage{tikz,pgfplots}")
> #+BEGIN_SRC latex :exports results
>     \begin{tikzpicture}
>       \begin{axis}
>         \draw [green,->] (0,0) -- (2,2) -- (3,1);
>       \end{axis}
>     \end{tikzpicture}
> #+END_SRC
>
> However, the following produces a png with only the axis displayed (but
> the boundaries are wrong), the data points don't appear. Strangely, the
> png produced is transparent: the background is the one of the Emacs buffer.
>
> #+NAME: python-tikz
> #+header: :results raw :file py2tikz_sin.png
> #+header: :imagemagick yes :fit yes :headers '("\\usepackage{tikz,pgfplots}")
> #+BEGIN_SRC latex :exports results
>     \begin{tikzpicture}
>       \begin{axis}
>         \addplot [red,only lines] table {sin_py2csv.csv};
>       \end{axis}
>     \end{tikzpicture}
> #+END_SRC
>
> The temp latex file seems ok (pdflatex produces a correct picture). I
> couldn't find the command line for imagemagick conversion to png to test
> it though.

The problem is in your external data file, I guess.

What happens, is that org creates a temporary tex file in a temporary
directory (it is in /tmp/babel-sth under Linux) and compiles this tex
file there.  At that directory your sin_py2csv.csv is not present.

So, one quick remedy should be to use an absolute path to the csv.

Regards,
Andreas

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Problems with LaTeX source block
  2013-07-16  7:57   ` Julien Cubizolles
  2013-07-16  8:03     ` Andreas Leha
@ 2013-07-16 11:09     ` Eric S Fraga
  2013-07-16 15:04       ` Julien Cubizolles
  1 sibling, 1 reply; 9+ messages in thread
From: Eric S Fraga @ 2013-07-16 11:09 UTC (permalink / raw)
  To: Julien Cubizolles; +Cc: emacs-orgmode

Julien Cubizolles <j.cubizolles@free.fr> writes:

[...]

> However, the following produces a png with only the axis displayed (but
> the boundaries are wrong), the data points don't appear. Strangely, the
> png produced is transparent: the background is the one of the Emacs buffer.

Interesting.  I have this behaviour as well in terms of background.  I
use a dark theme on all of my windows, be they emacs or xterms.  The png
generated by imagemagick sets the background to transparent which means
I cannot see the images produced as the actual drawing and text are
black.

I am happy with this: just had to remember to set the drawing colour to
white by "\begin{tikzpicture}[white]".

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 24.3.50.1, Org release_8.0.5-337-g9f3bed

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Problems with LaTeX source block
  2013-07-16  8:03     ` Andreas Leha
@ 2013-07-16 14:57       ` Julien Cubizolles
  0 siblings, 0 replies; 9+ messages in thread
From: Julien Cubizolles @ 2013-07-16 14:57 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode

The following message is a courtesy copy of an article
that has been posted to gmane.emacs.orgmode as well.

Hi Andreas

Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:


> The problem is in your external data file, I guess.
>
> What happens, is that org creates a temporary tex file in a temporary
> directory (it is in /tmp/babel-sth under Linux) and compiles this tex
> file there.  At that directory your sin_py2csv.csv is not present.
>
> So, one quick remedy should be to use an absolute path to the csv.

You were right, using the whole path for the data file fixed this
problem. It would be convenient to have the PATH of the org file added
to some TEXMF path prior to compilation to address this issue.

Thanks for your help,

Julien.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Problems with LaTeX source block
  2013-07-16 11:09     ` Eric S Fraga
@ 2013-07-16 15:04       ` Julien Cubizolles
  0 siblings, 0 replies; 9+ messages in thread
From: Julien Cubizolles @ 2013-07-16 15:04 UTC (permalink / raw)
  To: emacs-orgmode

Hi Eric,

Eric S Fraga <e.fraga@ucl.ac.uk> writes:


> Interesting.  I have this behaviour as well in terms of background.  I
> use a dark theme on all of my windows, be they emacs or xterms.  The png
> generated by imagemagick sets the background to transparent which means
> I cannot see the images produced as the actual drawing and text are
> black.
>
> I am happy with this: just had to remember to set the drawing colour to
> white by "\begin{tikzpicture}[white]".

The background/foreground are supposed to be changed by setting the
:buffer yes header and by customizing org-format-latex-options. I didn't
try it though, I'm happy with the [white] option to tikzpicture.

However, I noticed something odd. If I use the following headers

--8<---------------cut here---------------start------------->8---
#+header: :results raw :file py2tikz_sin.png
#+header: :imagemagick yes :fit yes :headers '("\\usepackage{tikz,pgfplots}")
#+header: :iminoptions -density 600 :imoutoptions -geometry 400
--8<---------------cut here---------------end--------------->8---

the png is transparent. If I remove the last line:
--8<---------------cut here---------------start------------->8---
#+header: :results raw :file py2tikz_sin.png
#+header: :imagemagick yes :fit yes :headers '("\\usepackage{tikz,pgfplots}")
--8<---------------cut here---------------end--------------->8---
I get the white background back, although in both cases, imagemagick is
used.

Julien.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-07-16 15:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-15  8:34 Problems with LaTeX source block Julien Cubizolles
2013-07-15  8:57 ` Andreas Leha
2013-07-15 10:24   ` Julien Cubizolles
2013-07-15 21:06     ` Andreas Leha
2013-07-16  7:57   ` Julien Cubizolles
2013-07-16  8:03     ` Andreas Leha
2013-07-16 14:57       ` Julien Cubizolles
2013-07-16 11:09     ` Eric S Fraga
2013-07-16 15:04       ` Julien Cubizolles

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).