代码 [已弃用;请参阅修订版 2],我在 OS X 10.11.4 El Capitan 的 TextMate 中使用 XeLaTeX--shell-escape 运行
\documentclass{article}
\usepackage{graphicx}
\usepackage{python} % http://tex.stackexchange.com/a/53465/13173
%% OS X http://tex.stackexchange.com/a/136318/13173
% XeLaTeX--shell-escape
\begin{document}
\begin{python}
import os
directory = "/Users/masi/Desktop/testEps/eps"
extension = ".eps"
files = [file for file in os.listdir(directory) if file.lower().endswith(extension)]
for file in files:
if
print r"\begin{figure}"
print r"\includegraphics[scale=0.3]{%s}" % file
print r"\caption{File %s}" % file
print r"\label{Serie%s}" % file
print r"\end{figure}"
\end{python}
\end{document}
预期输出的是一些图片。我在日志中看到图片已正确加载。但是,输出是一个空白文档,带有页码,没有图片。
egrep 之后的修订版本 2
\documentclass{article}
\usepackage{graphicx}
\usepackage{python} % http://tex.stackexchange.com/a/53465/13173
%% OS X http://tex.stackexchange.com/a/136318/13173
% XeLaTeX--shell-escape
\graphicspath{{/Users/masi/Desktop/testEps/eps}}
\begin{document}
\begin{python}
import os
directory = "/Users/masi/Desktop/testEps/eps"
extension = ".eps"
files = [file for file in os.listdir(directory) if file.lower().endswith(extension)]
for file in files:
print r"\begin{figure}"
print r"\includegraphics[scale=0.3]{%s}" % file
print r"\caption{File %s}" % file
print r"\label{Serie%s}" % file
print r"\end{figure}"
\end{python}
\end{document}
但输出仍然相同。内容.py.out
\begin{figure}
\includegraphics[scale=0.3]{test.eps}
\caption{File test.eps}
\label{Serietest.eps}
\end{figure}
\begin{figure}
\includegraphics[scale=0.3]{test2.eps}
\caption{File test2.eps}
\label{Serietest2.eps}
\end{figure}
这是正确的。在日志中runsystem
(./test.py.out
^^JLaTeX Warning: File `test.eps' not found on input line 2.^^J
./test.py.out:2: Unable to load picture or PDF file 'test.eps'.
<to be read again>
}
l.2 ...cale=0.3]{test.eps}
The requested image couldn't be read because
it was not a recognized image format.
这很奇怪,因为我可以在设置 Python 进行处理之前在文档中单独加载 .eps 图像。但是,删除选项--shel-escape
不再会产生预期的输出。
不使用 Python 进行测试
代码
\documentclass{article}
\usepackage{graphicx}
\graphicspath{{/Users/masi/Desktop/testEps/eps/}}
\begin{document}
\begin{figure}
\includegraphics[scale=0.3]{test.eps}
\end{figure}
\end{document}
错误
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
Latex Error: ./test.tex:6 Unable to load picture or PDF file '/Users/masi/Desktop/testEps/eps/test.eps'.
Including: "/Users/masi/Desktop/testEps/eps/test.eps"
Latex Error: ./test.tex:6 Unable to load picture or PDF file '/Users/masi/Desktop/testEps/eps/test.eps'.
Latex Error: ./test.tex:8 Output loop---100 consecutive dead cycles.
这是一个奇怪的行为,删除 Python 也无济于事。要么是 Python 在系统中出现了问题,要么是我遇到了一些我没有注意到的错误。我不明白这个错误是什么100 consecutive dead cycles
。
案例中为何没有数字的输出?
答案1
if
您的Python 代码中有一个错误。您还遗漏了\graphicspath
。
在下面的代码中我屏蔽了我使用的真实路径。
\documentclass{article}
\usepackage{graphicx}
\usepackage{python} % http://tex.stackexchange.com/a/53465/13173
%% OS X http://tex.stackexchange.com/a/136318/13173
% XeLaTeX--shell-escape
\graphicspath{{<maskedInformation>/testeps/}}
\begin{document}
\begin{python}
import os
directory = "<maskedInformation>/testeps/"
extension = ".eps"
files = [file for file in os.listdir(directory) if file.lower().endswith(extension)]
for file in files:
print r"\begin{figure}"
print r"\includegraphics[scale=0.3]{%s}" % file
print r"\caption{File %s}" % file
print r"\label{Serie%s}" % file
print r"\end{figure}"
\end{python}
\end{document}