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(
        options=['12pt', 'landscape'],

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(
        options=['12pt', 'landscape'],
        options=['a6paper', 'showframe']))




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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.