Skip to main content

DocHINT

DocHINT (recursive acronym for DocHINT Is Not a Typesetter) is a command-line program and Python package that processes text macros for authoring HTML documents. DocHINT takes as input text files that contain macro commands, and evaluates those macros to produce HTML text as output. Macros are provided for functionality including escaping special characters, generating MathML from LaTeX maths notation, cross-referencing, and managing citations (with BibTeX support), and the user may additionally define custom macros.

DocHINT can work on either a single source file, or multiple source files that constitute a single document. The latter mode of operation is particularly useful for authoring EPUBs, e.g. in combination with epubsynth, and to support this use-case, DocHINT is designed to generate XHTML-compliant output.

Example

As an example, given (abridged) input HTML text containing macros

<p>Pythagoras' theorem\cite{saikia2013pythagorastheorem} is</p>
\mathblock{a^2 + b^2 = c^2;}
<p>this is illustrated in Figure \ref{fig:pythagoras}</p>
...
<h2>References</h2>
\bibliography

the (abridged) output is

<p>Pythagoras' theorem[<a href="#saikia2013pythagorastheorem">1</a>] is</p>
<div class='mathsblock'><math alttext="a^2 + b^2 = c^2;" display="block" xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>a</mi><mn>2</mn></msup><mo>+</mo><msup><mi>b</mi><mn>2</mn></msup><mo>=</mo><msup><mi>c</mi><mn>2</mn></msup><mo>;</mo></math></div>
<p>this is illustrated in Figure <a href="#fig:pythagoras">1</a></p>
...
<h2>References</h2>
<ol>
<li id="saikia2013pythagorastheorem">Manjil&#160;P. Saikia.
The pythagoras' theorem.
2013.
URL: <a href="https://arxiv.org/abs/1310.0986">https://arxiv.org/abs/1310.0986</a>, <a href="https://arxiv.org/abs/1310.0986">arXiv:1310.0986</a>.</li>
</ol>

containing a cross-reference link, MathML, and a formatted citation.

As another, extended, example, here is the source for an EPUB version of my Honours thesis, generated using DocHINT and epubsynth.

Installation

Arch Linux: Use the official Arch User Repository (AUR) package maintained by myself.

PyPI: Use pip install dochint to install DocHINT from PyPI.

Manual Installation: Use make install and make uninstall to install and uninstall DocHINT respectively. DocHINT's runtime dependencies are the Python interpreter and the pybtex, and it additionally has a build-time dependency on maturin for building Rust internals.

Conceptual Overview

DocHINT works as a "state machine", in which it copies input text to the output except when the macro prefix (by default \) is encountered, at which point DocHINT instead processes the macro and produces an output in place of it, returning to echoing/copying mode after that.

After encountering the macro prefix, the following text is read to find the macro command, an identifier that can either be a string of "identifier" characters (regex \w: letters, digits, and _) or a single non-identifier character. After that, the macro is evaluated; many macros take some additional text following their identifier as input. Once the macro has been evaluated, its resultant text is appended to the output, and the DocHINT state machine returns to the normal "copy input to output until the macro prefix is encountered" mode.

Macro logic may be stateful, with the result text of a macro being affected by other macros. To allow macros to be affected by other macros that come after them in the source text, DocHINT works in two passes. In the first pass, the procedure described above is done, but macros may defer (delay) producing their result text until the second pass, in which all deferred macro results are evaluated.

DocHINT is intended for use in authoring HTML documents insofar as all built-in macros generate HTML code, but DocHINT is not aware of the HTML structure of the input text surrounding and outside of macros. In particular, macros inside HTML comments are not ignored.

Invoking DocHINT

DocHINT can be used through either the command line or as a Python package.

Command-Line Interface

The command-line program dochint has an interface that takes a sequence of input file names as positional arguments, and some options:

dochint NAME... [OPTIONS...]

The NAMEs of the input files correspond to the file names/paths used for URIs generated by macros (e.g. cross-reference hyperlinks). By default, DocHINT will look for source files of those names in the current working directory; to look in another directory, set --source-dir (aliases --src-dir and -d).

