在 LaTeX 中嵌入 Python - 你好示例?

在 LaTeX 中嵌入 Python - 你好示例?

找到示例在 LaTex 中使用 Python,但不幸的是我遇到了问题。

  • Microsoft Windows [版本 6.2.9200]
  • 这是 XeTeX,版本 3.1415926-2.5-0.9999.3(MiKTeX 2.9 32 位)
  • Python 3.3.2(v3.3.2:d047928ae3f6,2013 年 5 月 16 日,00:06:53)[MSC v.1600 64 位(AM D64)] 在 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 错误:我找不到 hello.py.out!

但生成了两个文件(hello.py,latex.py)。有人能帮帮我吗?

答案1

如果我删除以下字符,代码就可以编译成功%

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

Say hello Python:

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

\end{document}

问题是,\begin{python}需要看到行尾才能开始工作;如果你对它进行注释,那么看到的下一个行就太晚了,而且该print行会被吞噬,所以什么都不会写出来。

相关内容