pyexlatex.models package

Subpackages

Submodules

pyexlatex.models.blindtext module

class pyexlatex.models.blindtext.BlindText(overlay=None)[source]

Bases: pyexlatex.models.item.NoOptionsNoContentsItem

Produces lorem ipsum dolor… etc. example text

__init__(overlay=None)[source]
name = 'blindtext'

pyexlatex.models.caption module

class pyexlatex.models.caption.Caption(contents, short_caption=None)[source]

Bases: pyexlatex.models.item.SimpleItem

__init__(contents, short_caption=None)[source]
name = 'caption'

pyexlatex.models.containeritem module

class pyexlatex.models.containeritem.ContainerItem(name, content, *args, **kwargs)[source]

Bases: pyexlatex.models.documentitem.DocumentItem

Inherit to be able to include LaTeX objects inside LaTeX objects

__init__(name, content, *args, **kwargs)[source]
add_data_from_content(content)[source]
init_data()[source]

pyexlatex.models.datastore module

class pyexlatex.models.datastore.DataStore(content=None)[source]

Bases: pyexlatex.models.containeritem.ContainerItem, pyexlatex.models.documentitem.DocumentItem

Holds LaTeX item data and can be included directly in documents. Mainly for internal use.

__init__(content=None)[source]

pyexlatex.models.date module

class pyexlatex.models.date.Date(contents=None)[source]

Bases: pyexlatex.models.item.SimpleItem

__init__(contents=None)[source]
name = 'date'

pyexlatex.models.document module

class pyexlatex.models.document.Document(content, packages=None, landscape=False, title=None, authors=None, date=None, abstract=None, skip_title_page=False, page_modifier_str='margin=0.8in, bottom=1.2in', page_header=False, page_numbers=True, appendix_modifier_str='page', section_numbering_styles=None, floats_at_end=False, floats_at_end_options='nolists', document_type='article', font_size=None, num_columns=None, line_spacing=None, tables_relative_font_size=0, figures_relative_font_size=0, page_style='fancy', custom_headers=None, custom_footers=None, remove_section_numbering=False, separate_abstract_page=False, extra_title_page_lines=None, empty_title_page_style=False, pre_output_func=None, apply_page_style_to_section_starts=False, extra_pre_env_contents=None)[source]

Bases: pyexlatex.models.document.DocumentBase

Main class used for creating latex documents.

__init__(content, packages=None, landscape=False, title=None, authors=None, date=None, abstract=None, skip_title_page=False, page_modifier_str='margin=0.8in, bottom=1.2in', page_header=False, page_numbers=True, appendix_modifier_str='page', section_numbering_styles=None, floats_at_end=False, floats_at_end_options='nolists', document_type='article', font_size=None, num_columns=None, line_spacing=None, tables_relative_font_size=0, figures_relative_font_size=0, page_style='fancy', custom_headers=None, custom_footers=None, remove_section_numbering=False, separate_abstract_page=False, extra_title_page_lines=None, empty_title_page_style=False, pre_output_func=None, apply_page_style_to_section_starts=False, extra_pre_env_contents=None)[source]
Parameters
  • content (Union[IsLatexItemMixin, str, Sequence[Union[IsLatexItemMixin, str]]]) –

  • packages (Optional[List[Package]]) –

  • pre_env_contents

  • data_cleanup_func – should accept DocumentSetupData and modify it in place. This is called just before using the data.

  • pre_output_func (Optional[Callable]) – function which modifies the latex string before outputting it. The function should accepts a single argument which is a string of the entire latex contents, and it should return a string which will be used as the latex contents for output.

construct_packages(packages=None, page_modifier_str='margin=0.8in, bottom=1.2in', appendix_modifier_str='page', floats_at_end=False, floats_at_end_options='nolists', line_spacing=None, tables_relative_font_size=0, figures_relative_font_size=0)[source]
Return type

List[Package]

name = 'document'
class pyexlatex.models.document.DocumentBase(content, packages=None, pre_env_contents=None, data_cleanup_func=None, pre_output_func=None)[source]

Bases: pyexlatex.models.containeritem.ContainerItem, pyexlatex.models.item.Item

