py2LaTeX¶
Create LaTeX documents with Python, Markdown and Jinja2.
Docs |
|
---|---|
Tests |
|
PyPI |
|
Activity |
|
QA |
|
Other |
python3 -m pip install py2latex --user
python3 -m pip install git+https://github.com/domdfcoding/py2latex@master --user
py2latex
¶
Create LaTeX documents with Python, Markdown and Jinja2.
Functions:
|
Construct a LaTeX document from the given elements. |
py2latex.colors
¶
Functions:
|
Make the given text black. |
|
Make the given text blue. |
|
Make the given text brown. |
|
Make the given text the given colour. |
|
Make the given text cyan. |
|
Make the given text darkgray. |
|
Make the given text darkgrey. |
|
Make the given text gray. |
|
Make the given text green. |
|
Make the given text grey. |
|
Make the given text lime. |
|
Make the given text magenta. |
|
Make the given text olive. |
|
Make the given text orange. |
|
Make the given text pink. |
|
Make the given text purple. |
|
Make the given text red. |
|
Make the given text teal. |
|
Make the given text violet. |
|
Make the given text white. |
|
Make the given text yellow. |
-
colour
(text_colour, text)[source]¶ Make the given text the given colour.
Akin to
\color{text_colour}{string}
.
py2latex.core
¶
Core functionality.
Functions:
|
Akin to |
|
Akin to |
|
Akin to |
|
Akin to |
|
Escape literal backslashes for use with |
py2latex.formatting
¶
Functions:
|
Make the given value bold. |
|
Make the given value italic. |
|
Returns the LaTeX subscript of the given value. |
|
Returns the LaTeX superscript of the given value. |
|
Underline the given value. |
py2latex.packages
¶
Functions:
|
Akin to |
py2latex.siunit
¶
Functions:
|
Create an siunitx-formatted formula from an astropy.units unit. |
|
Create an siunitx-formatted formula from an astropy.units unit. |
-
SI
(quantity, per_mode='symbol')[source]¶ Create an siunitx-formatted formula from an astropy.units unit.
py2latex.tables
¶
Classes:
|
Functions:
|
Add a caption to a longtable. |
|
Create a |
|
|
|
|
|
|
|
|
|
Override the column widths (and also the column alignments) in a tabular environment, etc. |
|
Create a series of |
|
Create a |
|
Create a |
-
class
SubTable
(tabular_data, *, caption, label=None, headers=(), floatfmt='g', numalign='decimal', stralign='left', missingval='', showindex='default', disable_numparse=False, colalign=None, colwidths=None, vlines=False, hlines=False, vspace=False, raw=True, footer=None)[source]¶ Bases:
object
- Parameters
caption (str) – The caption for the table
label (
Optional
[str
]) – The label for the table. If undefined the caption is used, in lowercase, with underscores replacing spaces DefaultNone
.headers (
Sequence
[str
]) – A sequence of column headers. Default()
.floatfmt (
Union
[str
,Iterable
[str
]]) – The formatting offloat
values. Default"g"
. Default'g'
.showindex (
Union
[str
,bool
,Iterable
[Any
]]) – Default'default'
.disable_numparse (
Union
[bool
,Iterable
[int
]]) – DefaultFalse
.colalign (
Optional
[Sequence
[Optional
[str
]]]) – DefaultNone
.colwidths (
Optional
[Sequence
[Optional
[str
]]]) – Sequence of column widths, e.g.3cm
. Values ofNone
indicates auto width. DefaultNone
.vlines (
Union
[Sequence
[int
],bool
]) – If a sequence of integers a line will be inserted before the specified columns.-1
indicates a line should be inserted after the last column. IfTrue
a line will be inserted before every column, and after the last column. IfFalse
no lines will be inserted. DefaultFalse
.hlines (
Union
[Sequence
[int
],bool
]) – If a sequence of integers a line will be inserted before the specified rows.-1
indicates a line should be inserted after the last row. IfTrue
a line will be inserted before every row, and after the last row. IfFalse
no lines will be inserted. DefaultFalse
.vspace (
Union
[Sequence
[int
],bool
]) – If a sequence of integers extra space will be inserted before the specified row.-1
indicates a space should be inserted after the last row. IfTrue
a space will be inserted before every row, and after the last row. IfFalse
no spaces will be inserted. DefaultFalse
.raw (bool) – Whether latex markup in
tabular_data
should be unescaped. DefaultFalse
. DefaultTrue
.footer (
Optional
[str
]) – Optional footer for the table. Inserted as raw LaTeX. DefaultNone
.
-
longtable_from_template
(tabular_data, *, caption, label=None, headers=(), pos='htpb', floatfmt='g', numalign='decimal', stralign='left', missingval='', showindex='default', disable_numparse=False, colalign=None, colwidths=None, vlines=False, hlines=False, vspace=False, raw=True, footer=None)[source]¶ Create a
longtable
withbooktabs
formatting.- Parameters
caption (str) – The caption for the table
label (
Optional
[str
]) – The label for the table. If undefined the caption is used, in lowercase, with underscores replacing spaces DefaultNone
.headers (
Sequence
[str
]) – A sequence of column headers. Default()
.pos (str) – The positioning of the table, e.g.
"htp"
. Default'htpb'
.floatfmt (
Union
[str
,Iterable
[str
]]) – The formatting offloat
values. Default"g"
. Default'g'
.showindex (
Union
[str
,bool
,Iterable
[Any
]]) – Default'default'
.disable_numparse (
Union
[bool
,Iterable
[int
]]) – DefaultFalse
.colalign (
Optional
[Sequence
[Optional
[str
]]]) – DefaultNone
.colwidths (
Optional
[Sequence
[Optional
[str
]]]) – Sequence of column widths, e.g.3cm
. Values ofNone
indicates auto width. DefaultNone
.vlines (
Union
[Sequence
[int
],bool
]) – If a sequence of integers a line will be inserted before the specified columns.-1
indicates a line should be inserted after the last column. IfTrue
a line will be inserted before every column, and after the last column. IfFalse
no lines will be inserted. DefaultFalse
.hlines (
Union
[Sequence
[int
],bool
]) – If a sequence of integers a line will be inserted before the specified rows.-1
indicates a line should be inserted after the last row. IfTrue
a line will be inserted before every row, and after the last row. IfFalse
no lines will be inserted. DefaultFalse
.vspace (
Union
[Sequence
[int
],bool
]) – If a sequence of integers extra space will be inserted before the specified row.-1
indicates a space should be inserted after the last row. IfTrue
a space will be inserted before every row, and after the last row. IfFalse
no spaces will be inserted. DefaultFalse
.raw (bool) – Whether latex markup in
tabular_data
should be unescaped. DefaultFalse
. DefaultTrue
.footer (
Optional
[str
]) – Optional footer for the table. Inserted as raw LaTeX. DefaultNone
.
- Returns
- Return type
-
set_table_widths
(table, widths)[source]¶ Override the column widths (and also the column alignments) in a tabular environment, etc.
-
subtables_from_template
(subtables, *, caption, label=None, pos='htpb')[source]¶ Create a series of
subtables
withbooktabs
formatting.- Parameters
- Returns
- Return type
-
table_from_template
(tabular_data, *, caption, label=None, headers=(), pos='htpb', floatfmt='g', numalign='decimal', stralign='left', missingval='', showindex='default', disable_numparse=False, colalign=None, colwidths=None, vlines=False, hlines=False, vspace=False, raw=True, footer=None)[source]¶ Create a
table
withbooktabs
formatting.- Parameters
caption (str) – The caption for the table
label (
Optional
[str
]) – The label for the table. If undefined the caption is used, in lowercase, with underscores replacing spaces DefaultNone
.headers (
Sequence
[str
]) – A sequence of column headers. Default()
.pos (str) – The positioning of the table, e.g.
"htp"
. Default'htpb'
.floatfmt (
Union
[str
,Iterable
[str
]]) – The formatting offloat
values. Default"g"
. Default'g'
.showindex (
Union
[str
,bool
,Iterable
[Any
]]) – Default'default'
.disable_numparse (
Union
[bool
,Iterable
[int
]]) – DefaultFalse
.colalign (
Optional
[Sequence
[Optional
[str
]]]) – DefaultNone
.colwidths (
Optional
[Sequence
[Optional
[str
]]]) – Sequence of column widths, e.g.3cm
. Values ofNone
indicates auto width. DefaultNone
.vlines (
Union
[Sequence
[int
],bool
]) – If a sequence of integers a line will be inserted before the specified columns.-1
indicates a line should be inserted after the last column. IfTrue
a line will be inserted before every column, and after the last column. IfFalse
no lines will be inserted. DefaultFalse
.hlines (
Union
[Sequence
[int
],bool
]) – If a sequence of integers a line will be inserted before the specified rows.-1
indicates a line should be inserted after the last row. IfTrue
a line will be inserted before every row, and after the last row. IfFalse
no lines will be inserted. DefaultFalse
.vspace (
Union
[Sequence
[int
],bool
]) – If a sequence of integers extra space will be inserted before the specified row.-1
indicates a space should be inserted after the last row. IfTrue
a space will be inserted before every row, and after the last row. IfFalse
no spaces will be inserted. DefaultFalse
.raw (bool) – Whether latex markup in
tabular_data
should be unescaped. DefaultFalse
. DefaultTrue
.footer (
Optional
[str
]) – Optional footer for the table. Inserted as raw LaTeX. DefaultNone
.
- Returns
- Return type
-
tabular_from_template
(tabular_data, *, headers=(), floatfmt='g', numalign='decimal', stralign='left', missingval='', showindex='default', disable_numparse=False, colalign=None, colwidths=None, vlines=False, hlines=False, vspace=False, raw=True, footer=None, no_lines=False, left_margin=True, right_margin=True)[source]¶ Create a
tabular
environment withbooktabs
formatting.- Parameters
headers (
Sequence
[str
]) – A sequence of column headers. Default()
.floatfmt (
Union
[str
,Iterable
[str
]]) – The formatting offloat
values. Default"g"
. Default'g'
.showindex (
Union
[str
,bool
,Iterable
[Any
]]) – Default'default'
.disable_numparse (
Union
[bool
,Iterable
[int
]]) – DefaultFalse
.colalign (
Optional
[Sequence
[Optional
[str
]]]) – DefaultNone
.colwidths (
Optional
[Sequence
[Optional
[str
]]]) – Sequence of column widths, e.g.3cm
. Values ofNone
indicates auto width. DefaultNone
.vlines (
Union
[Sequence
[int
],bool
]) – If a sequence of integers a line will be inserted before the specified columns.-1
indicates a line should be inserted after the last column. IfTrue
a line will be inserted before every column, and after the last column. IfFalse
no lines will be inserted. DefaultFalse
.hlines (
Union
[Sequence
[int
],bool
]) – If a sequence of integers a line will be inserted before the specified rows.-1
indicates a line should be inserted after the last row. IfTrue
a line will be inserted before every row, and after the last row. IfFalse
no lines will be inserted. DefaultFalse
.vspace (
Union
[Sequence
[int
],bool
]) – If a sequence of integers extra space will be inserted before the specified row.-1
indicates a space should be inserted after the last row. IfTrue
a space will be inserted before every row, and after the last row. IfFalse
no spaces will be inserted. DefaultFalse
.raw (bool) – Whether latex markup in
tabular_data
should be unescaped. DefaultFalse
. DefaultTrue
.footer (
Optional
[str
]) – Optional footer for the table. Inserted as raw LaTeX. DefaultNone
.no_lines (
bool
) – Whether to suppress horizontal lines in the table. DefaultFalse
. DefaultFalse
.left_margin (
bool
) – Whether to include a margin to the left of the table. DefaultTrue
. DefaultTrue
.right_margin (
bool
) – Whether to include a margin to the right of the table. DefaultTrue
. DefaultTrue
.
- Returns
- Return type
Overview¶
py2LaTeX
uses tox to automate testing and packaging,
and pre-commit to maintain code quality.
Install pre-commit
with pip
and install the git hook:
python -m pip install pre-commit
pre-commit install
Coding style¶
formate is used for code formatting.
It can be run manually via pre-commit
:
pre-commit run formate -a
Or, to run the complete autoformatting suite:
pre-commit run -a
Automated tests¶
Tests are run with tox
and pytest
.
To run tests for a specific Python version, such as Python 3.6:
tox -e py36
To run tests for all Python versions, simply run:
tox
Build documentation locally¶
The documentation is powered by Sphinx. A local copy of the documentation can be built with tox
:
tox -e docs
License¶
py2LaTeX
is licensed under the MIT License
A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.
Permissions | Conditions | Limitations |
---|---|---|
|
|
Copyright (c) 2020 Dominic Davis-Foster
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
Downloading source code¶
The py2LaTeX
source code is available on GitHub,
and can be accessed from the following URL: https://github.com/domdfcoding/py2latex
If you have git
installed, you can clone the repository with the following command:
git clone https://github.com/domdfcoding/py2latex
Cloning into 'py2latex'...
remote: Enumerating objects: 47, done.
remote: Counting objects: 100% (47/47), done.
remote: Compressing objects: 100% (41/41), done.
remote: Total 173 (delta 16), reused 17 (delta 6), pack-reused 126
Receiving objects: 100% (173/173), 126.56 KiB | 678.00 KiB/s, done.
Resolving deltas: 100% (66/66), done.

Downloading a ‘zip’ file of the source code¶
Building from source¶
The recommended way to build py2LaTeX
is to use tox:
tox -e build
The source and wheel distributions will be in the directory dist
.
If you wish, you may also use pep517.build or another PEP 517-compatible build tool.
View the Function Index or browse the Source Code.