Constructor Document
does not support options for the document class. However, the documentclass
is available as Command
and can be overwritten:
doc = Document('basic')
doc.documentclass = Command(
'documentclass',
options=['12pt', 'landscape'],
arguments=['article'],
)
Also a package like geometry
can be added, see the following example, which was derived from the basic and full example of the documentation of pylatex
:
#!/usr/bin/env python
from pylatex import Document, Section, Subsection, Package, Command
from pylatex.utils import italic, NoEscape
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')
doc.documentclass = Command(
'documentclass',
options=['12pt', 'landscape'],
arguments=['article'],
)
fill_document(doc)
doc.packages.append(Package('geometry',
options=['a6paper', 'showframe']))
doc.generate_pdf(clean_tex=False)
doc.generate_tex()
You need to change the pylatex.Document
arguments to:
doc = pylatex.Document('basic',font_size = '', inputenc = 'utf8x', lmodern = False, fontenc = None, textcomp = None)
in order to remove the normalsize
line.
To put the fontselect
in place a command for it after the command for fontsize
like this:
doc.append(pylatex.Command('fontsize', arguments = ['15', '12']))
doc.append(pylatex.Command('selectfont'))
The font size will then be 15.
Best Answer
You can add stuff to your preamble using
doc.preamble.append()
. To addhelvet
to your preamble use:This needs
to work out, if you imported
pylatex
and not only submodules and functions from it, usepylatex.Command
instead.From what I gathered by a quick look on the documentation of
pylatex
you might be able to add arbitrary stuff to your document (making a horizontal line possible) by doing:and then
I'm not sure what
NoEscape
is needed for, perhaps it isn't needed, but I can't try because I don't havepylatex
installed.