__init__(content, packages=None, pre_env_contents=None, data_cleanup_func=None, pre_output_func=None)[source]
Parameters
document_class_obj: Optional[pyexlatex.models.control.documentclass.documentclass.DocumentClass] = None
classmethod from_ambiguous_collection(collection, **document_kwargs)[source]
name = '<invalid, do not use DocumentBase directly>'
to_html(outfolder, outname='document', move_folder_name='Tables', as_document=True, date_time_move=False)[source]
to_pdf(outfolder, outname='document', move_folder_name='Tables', as_document=True, date_time_move=False)[source]
class pyexlatex.models.document.DocumentEnvironment[source]

Bases: pyexlatex.models.environment.Environment

__init__()[source]
name = 'document'
pyexlatex.models.document.get_table_figure_size_packages(tables_relative_font_size=0, figures_relative_font_size=0, floatrow_table_options='capposition=top', floatrow_figure_options='capposition=top')[source]
Return type

List[ItemBase]

pyexlatex.models.documentitem module

class pyexlatex.models.documentitem.DocumentItem(*args, **kwargs)[source]

Bases: pyexlatex.models.mixins.IsSpecificClassMixin, pyexlatex.models.item.IsLatexItemMixin

Used for differentiating which items can be directly included in a document

is_DocumentItem = True

pyexlatex.models.documentsetup module

class pyexlatex.models.documentsetup.DocumentSetupData(filepaths=None, binaries=None, begin_document_items=None, end_document_items=None, packages=None, source_paths=None, references=None, flags=None)[source]

Bases: mixins.repr.ReprMixin, mixins.attrequals.EqOnAttrsMixin, mixins.attrequals.EqHashMixin

__init__(filepaths=None, binaries=None, begin_document_items=None, end_document_items=None, packages=None, source_paths=None, references=None, flags=None)[source]
property attrs: List[str]
Return type

List[str]

equal_attrs = ['filepaths', 'binaries', 'begin_document_items', 'end_document_items', 'packages', 'source_paths', 'references', 'flags']
ignore_attrs = ['ignore_attrs', 'repr_cols', 'attrs', 'readable_repr', 'equal_attrs']
non_unique_attrs = ['filepaths', 'binaries']
repr_cols: List[str] = ['filepaths', 'begin_document_items', 'end_document_items', 'packages', 'source_paths', 'references', 'flags']
class pyexlatex.models.documentsetup.UniqueDataList(iterable)[source]

Bases: list

A list where the items are always unique.

__init__(iterable)[source]
append(value)[source]

Append object to the end of the list.

extend(iterable)[source]

Extend list by appending elements from the iterable.

class pyexlatex.models.documentsetup.UniquePackagesList(packages=None)[source]

Bases: pyexlatex.models.documentsetup.UniqueDataList

A unique data list that allows passing of just a string to represent a package

__init__(packages=None)[source]
append(package)[source]

Append object to the end of the list.

delete_by_name(name)[source]
extend(packages=None)[source]

Extend list by appending elements from the iterable.

get_by_name(name)[source]

pyexlatex.models.environment module

class pyexlatex.models.environment.Environment(name, modifiers=None, overlay=None)[source]

Bases: object

__init__(name, modifiers=None, overlay=None)[source]
wrap(other)[source]

pyexlatex.models.environmenttemplate module

class pyexlatex.models.environmenttemplate.EnvironmentTemplate(contents, **kwargs)[source]

Bases: pyexlatex.models.section.base.TextAreaMixin, pyexlatex.models.item.Item

Base class which makes it easy to create new environment types.

Examples: >>> import pyexlatex as pl >>> class BoldEnvironment(pl.EnvironmentTemplate): >>> name = ‘myenv’ >>> begin_def = r’f’ >>> end_def = ‘’ >>> >>> print(pl.Document(BoldEnvironment(‘woo’))) documentclass[]{article}

ewenvironment{myenv}{f}{}

… egin{document} egin{myenv} woo end{myenv} end{document}

__init__(contents, **kwargs)[source]
begin_def = ''
end_def = ''

pyexlatex.models.equation module

class pyexlatex.models.equation.Equation(eq=None, str_eq=None, inline=True, numbered=True)[source]

