LaTeX forum ⇒ GeneralHow to embed python in latex?

LaTeX specific issues not fitting into one of the other forums of this category.
luofeiyu
Posts: 3
Joined: Wed Aug 23, 2017 8:36 am

How to embed python in latex?

Postby luofeiyu » Wed Aug 23, 2017 8:45 am

For the article here http://www.texample.net/weblog/2008/oct ... hon-latex/.

Let’s start with a basic “hello world” example:

%& -shell-escape
\documentclass{article}
\usepackage{python}
\begin{document}

Say hello Python:

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

Compiling the above code with shell escape enabled gives the following output:
Say Hello world!
Hello Latex


How to compile it?
vim test.latex

%& -shell-escape
\documentclass{article}
\usepackage{python}
\begin{document}

Say hello Python:

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

Which shell command to compile the test.latex file?

Tags:

User avatar
Stefan Kottwitz
Site Admin
Posts: 8527
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Wed Aug 23, 2017 9:28 am

Hi,

compile it by

pdflatex -shell-escape test.latex

By the way, the file name extension is usually .tex.

Stefan
Site admin

luofeiyu
Posts: 3
Joined: Wed Aug 23, 2017 8:36 am

Postby luofeiyu » Wed Aug 23, 2017 10:36 am

pdflatex -shell-escape test.latex
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2015/dev/Debian) (preloaded format=pdflatex)
\write18 enabled.
entering extended mode
(./test.latex
LaTeX2e <2014/05/01>
Babel <3.9l> and hyphenation patterns for 2 languages loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/python/python.sty) (./test.aux)

! LaTeX Error: Environment /usr/bin/python undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...

l.8 \begin{/usr/bin/python}
%
?


! LaTeX Error: Environment /usr/bin/python undefined.
How to fix then?

User avatar
Stefan Kottwitz
Site Admin
Posts: 8527
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Wed Aug 23, 2017 10:47 am

That line is wrong:

\begin{/usr/bin/python}

It has to be:

\begin{python}

The same with \end.

Stefan
Site admin


Return to “General”

Who is online

Users browsing this forum: Google [Bot] and 11 guests