Skip to main content

Some Utilities for Building Scientific LaTeX Documents Backed by Python Tasks

The focus lies on usage with PyTask, but this is not a strict requirement. Code which requires PyTask is behind an try-import guard.

Provided Modules

The modules are meant to be imported one-by-one as needed.

latex_task_utils.jinja

Configure a Jinja environment with custom control sequences to avoid collision with LaTeX syntax. The default config is stored in ENVIRONMENT_CONFIG and the environment is obtained with get_env(loader, **kwargs), where the kwargs override the default config.

latex_task_utils.matplotlib

Configure Matplotlib to output figures suitable for LaTeX documents by applying a config with use_default_config(overrides) and optionally use a preamble file with use_preamble(path).

The default config sets the figure size to 160 mm x 120 mm, the resolution to 600 dpi, configures some linewidths, uses constrained layout and lualatex/pgf as renderer.

If pytask is installed, a FigureNode class is provided which follows the PPathNode protocol an can be used to store a figure in multiple formats simultaneously. The figure is stored in the format defined by the main node path extension and additionally in those configured by DEFAULT_FORMATS or the additional_formats field of the node. For example with task returns:

def task_plot_something() -> Annotated[Figure, FigureNode.from_path(Path("test.pdf"), ["png", "svg"])]:
    fig = plt.figure()
    ...
    return fig

latex_task_utils.symbols

Define mathematical symbols in a TOML file and generate respective command definitions as well as a symbol index for LaTeX. This allows for single-source-of-truth definitions of your symbols. The commands are defined with \gdef to avoid creating groups around the symbols and thus make further sub- and superscripts work as with handwritten symbols (unlike other existing pure LaTeX packages like glossaries). These definitions also work usually without problems with the setups in scientific journals' production offices.

For flat symbol list use the following format:

SymI = { code = 'abc', doc = "A symbol." }
SymII = '\dot{#1}'
SymIII = { name = "Symbol 3", code = '\frac{#1}{#2}', doc = "Another symbol." }

For a categorized list the following:

doc = "The Root"

[symbols]

SymI = { code = 'abc', doc = "A symbol." }
SymII = '\dot{#1}'

[categories.CatI]
name = "Category 1"
doc = "SubCat"

[categories.CatI.symbols]
SymIII = { name = "Symbol 3", code = '\frac{#1}{#2}', doc = "Another symbol." }

The doc-strings and names are used in the symbols index to describe the meaning of the symbol. The key is used to generate the command name. Note that LaTeX does not allow numbers in command names. #1, #2 and so on can be used to include mandatory arguments in the symbols.

The flat file will lead to the following command usage:

$\SymI$
$\SymII{something}$
$\SymIII{some}{other}$

The categorized file will lead to the following command usage:

$\SymI$
$\SymII{something}$
$\CatISymIII{some}{other}$

Load the symbols from file with the read_toml(file) function and generate:

  • the command definitions with write_symbols_sty(file, symbols)
  • the symbols index with write_symbols_index(file, symbols, template, toplevel, heading).
symbols = read_toml("symbols.toml")
write_symbols_sty("symbols.sty", symbols)
write_symbols_index(
    "symbols.sty",
    symbols,
    template=SymbolsIndexTemplates.DESCRIPTION, # optional
    toplevel=0, # optional
    heading="List of Symbols" # optional
)

Metadata

Release files for latex-task-utils 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for latex-task-utils 0.1.0
File Size Uploaded
latex_task_utils-0.1.0.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for latex-task-utils 0.1.0
File Interpreter ABI Platform
latex_task_utils-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.0 kB

Release files / latex_task_utils-0.1.0.tar.gz

Download URL latex_task_utils-0.1.0.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e919d346d9f21a19debe389884294fa447cd1205299ca91b3744d85ca9cadb5f
BLAKE2b-256 checksum
How to use checksums
0adcb8be24d8c53f36dc2aba8cd6b37beeb3b42125e8ddac0480a7a72958e4d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.19

Release files / latex_task_utils-0.1.0-py3-none-any.whl

Download URL latex_task_utils-0.1.0-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4dbf242b53c2e98068578d3e85b54e4537d391ba3079209ec804a15519dc7df4
BLAKE2b-256 checksum
How to use checksums
cfaf26cd7c4f5cb702f518e974f20ea2312a92b6865874562016587c67217998
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.19

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page