# pylatex.document¶

This module implements the class that deals with the full document.

class Document(default_filepath='default_filepath', *, documentclass='article', document_options=None, fontenc='T1', inputenc='utf8', font_size='normalsize', lmodern=True, textcomp=True, microtype=None, page_numbers=True, indent=None, geometry_options=None, data=None)[source]

A class that contains a full LaTeX document.

If needed, you can append stuff to the preamble or the packages. For instance, if you need to use \maketitle you can add the title, author and date commands to the preamble to make it work.

Parameters: default_filepath (str) – The default path to save files. documentclass (str or Command) – The LaTeX class of the document. document_options (str or list) – The options to supply to the documentclass fontenc (str) – The option for the fontenc package. If it is None, the fontenc package will not be loaded at all. inputenc (str) – The option for the inputenc package. If it is None, the inputenc package will not be loaded at all. font_size (str) – The font size to declare as normalsize lmodern (bool) – Use the Latin Modern font. This is a font that contains more glyphs than the standard LaTeX font. textcomp (bool) – Adds even more glyphs, for instance the Euro (€) sign. page_numbers (bool) – Adds the ability to add the last page to the document. indent (bool) – Determines whether or not the document requires indentation. If it is None it will use the value from the active config. Which is True by default. geometry_options (str or list) – The options to supply to the geometry package data (list) – Initial content of the document.
generate_tex(filepath=None)[source]

Generate a .tex file for the document.

Parameters: filepath (str) – The name of the file (without .tex), if this is not supplied the default filepath attribute is used as the path.
generate_pdf(filepath=None, *, clean=True, clean_tex=True, compiler=None, compiler_args=None, silent=True)[source]

Generate a pdf file from the document.

Parameters: filepath (str) – The name of the file (without .pdf), if it is None the default_filepath attribute will be used. clean (bool) – Whether non-pdf files created that are created during compilation should be removed. clean_tex (bool) – Also remove the generated tex file. compiler (str or None) – The name of the LaTeX compiler to use. If it is None, PyLaTeX will choose a fitting one on its own. Starting with latexmk and then pdflatex. compiler_args (list or None) – Extra arguments that should be passed to the LaTeX compiler. If this is None it defaults to an empty list. silent (bool) – Whether to hide compiler output
change_page_style(style)[source]

Alternate page styles of the current page.

Parameters: style (str) – value to set for the page style of the current page
change_document_style(style)[source]

Alternate page style for the entire document.

Parameters: style (str) – value to set for the document style
add_color(name, model, description)[source]

Add a color that can be used throughout the document.

Parameters: name (str) – Name to set for the color model (str) – The color model to use when defining the color description (str) – The values to use to define the color
change_length(parameter, value)[source]

Change the length of a certain parameter to a certain value.

Parameters: parameter (str) – The name of the parameter to change the length for value (str) – The value to set the parameter to
omit_if_empty = False
set_variable(name, value)[source]

Add a variable which can be used inside the document.

Variables are defined before the preamble. If a variable with that name has already been set, the new value will override it for future uses. This is done by appending \renewcommand to the document.

Parameters: name (str) – The name to set for the variable value (str) – The value to set for the variable