Skip to main content

Tools for Latex Documents

Project description

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}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nlcLatex-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

nlcLatex-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file nlcLatex-0.1.0.tar.gz.

File metadata

  • Download URL: nlcLatex-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for nlcLatex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b8e5cc545414dc5939b8f8c2f89fd52b9b033756a47a01ba7c35b7950e73ae7d
MD5 49d222f1c58ac18e54a5ce607c56b1d5
BLAKE2b-256 d2afff8e13fa3a32346192395671758536327b81684fc33a1d2a9c4482f0856f

See more details on using hashes here.

File details

Details for the file nlcLatex-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nlcLatex-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for nlcLatex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 34f77edbf320cc498aaf344337d0e769a0827d50f28f31c437bae2739f88beb0
MD5 a7bb99fb002fe9e164d332759353b0e3
BLAKE2b-256 3dee6ed9f462b46223bfe4cd29f39064c0615171c64599061cc5ac6f8f83ea3a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page