Skip to main content

nlcLatex

This this the very first version. I removed logging to keep this very light and small. Logging and error responses will be added later.

Tools to create Latex Documents.

Processes files with extension .pytex inside any include / input is checked if

  • .pytex exists -> process this file
  • .py exists -> run as python. The script is expected to write a .tex file with the same name.

Process:

  1. load file and create / return document

    doc = nlcLatex.load(<filename>)

  2. process the includes within document

    doc.process()

  3. write LaTeX file

    doc.write()

  4. run pdflatex

    doc.run_latex()

nlcLatex.process takes the name of a .pytex-file and executes the steps mentioned above.

Providing Parameters (for Python scripts)

Parameters can be provided with in the respective \inclucde or \input statement in two formats:

  • \input[p1][p2][with space]{script-name}
  • \input[p1 p2 p3]{script-name}

The first form allows parameters with spaces, the second form is split at the whitespace to separate the parameters.

Note: I typically use the first parameter to signify the LaTeX section level, numerical from -1 to 5, or using the respective names (e.g. 'chapter').

Public Interface

Functions:

nlcLatex.load(<file-name>) or nlcLatex.Document(<file-name>)

Expects a .pytex-file that conforms to a regular LaTeX document with the possible exception of \include and \input format.

Returns an instance of nlcLatex.Document

nlcLatex.get_level(<level>, delta=0)

Returns the respective Latex-Name of the sectioning level, can be provided as integer or name. Delta allows to calculate up or down.

int name
-1 part
0 chapter
1 section
2 subsection
3 subsubsection
4 paragraph
5 subparagraph

Tip: Might be used like this:

f'\\{get_level(current, 1)}[Toc-Entry]{{Text}}

nlcLatex.latex_safe(<string>, visiblespace=False)

Returns a string that has special Latex-characters replaced with their respective escape sequences:

char replacement char replacement
& \& % \%
$ \$ # \#
_ \_ { \{
} \}
Unicode Character 'ZERO WIDTH SPACE' [U+200B] ● [U+25CF]
× [U+00D7] → $\rightarrow$
~ \textasciitilde{} ^ \textasciicircum{}

If visiblespace=True, spaces will be replaced with \textvisiblespace{} (␣)

nlcLatex.index_page(level=1)

Returns string to insert toc-entry for Index and issues \printindex

nlcLatex.ArgParser

Wrapper around argparse.ArgumentParser to remove double quotes around parameters (they are required to protect spaces).

Example

The following files can be stored in the same directory and show an example:

example01.py

import pathlib

from nlcLatex import get_level, latex_safe, ArgParser


def main(args):
    path = pathlib.Path(__file__)
    with open(path.with_suffix(".tex"), "w", encoding="utf8") as f:
        f.write("\\" f"{get_level(args.level)}" "{Test}\n\n")
        f.write(latex_safe(args.text, visiblespace=True))


if __name__ == "__main__":
    parser = ArgParser()

    parser.add_argument("level")
    parser.add_argument("text")

    main(parser.parse_args())

report.pytex

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}

    \title{Example Article}
    \author{Automated with \texttt{nlcLatex}}

    \maketitle

    \tableofcontents

    \vfill

    \section{Executive Summary}

    \input[subsection][A parameter]{example01}

    \section{Background}

\end{document}

Metadata

Release files for nlcLatex 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 nlcLatex 0.1.0
File Size Uploaded Provenance Actions
nlcLatex-0.1.0.tar.gz 5.4 kB Without provenance Details for nlcLatex-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nlcLatex 0.1.0
File Interpreter ABI Platform Actions
nlcLatex-0.1.0-py3-none-any.whl Python 3 none any Details for nlcLatex-0.1.0-py3-none-any.whl

Total release size: 11.2 kB

Release files / nlcLatex-0.1.0.tar.gz

Download URL nlcLatex-0.1.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b8e5cc545414dc5939b8f8c2f89fd52b9b033756a47a01ba7c35b7950e73ae7d
BLAKE2b-256 checksum
How to use checksums
d2afff8e13fa3a32346192395671758536327b81684fc33a1d2a9c4482f0856f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/48.0.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

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

Download URL nlcLatex-0.1.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
34f77edbf320cc498aaf344337d0e769a0827d50f28f31c437bae2739f88beb0
BLAKE2b-256 checksum
How to use checksums
3dee6ed9f462b46223bfe4cd29f39064c0615171c64599061cc5ac6f8f83ea3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/48.0.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Security for nlcLatex 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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