The location of the output is set using the --output option (alias -o). By default, this is interpreted as a file for single-file input (one NAME) and a directory for multi-file input (multiple NAMEs), in which case the output files have the same names as the input NAMEs. The output of multi-file processing can instead be concatenated into a single output file by setting --output-single-file. If --output is not set, output is instead printed to STDOUT.

Other options are:

  • --prefix PREFIX (alias -p): Set the macro command prefix (defaults to \).
  • --text-macro MACRO TO_TEXT: Define a custom macro that does simple text substitution. This option can occur multiple times.
  • --set-numbering NAME NUMBERING: In multi-file mode, (re)set the chapter numbering for a file; see Cross-Referencing for more information. This option can occur multiple times.

The command-line interface does not allow the user to define custom macros that have programmatic logic rather than being simple text substitutions; for this, the Python API must be used.

Python API

The Python package dochint is invoked through the functions dochint.process_text and dochint.process_texts for processing a single text source and multiple text sources respectively. These functions have the optional argument extra_macros for setting custom macros; see the docstrings for details.

Macros and Processing Behaviour

Macros in DocHINT (including user-defined macros) may either be static text substitutions or implement some computational logic. The latter case can further be broken down into two types: macros that take bracketed arguments as input (dochint.ArgsMacro in the Python API), or those which are state machines consuming as input an arbitrary amount of the text that follows them (dochint.RawMacro in the Python API). Out of the built-in macros in DocHINT, only \verb and \verbatim (which are aliases of each other) are RawMacros, with all others being either ArgsMacros or static text substitution.

