pylatex.base_classes.containers

This module implements LaTeX base classes that can be subclassed.

class Container(*, data=None)[source]

Bases: pylatex.base_classes.latex_object.LatexObject, collections.UserList

A base class that groups multiple LaTeX classes.

This class should be subclassed when a LaTeX class has content that is of variable length. It subclasses UserList, so it holds a list of elements that can simply be accessed by using normal list functionality, like indexing or appending.

Parameters:data (list, LatexObject or something that can be converted to a ) – string The content with which the container is initialized
dumps_content(**kwargs)[source]

Represent the container as a string in LaTeX syntax.

Parameters:**kwargs – Arguments that can be passed to dumps_list
Returns:A LaTeX string representing the container
Return type:string
create(child)[source]

Add a LaTeX object to current container, context-manager style.

Parameters:child (Container) – An object to be added to the current container
begin_paragraph = False
dumps()[source]

Represent the class as a string in LaTeX syntax.

This method should be implemented by any class that subclasses this class.

class Environment(*, options=None, arguments=None, start_arguments=None, **kwargs)[source]

Bases: pylatex.base_classes.containers.Container

A base class for LaTeX environments.

This class implements the basics of a LaTeX environment. A LaTeX environment looks like this:

\begin{environment_name}
    Some content that is in the environment
\end{environment_name}

The text that is used in the place of environment_name is by default the name of the class in lowercase. However, this default can be overridden in 2 ways: 1. setting the _latex_name class variable when declaring the class 2. setting the _latex_name attribute when initialising object

Parameters:
  • options (str or list or Options) – Options to be added to the \begin command
  • arguments (str or list or Arguments) – Arguments to be added to the \begin command
  • start_arguments (str or list or Arguments) – Arguments to be added before the options
omit_if_empty = False[source]

Set to true if this full container should be equivalent to an empty string if it has no content.

dumps()[source]

Represent the environment as a string in LaTeX syntax.

Returns:A LaTeX string representing the environment.
Return type:str
begin_paragraph = False
create(child)[source]

Add a LaTeX object to current container, context-manager style.

Parameters:child (Container) – An object to be added to the current container
dumps_content(**kwargs)[source]

Represent the container as a string in LaTeX syntax.

Parameters:**kwargs – Arguments that can be passed to dumps_list
Returns:A LaTeX string representing the container
Return type:string
class Fragment(**kwargs)[source]

Bases: pylatex.base_classes.containers.Container

A LaTeX fragment container class for fragmented document construction.

This only provides logical wrapping of the items. The final document will look the same as if all items would not have been part of a container.

A common usecase of this is to generate a .tex snippet containing more than one LaTeX item item without any extra container around it. This snippet can then be included in another .tex file using \input{snippet.tex}

class ContainerCommand(arguments=None, options=None, *, data=None, **kwargs)[source]

Bases: pylatex.base_classes.containers.Container

A base class for a container command (A command which contains data).

Container command example:

\CommandName[options]{arguments}{
    data
}
Parameters:
  • arguments (str or list) – The arguments for the container command
  • options (str, list or Options) – The options for the preamble command
  • data (str or LatexObject) – The data to place inside the preamble command
omit_if_empty = False[source]