我使用带有 Python 2.7 和 LaTeX 的 Ubuntu 服务器,并尝试使用 shell 命令编译此 LaTeX 代码:pdflatex test.tex
\documentclass{article}
\usepackage{python}
\begin{document}
\begin{python}
print "Hello World"
\end{python}
\end{document}
这非常简单,因为这是我第一次尝试同时使用两者,但我收到此错误消息:
(/usr/share/texmf/tex/latex/python/python.sty
Package: python 2007/06/07 v0.21 Python in LaTeX
\@out=\write3
\@module=\write4
) (./test.aux)
! I can't write on file `test.aux'.
\document ...ate \openout \@mainaux \jobname .aux
\immediate \write \@mainau...
l.5 \begin{document}
(Press Enter to retry, or Control-D to exit; default file extension is `.tex')
Please type another output file name:
! Emergency stop.
\document ...ate \openout \@mainaux \jobname .aux
可能是权限问题还是其他问题?
最佳答案
我对所讨论的 LaTeX 包没有任何经验,但据我所知,它将尝试执行 python 代码片段并包含输出。尝试从 python 段中删除前导空格:
\begin{python}
print "Hello World!"
\end{python}
而不是:
\begin{python}
print "Hello World!"
\end{python}
无关的前导空格将导致 python 解释器抛出 IndentationError
这可能是令人困惑的 python.sty。粗略看看python.sty让我相信它将执行以下 shell 命令将执行的操作:
prompt$ echo ' print "Hello World!"' > test.py
prompt$ cat test.py | python > test.py.out 2> test.py.err
然后它将逐字包含 test.py.out,该文件将为空。标准错误输出将包含类似以下内容:
File "<stdin>", line 1
print "Hello World!"
^
IndentationError: unexpected indent
sty 文件中提到他不应该忽略标准错误输出。我有一种感觉,如果 python
解释器退出失败,那么 LaTeX 永远不会生成输出,但我可能是错的。
关于python - Latex 和嵌入式 python 代码的编译问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11542491/