In a syntax similar to that of TeX, an ArgsMacro and its arguments look something like \command[optional1]{mandatory1}{mandatory2}, with first a sequence of zero or more optional arguments (i.e. that may be omitted) enclosed in [], and then a sequence of zero or more mandatory arguments enclosed in {}. Any whitespace is permitted before an opening bracket and after a closing bracket. Unlike in TeX, however, brackets around single-character arguments may not be omitted. Arguments for macros come in one of three types:

  • Identifier-like, in which brackets in the argument text can be escaped by preceding them with the macro prefix, as can the macro prefix itself. For example, the macro \id{abc\{\\\}} has input string abc{\}.
  • TeX-like, in which brackets preceded by \ (always \, not the customisable macro prefix) are not counted for finding the balancing bracket that ends the argument, but the preceding \ is still part of the argument text. For example, the macro \math{x \in \{1, 2, 3} has input string x \in \{1, 2, 3.
  • Document-like, in which the argument text may itself contain DocHINT macros, which are handled normally, and brackets can be escaped by preceding them with the macro prefix (i.e. there are additional macros which print the brackets). For example, the macro \footnote{See Reference \cite{some_paper}.} would have input See Reference [<a href="#some_paper">24</a>]. given that the citation with identifier some_paper is the 24th source cited.

In this section, ArgsMacro syntax will be notated with brackets corresponding to the sequence of optional and mandatory arguments, with the brackets containing the argument name, followed by a colon, followed by a letter i, t, or d for which of the three types of argument it is. For example: \equation[label: d]{id: i}{latex: t} takes a document-like optional argument label, an identifier-like mandatory argument id, and a TeX-like mandatory argument latex.

Escaping Special Characters

\<

Static text macro printing &lt;.

\>

Static text macro printing &gt;.

\&

Static text macro printing &amp;.

\'

Static text macro printing &apos;.

\"

Static text macro printing &quot;.

\<newline>

Static text macro printing the empty string, used to escape line breaks. To be clear, the macro command identifier here is the newline character, not any part of the literal text <newline>. For example, in processing, the text

<p>The quick brown fox jumped \
over the lazy dog.</p>

becomes

<p>The quick brown fox jumped over the lazy dog.</p>

\\

Prints the literal macro prefix. Note that this escape sequence is not a macro in the normal sense; it is always two of the macro prefix in a row, not necessarily \. For example, if the macro prefix is changed to @, this escape sequence is instead @@.

\verbatim|...|

RawMacro used to escape all HTML special characters in an extended block of text. The first character following the macro command sets the "delimiter" of the macro input, such that the macro consumes and processes all text up to the second occurrence of that character. For example, \verbatim|1 < 2| becomes 1 &lt; 2, as does \verbatim!1 < 2! or \verbatim\1 < 2\.

Alias: \verb.

Converting LaTeX to MathML

Conversion of LaTeX to MathML is done internally using the pulldown-latex Rust library crate. The output conforms to the MathML Core standard, which is a subset of MathML that is broadly supported by web browsers.

However, MathML Core can't represent certain LaTeX features as semantic elements (namely, alignments as in the align, array, and cases environments), and so these instead need to be implemented with CSS. The pulldown-latex project has its own recommended stylesheet, but this is somewhat opinionated, so a smaller stylesheet that fixes these problems with minimal styling is provided in Appendix: CSS for Maths Alignments.

\maths{latex: t}

Converts LaTeX maths notation latex into inline MathML, generating a <math> element with the following attributes:

  • alttext, whose value is the latex input text, properly quoted and escaped.
  • xmlns="http://www.w3.org/1998/Math/MathML", for XHTML compliance.
  • display="inline".

Aliases: \math, \m, \imath, \imaths.

\mathsblock{latex: t}

Converts LaTeX maths notation latex into block-display MathML, generating a <math> element with the following attributes:

  • alttext, whose value is the latex input text, properly quoted and escaped.
  • xmlns="http://www.w3.org/1998/Math/MathML", for XHTML compliance.
  • display="block".

The <math> element is wrapped in a <div class='mathsblock'> element.

Aliases: \mathblock, \bmath, \bmaths, \dmath, \dmaths.

Cross-Referencing

DocHINT's cross-referencing system uses and builds on top of the id attributes of HTML elements. A cross-reference has an identifier which is the id attribute of the element being cross-referenced, and a "label" which is the text displayed in hyperlinks to that cross-reference, which may either be specified by the user or automatically generated by DocHINT as sequential numbering.

Sequential number labelling of cross-references is done in the order that cross-references are declared (e.g. using the \id macro). If a cross-reference identifier contains . or :, the text before the first occurrence of either of those characters is the namespace for that cross-reference's numberings, with different namespaces having separate numberings. For example, fig:my:figure belongs to the namespace fig, and eq.my_equation belongs to the namespace eq, and the presence of one does not affect the other's numbering.

Additionally, when DocHINT is processing multiple input files, sequentially numbered labels are prefixed with the file number in the document, e.g. the second automatically-labelled cross-reference (in a given namespace) in the third file is labelled 3.2. This file counter can be reset, or set to a Roman letter (e.g. for appendices) using the --set-numbering option in the command-line interface or the numberings option of the dochint.process_texts function in the Python API.

\id[label: d]{id: i}

Declares a cross-reference with identifier id and optionally label label, and outputs id properly quoted and escaped for use as an attribute. For example, <figure id=\id{fig:my_plot}> becomes <figure id="fig:my_plot">. If label is not provided, a sequentially-numbered label is set as described above.

\ref{id: i}

Generates a hyperlink (<a> element) to the element cross-referenced by id, assuming that that is the value of the element's id attribute, with the cross-reference label as the link text. For example, for a cross-reference with identifier fig:my_plot and label 2, Figure \ref{fig:my_plot} becomes Figure <a href="#fig:my_plot">2</a>.

\tref{id: i}

Outputs the label of the cross-reference with identifier id. For example, for a cross-reference with identifier eq:pythagoras and label 7, Equation \tref{eq:pythagoras} becomes Equation 7. Therefore, this is like \ref but does not generate a hyperlink.

\equation[label: d]{id: i}{latex: t}

Converts LaTeX maths notation latex into MathML, which is then placed inside a <figure> element to which a cross-reference with identifier id is declared, optionally with label label. The cross-reference label is then placed inside the figure's <figcaption> element. Namely, this is equivalent to <figure class='equation' id=\id[label]{id}>\mathblock{latex}<figcaption>(\tref{id})</figcaption></figure>.

Some CSS for placing the figure caption to the right of the MathML, as in a numbered equation, is:

figure.equation
{
    display: flex;
    align-items: center;
    justify-content: space-between;
}

figure.equation div.mathsblock
{
    flex-grow: 1;
}

figure.equation figcaption
{
    margin-left: 1em;
}

Alias: \eqn.

Citations and Bibliography

For citation/bibliography management in DocHINT, bibliography items can be declared either from BibTeX source, or manually as a pre-formatted reference. These are then listed in a central bibliography, as well as referenced in in-text citations which link to the corresponding bibliography entry.

BibTeX processing is done internally using the pybtex Python package, which is a dependency of DocHINT.

\cite{ids: i}

Generates an in-text citation for each bibliography item whose identifier occurs in ids, a comma-separated list of reference identifiers. This takes the form of numbered hyperlinks, e.g. \cite{some_paper,other_paper} becomes [<a href="#some_paper">12</a>,<a href="#other_paper">13</a>] if these are the 12th and 13th unique in-text citations.

Citations are numbered in the order that they are first referenced in the text, not in the order that bibliography items are defined.

\addbibliographyitem{id: i}{bibtext: d}

Declares a bibliography item with identifier id and bibliography text bibtext, and outputs the empty string.

Alias: \addbibitem.

\addbibtextext{bibtex: t}

Declares all bibliography items occurring in the BibTeX string bibtex, and outputs the empty string.

\addbibtexfile{fpath: i}

Declares all bibliography items occurring in the BibTeX text file at location fpath, and outputs the empty string. fpath is relative to --source-dir in the command-line interface or the cwd option in the dochint.process_text and dochint.process_texts Python API functions, if these options are set, or relative to the process' working directory if they are not set.

\printbibliography

Generates a formatted bibliography as an <ol> element listing each bibliography item in the order that bibliography items are first referenced in-text, such that the numbering matches that of the in-text citations. Can be invoked multiple times, but each invocation outputs the full bibliography of the document, making multiple invocations duplicates of each other, except that only the first one has id attributes set for the <li> list items.

Alias: \bibliography.

Footnotes

\footnote{text: d}

Declares a footnote with text text, and outputs a superscripted hyperlink to where it is later printed using \printfootnotes, for example <sup><a href="#_footnote_1_2">2</a></sup>. The hyperlink text is a sequential numbering of footnotes, which resets after every invocation of \printfootnotes.

\printfootnotes

Prints all footnotes that have been declared since the last invocation of this command, or the beginning of the document if this is the first invocation. This is a sequence of <p> elements, one for each footnote, containing the superscripted number of the footnote followed by the footnote text. These <p> elements have automatically assigned id attributes like _footnote_1_2, with the first number being how many times \printfootnote has been invoked (including this time), and the second number being the footnote number.

It is generally recommended to place this command inside a <footer> element; some e-reader software seems to expect this for footnotes.

Alias: \footnotes.

Appendix: CSS for Maths Alignments

mtable.menv-alignlike > mtr > mtd
{
    padding-left: 0;
    padding-right: 0;
}

mtable.menv-alignlike > mtr > mtd:nth-child(odd)
{
    text-align: right;
}
mtable.menv-alignlike > mtr > mtd:nth-child(even)
{
    text-align: left;
}

mtable.menv-alignlike > mtr > mtd:nth-child(odd):not(:first-child)
{
    padding-left: 2em;
}

mtable.menv-cells-left > mtr > mtd
{
    text-align: left;
}

mtd.cell-left
{
    text-align: left;
}

mtd.cell-right
{
    text-align: right;
}

mtable.menv-cases > mtr > mtd
{
    padding-left: 0;
    padding-right: 0;
}

mtable.menv-cases > mtr > mtd + mtd
{
    padding-left: 1em;
}

Metadata

Release files for dochint 1.0.4

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

Source distribution (sdist)

Source distribution for dochint 1.0.4
File Size Uploaded Provenance Actions
dochint-1.0.4.tar.gz 39.0 kB Without provenance Details for dochint-1.0.4.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for dochint 1.0.4
File Actions
dochint-1.0.4-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details for dochint-1.0.4-cp310-abi3-win_arm64.whl
dochint-1.0.4-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for dochint-1.0.4-cp310-abi3-win_amd64.whl
dochint-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for dochint-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl
dochint-1.0.4-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details for dochint-1.0.4-cp310-abi3-musllinux_1_2_aarch64.whl
dochint-1.0.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for dochint-1.0.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
dochint-1.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for dochint-1.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
dochint-1.0.4-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64), macOS 11.0+ ARM64, macOS 10.12+ x86-64 Details for dochint-1.0.4-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Total release size: 2.6 MB

Release files / dochint-1.0.4.tar.gz

Download URL dochint-1.0.4.tar.gz
Size 39.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b4661ce9a7d5c688753cd96b9dc24a1d2f191d71cfbdc2787e1844d19d853ea2
BLAKE2b-256 checksum
How to use checksums
f2a885a63de5a06369453d97e7a84ac518c6ca280b3466abe039460bfec7163d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / dochint-1.0.4-cp310-abi3-win_arm64.whl

Download URL dochint-1.0.4-cp310-abi3-win_arm64.whl
Size 246.5 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
14b2f7f6744d232cd0d471e8427fc5a4895b55d0951b6bb4053459e8ece0f416
BLAKE2b-256 checksum
How to use checksums
45bbdc0c60b247f3fdc7a18ca5158dee32c525bf9e3fe659c26bb19d52cf042f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / dochint-1.0.4-cp310-abi3-win_amd64.whl

Download URL dochint-1.0.4-cp310-abi3-win_amd64.whl
Size 247.8 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
55a348d384d365a65cbf2f7b5e91236a4abd1e152dadc92932f2e58575a9a968
BLAKE2b-256 checksum
How to use checksums
dbf4319895728f84ee0f917263a49c3d77b6f27f736006f0d09caa93bd625330
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / dochint-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL dochint-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl
Size 354.3 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
5efd8fbee0a0fe88454eb441c62e593fa15682ff2d61d23e56724ed8e8a6e79f
BLAKE2b-256 checksum
How to use checksums
27b070ebd1379dee57c108752eaae6c7db32e61b2902d048a779c612be0301e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / dochint-1.0.4-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL dochint-1.0.4-cp310-abi3-musllinux_1_2_aarch64.whl
Size 347.8 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
ecd8b0fda1fed1100998379d720e691d442f5326560160ee2a58d033c6f30a71
BLAKE2b-256 checksum
How to use checksums
1940a8b140c5a20e2617d360e1ddfcf5d9b7406c5cd2247c7aa99cebe4f70d98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / dochint-1.0.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL dochint-1.0.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 355.5 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
61f7310aa8b6525d7a2991e152bde036a9c990bd501c41007865c4916a376962
BLAKE2b-256 checksum
How to use checksums
72b37f8381909ed4b102ca8d68e095a0db45fd46394f604c55b7041a6f43c7a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / dochint-1.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL dochint-1.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 348.8 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
7f43c6acfb612aa13c9e166206735750af187c162b66ed537ced16013daa6e75
BLAKE2b-256 checksum
How to use checksums
5abe5457edc984957789eec5ad0e7c0891725a2773e043857e7bff891354b622
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / dochint-1.0.4-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Download URL dochint-1.0.4-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 619.5 kB
Tags CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7a1a1cf72a77618ba24422008b14b52ec66ae590707b999715179abbb74e41e0
BLAKE2b-256 checksum
How to use checksums
c708b8fe76e76f9ea68e7c36984b6139321b6faa5aa3b93acdbf9b563fa6c0e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Security for dochint 1.0.4

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.

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