gpt4 book ai didi

python - PyLatex 如何添加自定义usepackage

转载 作者:行者123 更新时间:2023-12-02 06:31:12 26 4
gpt4 key购买 nike

我想知道向 pylatex 添加自定义使用包的命令是什么。我已经尝试使用 document.append 函数和 document.preamble.append 函数,但仍然出现错误。

# encoding=utf-8

from pylatex import Document, Section, Subsection, Command
from pylatex.utils import italic, NoEscape
from pylatex.package import Package
from pylatex import Document, Section, UnsafeCommand
from pylatex.base_classes import Environment, CommandBase, Arguments





def fill_document(doc):
"""Add a section, a subsection and some text to the document.

:param doc: the document
:type doc: :class:`pylatex.document.Document` instance
"""
with doc.create(Section('A section')):
doc.append('Some regular text and some ')
doc.append(italic('italic text. '))

with doc.create(Subsection('A subsection')):
doc.append('Also some crazy characters: $&#{}')


if __name__ == '__main__':
# Basic document
doc = Document('basic')
fill_document(doc)

doc.generate_pdf(clean_tex=False)
doc.generate_tex()

# Document with `\maketitle` command activated
doc = Document()

#packages = [Package('caratula',"showRevisiones")]


#doc.append(Package("caratula"))

doc.data.append(Package("caratula"))

doc.preamble.append(Command('begin', 'document'))
doc.preamble.append(Command('materia', 'Materia del Apunte'))
doc.preamble.append(Command('tipoapunte', str('Tipo de Apunte (Teorico o Practico)')))
doc.preamble.append(Command('fecha', NoEscape(r'\today')))
doc.preamble.append(Command('tema', NoEscape(r'Tema')))
doc.preamble.append(Command('subtema', NoEscape(r'Subtema')))
doc.preamble.append(Command('autor',["Apellido", "Nombre2", "002/01","email2@dominio.com"]))
doc.preamble.append(Command('revision',["05/01/2015", "Apellido, Nombre2", "em"]))
doc.append(NoEscape(r'\maketitle'))

fill_document(doc)

doc.generate_pdf('basic_maketitle', clean_tex=False)

# Add stuff to the document
with doc.create(Section('A second section')):
doc.append('Some text.')

doc.generate_pdf('basic_maketitle2', clean_tex=False)
tex = doc.dumps() # The document as string in LaTeX syntax


import subprocess
subprocess.Popen("basic_maketitle2.tex",shell=True)

最佳答案

自定义包是什么意思?如果您的意思是您创建的 .sty 文件,那么我不知道(可能相同),但如果您只想添加标准包,那么例如

doc.packages.append(Package('tikz'))

对我有用(从 pylatex 导入之后)。

干杯。

关于python - PyLatex 如何添加自定义usepackage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41926515/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com