在将pylatex
版本更新为1.3.0
之后,我在文档的小节中遇到了特殊字符(例如$,#)的问题。
这是一个最小的脚本:
from pylatex import Document, Section, Subsection, Tabular, UnsafeCommand, NoEscape, Table, Package, utils
doc = Document(geometry_options={"tmargin": "2cm", "lmargin": "2cm", "rmargin": "2cm", "bmargin": "2cm"})
doc.packages.append(Package('bookmark'))
doc.packages.append(Package('float'))
doc.append(UnsafeCommand('title', 'A Title'))
doc.append(NoEscape('\\maketitle'))
doc.append(NoEscape('\\clearpage'))
doc.append(Section('Section One'))
doc.append(Subsection(utils.escape_latex('Prices ($)'))) # PROBLEM HERE
doc.generate_pdf(r'/home/test', clean_tex=True, clean=True, compiler='pdflatex', silent=False)
我认为错误的相关部分是这个:
AED: lastpage setting LastPage
[2] (./test.aux
! Missing \endcsname inserted.
<to be read again>
\protect
l.25 ...}{{1.1}{2}{Prices (\$)}{subsection.1.1}{}}
! Extra \endcsname.
\@newl@bel ...dafter \ifx \csname #1@#2\endcsname
\reserved@a \else \@tempsw...
l.25 ...}{{1.1}{2}{Prices (\$)}{subsection.1.1}{}}
)
我尝试使用python原始字符串r''
和pylatex.utils.escape_latex
玩一些,但无法正常工作。
有什么建议吗?