Skip to main content

library to convert Markdown with included LaTeX-Formulas to HTML with MathML

Project description

mdtex2html

python3-library to convert Markdown with included LaTeX-Formulas to HTML with MathML

What is mdtex2html

mdtex2html is a library to convert (Github-flavored) Markdown-Code with included LaTex-formulas to HTML-Source. The formulas are converted to MathML.

An inline-formula can either start and end with $ or it can start with \( and end with \), according to valid LaTeX-Code. Block-formulas either start and end with $$ or start with \[ and end with \].

An example that mdtex2html will convert:

# Example-Title

TeX-Formula: $\sqrt2=x^2 \Rightarrow x=\sqrt{\sqrt{2}}$

- This
- is
    - a List with `inline-Code`

How to use mdtex2html

install it, i.e. using pip:

python3 -m pip install mdtex2html

then in python import in your code with

import mdtex2html

and convert your mdTeX with something like

mdtex2html.convert('- Hello ${\sqrt{World}}^2$!')

passing any mdTeX-Code to mdtex2html.convert().

Extra

You may want to (but don't need to) include this css-snippet on your page to hide error message texts, only showing on mouse-over:

.tooltip .tooltiptext {
    display: none;
}
.tooltip:hover .tooltiptext {
    display: inline;
    border-radius: 0.3em;
    background-color: #777;
    position: fixed;
}

Markdown-Extensions

Starting with v1.1 you can use python-markdown-extensions for i.e. tables, definition-lists, html-attributes and much more by passing a list of the extension(s) to be used to the convert-command as described in the python-markdown documentation.

For example mdtex2html.convert('Hello green\n{: style="color:green" }', extensions=['attr_list']) will make use of the extension attr_list.

Dependencies

This depends on:

The dependencies will be installed when installing using pip.

Limitations

The Firefox browser will display the result smoothly, as well as Safari (according to user reports).

Just be aware that the Chromium-engine (Browsers: Chrome, Edge, ...) still is not able to render MathML properly, but rumors say that in 2020 work has started again to make that happen, so maybe you want to check the status there.

Credits

Special thanks to Ronie Martinez for creating latex2html!

This library is just a few lines of code added to his work and to Python-Markdown.

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

mdtex2html-1.2.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mdtex2html-1.2.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file mdtex2html-1.2.0.tar.gz.

File metadata

  • Download URL: mdtex2html-1.2.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.3

File hashes

Hashes for mdtex2html-1.2.0.tar.gz
Algorithm Hash digest
SHA256 0331218de4ff4ad2979313573165347078fbafe1142667b4a44c3a45d672d8ba
MD5 bcdd93c559ab26fa00b22e8cc118f76f
BLAKE2b-256 8f2e32c341520a4957718e6ac89bbdd9d934ad17783093e5407bc140312677dc

See more details on using hashes here.

File details

Details for the file mdtex2html-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: mdtex2html-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.3

File hashes

Hashes for mdtex2html-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bd1b3848b6457e5badda9c6530d897a69ec731568af7021633278b5cd5ce7e8d
MD5 2a154057155fbfc6e970a3bb522fb333
BLAKE2b-256 47fa5156a032ad68f6c32ae0dc3aaf8b3d690004b42497d4735a08bb4cea6ec3

See more details on using hashes here.

Supported by

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