General ⇒ How to embed python in latex?
How to embed python in 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?
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- Stefan Kottwitz
- Site Admin
- Posts: 10397
- Joined: Mon Mar 10, 2008 9:44 pm
How to embed python in latex?
compile it by
pdflatex -shell-escape test.latexBy the way, the file name extension is usually .tex.
Stefan
How to embed python in 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?
- Stefan Kottwitz
- Site Admin
- Posts: 10397
- Joined: Mon Mar 10, 2008 9:44 pm
How to embed python in latex?
\begin{/usr/bin/python}It has to be:
\begin{python}The same with \end.
Stefan