Bases: pyexlatex.models.mixins.IsSpecificClassMixin, pyexlatex.models.item.IsLatexItemMixin

Pass sympy or string equations to have them rendered in LaTeX.

__init__(eq=None, str_eq=None, inline=True, numbered=True)[source]
property eq_str
property formatted_eq
name = 'equation'

pyexlatex.models.footnote module

class pyexlatex.models.footnote.Footnote(contents)[source]

Bases: pyexlatex.models.item.SimpleItem

Creates a footnote at the bottom of the page, with a mark next to where the object itself is placed to reference the footnote.

__init__(contents)[source]
name = 'footnote'

pyexlatex.models.item module

class pyexlatex.models.item.DataItem[source]

Bases: object

add_package(package)[source]
init_data()[source]
class pyexlatex.models.item.EqualsItem(name, contents)[source]

Bases: pyexlatex.models.item.ItemBase

__init__(name, contents)[source]
class pyexlatex.models.item.IsLatexItemMixin[source]

Bases: object

is_LatexItem = True
class pyexlatex.models.item.Item(name, contents, pre_env_contents=None, post_env_contents=None, env_modifiers=None, overlay=None)[source]

Bases: pyexlatex.models.item.ItemBase

__init__(name, contents, pre_env_contents=None, post_env_contents=None, env_modifiers=None, overlay=None)[source]
equal_attrs = ['contents', 'pre_env_contents', 'post_env_contents', 'data', 'env']
class pyexlatex.models.item.ItemBase(*args, **kwargs)[source]

Bases: pyexlatex.models.item.DataItem, pyexlatex.models.mixins.IsSpecificClassMixin, pyexlatex.models.item.IsLatexItemMixin, pyexlatex.models.mixins.StringAdditionMixin, mixins.attrequals.EqHashMixin, mixins.attrequals.EqOnAttrsMixin

Base class for all latex generating classes

Note: Does not pass any args to super call, so do not put another class below this one expecting args to be passed

__init__(*args, **kwargs)[source]
class pyexlatex.models.item.MultiOptionSimpleItem(name, *options, overlay=None)[source]

Bases: pyexlatex.models.item.ItemBase

__init__(name, *options, overlay=None)[source]
class pyexlatex.models.item.NoBracesItem(name, contents, overlay=None)[source]

Bases: pyexlatex.models.item.ItemBase

__init__(name, contents, overlay=None)[source]
class pyexlatex.models.item.NoOptionsNoContentsItem(name, overlay=None, modifiers=None)[source]

Bases: pyexlatex.models.item.ItemBase

__init__(name, overlay=None, modifiers=None)[source]
class pyexlatex.models.item.SimpleItem(name, contents, modifiers=None, pre_modifiers=None, overlay=None, format_content=True)[source]

Bases: pyexlatex.models.item.ItemBase

__init__(name, contents, modifiers=None, pre_modifiers=None, overlay=None, format_content=True)[source]
equal_attrs = ['contents', 'modifiers', 'pre_modifiers', 'overlay', 'format_content', 'data']

pyexlatex.models.jinja module

class pyexlatex.models.jinja.DataString(string, data)[source]

Bases: pyexlatex.models.item.ItemBase

__init__(string, data)[source]
class pyexlatex.models.jinja.JinjaEnvironment(*args, **kwargs)[source]

Bases: jinja2.environment.Environment

A jinja Environment but with pyexlatex models as built in filters and handling extracting pyexlatex data

Examples:

>>> import pyexlatex as pl
>>> from jinja2 import DictLoader
>>> env = pl.JinjaEnvironment(
>>>     loader=DictLoader({'my_temp': '{{ my_var | Italics }}'})
>>> )
>>> temp = env.get_template('my_temp')
>>> str(temp.render(my_var='woo'))
'\textit{woo}'
__init__(*args, **kwargs)[source]
from_string(*args, **kwargs)[source]

Load a template from a source string without using loader.

Parameters
  • source – Jinja source to compile into a template.

  • globals – Extend the environment globals with these extra variables available for all renders of this template. If the template has already been loaded and cached, its globals are updated with any new items.

  • template_class – Return an instance of this Template class.

