我正在尝试使用.pdf生成一个PyLaTeX文件。我看到PyLaTeX有一个预定义的语法来生成LaTeX文档,然后导出它们,但是我想简单地加载我已经构建的LaTeX文件,而不是通过PyLaTeX语法重新创建它。
我现在试图使用的代码如下,即使一切正常运行,我也会得到文档的“原始”代码:
from pylatex import Document, Section, Subsection, Command
from pylatex.utils import italic, NoEscape
latex_document = 'path'
with open(latex_document) as file:
tex= file.read()
doc = Document('basic')
doc.append(tex)
doc.generate_pdf(clean_tex=False)发布于 2017-08-18 02:51:16
您需要用tex包装NoEscape,这样PyLaTeX就可以逐字逐句地解释字符串内容。
如果文件path的内容是
\begin{equation}
\hat{H}\Psi = E\Psi
\end{equation}然后doc.append(tex)创建
\begin{document}%
\normalsize%
\textbackslash{}begin\{equation\}\newline%
\textbackslash{}hat\{H\}\textbackslash{}Psi = E\textbackslash{}Psi\newline%
\textbackslash{}end\{equation\}\newline%
%
\end{document}而doc.append(NoEscape(tex))创建了
\begin{document}%
\normalsize%
\begin{equation}
\hat{H}\Psi = E\Psi
\end{equation}
%
\end{document}https://stackoverflow.com/questions/44302200
复制相似问题