在reST文件中定义Latex包



我们使用Docutils生成reST文档,然后通过rst2latex生成TeX文件。

rst文件中,我们添加了许多LaTeX代码,如:

.. raw:: latex
    ~\
    rule{textwidth}{1pt}
    ~\

但是我不知道在哪里添加像usepackage{tabulary}这样的包。

如果我像上面所示的那样在rst文件中添加它,即使在最开始,这个usepackage行也会自动添加到tex输出文件中的begin{document}之后。这显然会产生错误。

任何想法在哪里我可以在reST中添加usepackage命令?

您可以使用LaTeX序言(在Docutils 0.7之后)

rst2latex foo.rst foo.tex --latex-preamble="usepackage{tabulary}"

将在foo.html

中生成以下内容
%%% Custom LaTeX preamble
usepackage{tabulary}

或者,可以通过

提供自定义样式表
rst2latex foo.rst foo.tex --stylesheet=preamble.tex

将生成

%%% User specified packages and stylesheets
input{preamble.tex}

最新更新