template_class

alias of pyexlatex.models.jinja.JinjaTemplate

class pyexlatex.models.jinja.JinjaTemplate(source, **kwargs)[source]

Bases: jinja2.environment.Template, pyexlatex.models.containeritem.ContainerItem

A jinja Template but with pyexlatex models as built-in filters and handling extracting pyexlatex data

Examples:

>>> import pyexlatex as pl
>>> str(pl.JinjaTemplate('{{ my_var | Italics }}').render(my_var='woo'))
'\textit{woo}'
__init__(*args, **kwargs)[source]
blocks: Dict[str, Callable[[jinja2.runtime.Context], Iterator[str]]]
environment: jinja2.environment.Environment
filename: Optional[str]
globals: MutableMapping[str, Any]
name: Optional[str]
render(*args, **kwargs)[source]

This method accepts the same arguments as the dict constructor: A dict, a dict subclass or some keyword arguments. If no arguments are given the context will be empty. These two calls do the same:

template.render(knights='that say nih')
template.render({'knights': 'that say nih'})

This will return the rendered template as a string.

root_render_func: Callable[[jinja2.runtime.Context], Iterator[str]]
pyexlatex.models.jinja.class_factory(latex_class, *args, **kwargs)[source]
pyexlatex.models.jinja.get_capitalized_items(items)[source]
Return type

List[str]

pyexlatex.models.label module

class pyexlatex.models.label.Label(contents)[source]

Bases: pyexlatex.models.item.SimpleItem

A label which can later be referred to by Ref

__init__(contents)[source]
name = 'label'

pyexlatex.models.landscape module

class pyexlatex.models.landscape.Landscape[source]

Bases: pyexlatex.models.environment.Environment

__init__()[source]
name = 'landscape'

pyexlatex.models.latex module

class pyexlatex.models.latex.LaTeX(**kwargs)[source]

Bases: pyexlatex.models.item.SimpleItem

Displays the string “LaTeX” with special formatting

__init__(**kwargs)[source]
name = 'LaTeX'

pyexlatex.models.mixins module

class pyexlatex.models.mixins.IsSpecificClassMixin(*args, **kwargs)[source]

Bases: object

creates attribute is_ClassName (with whatever class name)

be sure to put this mixin first among multiple classes

__init__(*args, **kwargs)[source]
class pyexlatex.models.mixins.StringAdditionMixin[source]

Bases: object

join(iterable)[source]
class pyexlatex.models.mixins.StringEqMixin[source]

Bases: object

pyexlatex.models.model module

class pyexlatex.models.model.Model(template_str=None, template_path=None, environment=None)[source]

Bases: pyexlatex.models.template.Template

A data model combined with a Jinja template.

Passes any class variables and methods to template to render the output string. Subclass this class to create your own data models for templates.

Set exclude_attrs class variable as a list of strings of any attributes which should not be passed to the template.

Examples:

>>> import pyexlatex as pl
>>> template_str = "{{ my_var | Bold }} {{ my_link }} {{ my_text }}"
>>>
>>> class MyModel(pl.Model):
>>>     my_var = 'woo'
>>>     my_link = pl.Hyperlink('https://www.google.com', 'Link!!!!')
>>>
>>>     def __init__(self, my_text: str, *args, **kwargs):
>>>         self.my_text = my_text
>>>         super().__init__(*args, **kwargs)
>>>
>>> model = MyModel('stuff', template_str=template_str)
>>> str(model)
'\textbf{woo} \href{https://www.google.com}{Link!!!!} stuff '
__init__(template_str=None, template_path=None, environment=None)[source]
property environment
exclude_attrs: List[str] = []
property render_dict: Dict[str, Any]
Return type

Dict[str, Any]

property template: pyexlatex.models.jinja.JinjaTemplate
Return type

JinjaTemplate

pyexlatex.models.package module

class pyexlatex.models.package.Package(name, modifier_str=None, eq_on_modifier=True)[source]

Bases: pyexlatex.models.package.PackageBase

Represents LaTeX usepackage{}, pass to Document if any custom LaTeX packages are needed.

class pyexlatex.models.package.PackageBase(name, modifier_str=None, eq_on_modifier=True)[source]

