[Tex/LaTex] Embedding Python in LaTeX – Hello example

pythonxetex

I found example of the using Python in LaTex, but unfortunately I have problem with it.

  • Microsoft Windows [Version 6.2.9200]
  • This is XeTeX, Version 3.1415926-2.5-0.9999.3 (MiKTeX 2.9 32 bit)
  • Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AM
    D64)] on win32

MNWE: (xetex –enable-write18 hello.tex)

\documentclass{article}
\usepackage{python}
\begin{document}

Say hello Python:

\begin{python}%
print r"Hello \LaTeX!"
\end{python}%
\end{document}

Latex Error: I can't find hello.py.out!

But two files (hello.py, latex.py) was generated. Could anyone help me?

Best Answer

The code compiles fine if I remove the % characters:

\documentclass{article}
\usepackage{python}
\begin{document}

Say hello Python:

\begin{python}
print r"Hello \LaTeX!"
\end{python}

\end{document}

The problem is that \begin{python} needs to see an end-of-line to start it working; and if you comment it, the next one that's seen is too late and the print line is gobbled, so nothing is written out.