0

Wanting to export a figure generated by matplotlib to LaTeX (as described here) I've encountered the following issue (which ultimately I was able to solve as described here).

My source block has two noweb syntax references

#+HEADER: :var path="./fig.png"
#+BEGIN_SRC python :exports results :results file :noweb yes
<<get-modules>>
x = np.random.normal(0, 1, 100)
<<plot-figure>>
#+END_SRC

where get-modules and plot-figure are defined in the commented headline named Source blocks

* COMMENT Source blocks

   #+NAME: get-modules
   #+BEGIN_SRC python
   import numpy as np
   import matplotlib.pyplot as plt
   #+END_SRC

   #+NAME: plot-figure
   #+BEGIN_SRC python
   plt.plot(x)
   plt.savefig(path)
   return path
   #+END_SRC

The code works properly and after executing (with C-c C-c) I get

#+RESULTS:
[[file:./fig.png]]

Unfortunately, while exporting my document to LaTeX instead of default

\includegraphics[width=.9\linewidth]{./fig.png}

I have just

\url{}

This problem does not occur when I give up noweb references, so

#+HEADER: :var path="./fig.png"
#+BEGIN_SRC python :exports results :results file
import numpy as np
import matplotlib.pyplot as plt
x = np.random.normal(0, 1, 100)
plt.plot(x)
plt.savefig(path)
return path
#+END_SRC

works as expected, but I would like to achieve this with noweb references.

I use org 8.3.4 version.

  • Your (noweb) example works for me just fine with org 8.2.2 and org 9.0.1. It gives just the \includegraphics commands you expect. Could there be some quirk in your installation (org, or python, or paths) that causes the python interpreter to fail in the export case? – Vera Johanna Nov 30 '16 at 23:34
  • @pingi Thanks for replay! Your answer encouraged me to keep searching. I found the reason and updated my question. – premopie Dec 1 '16 at 6:32
  • just fyi, actually you can also just answer your own quetsion – Vera Johanna Dec 1 '16 at 10:56
  • @pingi Done! Thanks once again for your help. – premopie Dec 1 '16 at 13:13
0

Everything came back to normal after removing the COMMENT of the Source block headline.

Actually this behaviour is consistent: commented headline - as expected - is excluded from the exported version of a document. At the same time the code for noweb references is also excluded which results in empty link.

In the second attempt - without noweb references - all code is in one place (in non commented headline) so export is done properly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.