Bases: pyexlatex.models.item.ItemBase

Base class for usepackage and RequirePackage

__init__(name, modifier_str=None, eq_on_modifier=True)[source]
Parameters
  • name (str) – Name of LaTeX package

  • modifier_str (Optional[str]) – any options to be passed to the LaTeX package. E.g. if ‘abc=true’ is passed, it will render as usepackage[abc=true]{mypackage}

  • eq_on_modifier (bool) – Whether to consider any package options when checking equality of the package. Useful to set it to False when this package should not be added if it was previously added with different options

equal_attrs = ['name', 'modifier_str']
matches_name(other)[source]
class pyexlatex.models.package.RequirePackage(name, modifier_str=None, eq_on_modifier=True)[source]

Bases: pyexlatex.models.package.PackageBase

Represents LaTeX RequirePackage, usually useful when building cls files and packages.

pyexlatex.models.ref module

class pyexlatex.models.ref.NameRef(contents)[source]

Bases: pyexlatex.models.item.SimpleItem

Pass a label to create an in text reference to that label. Will display the name of the section in the text.

__init__(contents)[source]
name = 'nameref'
class pyexlatex.models.ref.Ref(contents)[source]

Bases: pyexlatex.models.item.SimpleItem

Pass a label to create an in text reference to that label. Will display the number of the section in the text.

__init__(contents)[source]
name = 'ref'

pyexlatex.models.standalone module

class pyexlatex.models.standalone.Standalone(content, packages=None, pre_env_contents=None, font_size=None, doc_class_options=None, pre_output_func=None)[source]

Bases: pyexlatex.models.document.DocumentBase

The main high-level class for creating one-off graphics, equations, etc. Does not provide any document structure and will crop the document to the contents.

__init__(content, packages=None, pre_env_contents=None, font_size=None, doc_class_options=None, pre_output_func=None)[source]
Parameters
  • content (Union[ItemBase, List[ItemBase]]) –

  • packages (Optional[List[Package]]) –

  • pre_env_contents (Union[ItemBase, List[ItemBase], None]) –

  • data_cleanup_func – should accept DocumentSetupData and modify it in place. This is called just before using the data.

  • pre_output_func (Optional[Callable]) – function which modifies the latex string before outputting it. The function should accepts a single argument which is a string of the entire latex contents, and it should return a string which will be used as the latex contents for output.

name = 'document'

pyexlatex.models.template module

exception pyexlatex.models.template.ContentParseException[source]

Bases: Exception

class pyexlatex.models.template.Template[source]

Bases: pyexlatex.models.section.base.TextAreaMixin, pyexlatex.models.item.ItemBase

Base class for creating custom Pyexlatex templates.

To use, simply subclass Template, then in __init__, set the attribute .contents, and call super().__init__(). The .contents attribute should be set to a string, pyexlatex object, or iterable of those.

Examples:

Contents can be a Pyexlatex object or string:

>>> import pyexlatex as pl
>>> class BoldUnderline(pl.Template):
>>>
>>>     def __init__(self, contents):
>>>         self.contents = pl.Bold(pl.Underline(contents))
>>>         super().__init__()
>>>
>>> print(BoldUnderline('woo'))
\textbf{\underline{woo}}

Contents can also be an iterable of strings or Pyexlatex objects

>>> import pyexlatex as pl
>>> class BoldAndUnderline(pl.Template):
>>>
>>>     def __init__(self, bold_contents, underline_contents, *other_contents):
>>>         self.contents = [
>>>             pl.Bold(bold_contents),
>>>             pl.Underline(underline_contents),
>>>             *other_contents
>>>         ]
>>>         super().__init__()
>>>
>>> print(BoldAndUnderline('woo bold', 'woo underline', 'something'))
\textbf{woo bold}
\underline{woo underline}
something
__init__()[source]

pyexlatex.models.toc module

class pyexlatex.models.toc.TableOfContents(options=None, **kwargs)[source]

Bases: pyexlatex.models.item.NoOptionsNoContentsItem

__init__(options=None, **kwargs)[source]
name = 'tableofcontents'
property options_str: Optional[str]
Return type

Optional[str]