I do not understand the documentation of pylatex
. I'm using pylatex
.
How do I change the page orientation and font size?
I do not understand the documentation of pylatex
. I'm using pylatex
.
How do I change the page orientation and font size?
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()
In PyLaTeX >1.1.0 the constructor of the Document class allows to provide document_options as a list:
from pylatex import Document
doc = Document(inputenc="utf8", documentclass="scrarticle", document_options=["12pt", "landscape"])
Edit: PyLatex 1.1.0 was released few weeks after @heiko-oberdiek answered.