Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyLatex How to add custom usepackage

Tags:

python

i wanted to know which is the command to add custom use packages to pylatex. i have already tried using the document.append function and document.preamble.append function but i am still getting errors.

# 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","[email protected]"]))
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)
like image 691
Ilan Kleiman Avatar asked Jan 29 '17 22:01

Ilan Kleiman


1 Answers

What do you mean by custom packages? If you mean .sty files you created, then I have no idea (probably the same), but if you just want to add a standard package, then e.g.

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

works for me (after importing Package from pylatex).

Cheers.

like image 96
manu Avatar answered Oct 03 '22 02:10

manu