PyTeXmd
Pytexmd is a Python package designed to translate LaTeX documents to Markdown MyST and HTML. It provides utilities for filtering content, loading files, and integrating with Sphinx documentation.
Documentation
- Full Documentation: pytexmd.readthedocs.io
- GitHub Repository: github.com/martinpflaum/pytexmd
Installation
To install the required dependencies for pytexmd, run:
pip install -r requirements.txt
you also need texlive https://www.tug.org/texlive/ and ghostscript https://ghostscript.com/releases/gsdnld.html
Python Usage Example
If you want to use pytexmd from a Python script, make sure your script is in the same folder (or a subfolder) as the pytexmd package, or add pytexmd to your Python path. The following example can also be found in the examples folder:
copyright = '2025, Author'
author = 'Author'
release = '1.0'
extensions = ['myst_parser',
"sphinx_proof"]
templates_path = ['_templates']
exclude_patterns = []
mathjax3_config = {
"tex": {
"macros": {
"ltortoise": "\\unicode{x3014}",
"rtortoise": "\\unicode{x3015}",
"ltsbrak": ["\\mathopen{\\ltortoise\\mspace{1mu}}", 0],
"rtsbrak": ["\\mathopen{\\mspace{1mu}\\rtortoise}", 0],
"mathbbm": ["\\mathbb{#1}", 1],
"widebar": ["\\overline{#1}", 1],
"C": "\\mathbb{C}",
}
}
}
myst_enable_extensions = [
"amsmath",
"attrs_inline",
"attrs_block",
"colon_fence",
"deflist",
"dollarmath",
"fieldlist",
"html_admonition",
"html_image",
"replacements",
"smartquotes",
"strikethrough",
"substitution",
"tasklist",
]
prf_realtyp_to_countertyp = {
"axiom": "theorem",
"theorem": "theorem",
"lemma": "theorem",
"algorithm": "theorem",
"definition": "theorem",
"remark": "theorem",
"conjecture": "theorem",
"corollary": "theorem",
"criterion": "theorem",
"example": "theorem",
"property": "theorem",
"observation": "theorem",
"proposition": "theorem",
"assumption": "theorem",
"notation": "theorem",
}
#math_number_all = True # number *all* displayed equations
math_eqref_format = "({number})" # how equation refs look
html_theme = 'furo'
html_static_path = ['_static']
#math_number_all = True # number *all* displayed equations
math_eqref_format = "({number})" # how equation refs look
numfig = True # enable section-prefixed numbering
math_numfig = True # apply section prefix to equations
numfig_secnum_depth = 2 # use # and ## levels (e.g. 1.2.3)
html_theme = 'furo'
html_static_path = ['_static']
# Custom theorem types (auto-generated by pytexmd)
import sphinx_proof.nodes
import sphinx_proof.proof_type
import sphinx_proof.directive
import sphinx_proof.domain
from docutils import nodes
from sphinx_proof.directive import ElementDirective
class theorem_and_definition_node(nodes.Admonition, nodes.Element):
pass
class TheoremAndDefinitionDirective(ElementDirective):
name = "theorem_and_definition"
class proposition_and_definition_node(nodes.Admonition, nodes.Element):
pass
class PropositionAndDefinitionDirective(ElementDirective):
name = "proposition_and_definition"
_CUSTOM_TYPES = {
"theorem_and_definition": (theorem_and_definition_node, TheoremAndDefinitionDirective),
"proposition_and_definition": (proposition_and_definition_node, PropositionAndDefinitionDirective),
}
for _name, (_node_cls, _directive_cls) in _CUSTOM_TYPES.items():
sphinx_proof.nodes.NODE_TYPES[_name] = _node_cls
sphinx_proof.proof_type.PROOF_TYPES[_name] = _directive_cls
sphinx_proof.directive.DEFAULT_REALTYP_TO_COUNTERTYP[_name] = _name
sphinx_proof.domain.ProofDomain.directives[_name] = _directive_cls
prf_realtyp_to_countertyp[_name] = "theorem"
# Monkey-patch the 4 realtyp.title() calls in sphinx_proof.nodes so that
# underscored names like 'theorem_and_definition' render as
# 'Theorem And Definition' instead of 'Theorem_And_Definition'.
import sphinx_proof.nodes as _spn
import sphinx_proof as _sp
from sphinx.writers.latex import LaTeXTranslator as _LaTeXTranslator
def _depart_enumerable_node(self, node):
countertyp = node.attributes.get("countertype", "")
realtyp = node.attributes.get("realtype", "")
display = realtyp.replace("_", " ").title()
if isinstance(self, _LaTeXTranslator):
number = _spn.get_node_number(self, node, countertyp)
idx = _spn.list_rindex(self.body, _spn.latex_admonition_start) + 2
self.body.insert(idx, f"{display} {number}")
self.body.append(_spn.latex_admonition_end)
else:
number = _spn.get_node_number(self, node, countertyp)
idx = self.body.index(f"{countertyp} {number} ")
self.body[idx] = f"{_spn._(display)} {number} "
self.body.append("</div>")
def _depart_unenumerable_node(self, node):
realtyp = node.attributes.get("realtype", "")
display = realtyp.replace("_", " ").title()
node_id = node.attributes.get("ids", [""])[0]
if isinstance(self, _LaTeXTranslator):
idx = _spn.list_rindex(self.body, _spn.latex_admonition_start) + 2
self.body.insert(idx, display)
self.body.append(_spn.latex_admonition_end)
else:
search_str = f'<p class="admonition-title" id="{node_id}">'
idx = _spn.list_rindex(self.body, search_str) + 1
element = f'<span class="caption-number">{_spn._(display)} </span>'
self.body.insert(idx, element)
self.body.append("</div>")
# Patch both the nodes module AND sphinx_proof's __init__ namespace.
# sphinx_proof/__init__.py does `from .nodes import depart_enumerable_node`
# which binds the name in its own globals. Sphinx's setup() looks up the name
# there, so patching only sphinx_proof.nodes has no effect.
_spn.depart_enumerable_node = _depart_enumerable_node
_spn.depart_unenumerable_node = _depart_unenumerable_node
_sp.depart_enumerable_node = _depart_enumerable_node
_sp.depart_unenumerable_node = _depart_unenumerable_node
numfig_format = {
"theorem_and_definition": "Theorem and Definition %s",
"proposition_and_definition": "Proposition and Definition %s",
}
also in the file loader make sure that all .bib files are found also in folder mentioned in the \input thingies than concatenate these .bib file but eliminate duplicated entries also copy this thing to the created sphinx project also use of sphinxcontrib-bibtex
Release files for pytexmd 1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytexmd-1.1.tar.gz | 46.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytexmd-1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 97.5 kB
Release files / pytexmd-1.1.tar.gz
| Download URL | pytexmd-1.1.tar.gz |
|---|---|
| Size | 46.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9252d4c1424893dd56560fbb6fba813c1ae16ef5d851416cae8ac2b5b68f510f
|
|
BLAKE2b-256 checksum How to use checksums |
4accd7739e7bc4e7e82bdc45db4b7a2479a416f210cb8daead6d2dad8fc76529
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / pytexmd-1.1-py3-none-any.whl
| Download URL | pytexmd-1.1-py3-none-any.whl |
|---|---|
| Size | 51.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bbb7fe5994338f4eb6fffb8e14d7167c8016143b7ba810922fe0331bbef8e911
|
|
BLAKE2b-256 checksum How to use checksums |
db5b399080ac325c3300647b52765b0130b9beb284bd9b0a27b8d9d132978290
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|