Package: markdown-katex
markdown-katexThis is an extension forPython Markdownwhich addsKaTeXsupport.```math
f(x) = \int_{-\infty}^\infty
    \hat f(\xi)\,e^{2 \pi i \xi x}
    \,d\xi
```Project/Repo:Code Quality/CI:NamerolesinceuntilManuel Barkhau (mbarkhau@gmail.com)author/maintainer2019-05-Install$pipinstallmarkdown-katex
...
$python-mmarkdown_katex--version
markdown-katexversion:v202112.1034(usingbinary:/usr/local/bin/npx--no-installkatex)0.15.1This package includes the following binaries:katex_v0.15.1_node10_x86_64_Linux_katex_v0.15.1_node10_x86_64_Darwin_katex_v0.15.1_node12_x86_64_WindowsIf you are on a different platform, or want to use a more recent version ofkatex-cli, you will need toinstall it via npm.$npxkatex
$npxkatex--version0.15.1This extension will always use the locally installed version of KaTeX if it is available, instead of using the implementation bundled with this package.No JavaScript is required to render the resulting HTML, so it can be used with more limited renderers (which don't support JavaScript) such asWeasyPrint.UsageFormulas can be created and edited interactively using the editor onkatex.org. They also have somegood documentationfor the subset of LaTeX that is supported. When embedding these in your Markdown files, they must be marked with a special syntax in order to be rendered using KaTeX. There aremany syntax extensionsfor Markdown that allow LaTeX formulas to be embedded, however this package only supports the syntax introduced by Gitlab:For inline mode formulas: $`...`$For display mode formulas: ```mathHere isan examplethat uses this syntax.There are two main advantages of this syntax:Gitlab has an existing Markdown renderer that can be used without the need to download any software. This implementation also uses KaTeX, so the output should be exactly the same as this extension.The fallback behaviour of other Markdown renderers is to render the raw LaTeX as inline code or a code block. This means that they won't inadvertently parse a LaTeX formula as Markdown syntax.Hopefully other renderers will also adopt support for this syntax as:Rendering is done in the browser using KaTeX so implementation effort and should be minimal.The false positive rate for existing Markdown documents is negligible (i.e. existing alternate use of $` syntax is minimal to non-existent).Optionsno_inline_svg: Replace inline<svg>with<img data:image/svg+xml;base64..">tags.insert_fonts_css: Insert font loading stylesheet (default: True).Development/Testing$gitclonehttps://gitlab.com/mbarkhau/markdown-katex
$cdmarkdown-katex
$makeconda
$makelintmypytestMkDocs IntegrationIn yourmkdocs.ymladd this to markdown_extensions.# mkdocs.ymlmarkdown_extensions:-markdown_katex:no_inline_svg:Trueinsert_fonts_css:Truemacro-file:macros.texThemacro-filemight looks something like this:% macros.tex\mymacro:\text{prefix #1 suffix}WeasyPrint IntegrationWhen you generate html that is to be consumed byWeasyPrint, you need to use theno_inline_svg=Trueoption. This is due to along standing limitationof WeasyPrint. Without this option, some KaTeX formulas will not render properly, e.g.\sqrtmd_ctx=markdown.Markdown(extensions=['markdown.extensions.toc','markdown.extensions.extra','markdown.extensions.abbr',...'markdown_katex',],extension_configs={'markdown_katex':{'no_inline_svg':True,# fix for WeasyPrint'insert_fonts_css':True,},})raw_html_text=md_ctx.convert(md_text)You can also use markdown-katex for the conversion of individual formulas from tex to html:frommarkdown_katex.extensionimporttex2htmltex_text=r"""\frac{1}{\left(\sqrt{\phi\sqrt{5}}-\phi\right)e^{\frac{2}{5}\pi}}=1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\cdots}}}}"""options={'no_inline_svg':True,'insert_fonts_css':False}html=tex2html(tex_text,options)Changelog forhttps://gitlab.com/mbarkhau/markdown-katexContributorsThank you to for testing, reporting issues and contributing patches:@summersz - Richard Summers@bluhme3 - Evan Bluhm@pawamoy - Timothée Mazzucotelli@briankchan@spoorendonk@lisongmin@alexatadi@sacredfox - Akihiro Nomura@jnsdrtlf@dodoni - Markus Wendtv202112.1034Update KaTeX binaries to v0.15.1Fix#13: Don't strip<p></p>when using inline syntax for a single equation.v202106.1033Update KaTeX binaries to v0.13.18v202106.1032Fix#8: Math inside admonitionUpdate KaTeX binaries to v0.13.11v202105.1031Update KaTeX binaries to v0.13.6v202104.1030Update KaTeX binaries to v0.13.3Fix#4: Close file descriptors of PopenAdd support for blocks with extra backticksv202103.1029Fix#14: SinceMarkdown>=3.3support forMarkdown in HTMLwas broken.Thank you @summersz for reporting this issue.v202103.1028Use node12 for KaTeX binary on Windowsv202103.1027Update KaTeX binaries to v0.13.0v202008.1026Fix#12: Bug in handling of paths with whitespace. (Thanks @summersz !)v202008.1025Fix#9: Updatekatex.cssFix#8: Lookup of binaries on windowsUpdate documentation wrt. use with WeasyPrintv202008.1024Update KaTeX binaries to v0.12.0Fix#8: Update binaries...Fix#7: Lookup of binaries via npxv202006.1021Fix#7: File encoding issue on Windows.v202006.1020Fix#7katex-cli on Windows (now uses pkg --target node12...)Fix search for localkatex.ps1,katex.cmd,katex.exeon Windows.v202005.0017Allow use ofmacro-fileoption.Update katex-cli toversion v0.11.1v202005.0016-betaFix #6:Regression in code block parsing, introduced inv202004.0015-betav202004.0015-betaFix #3:Inline math inside blockv202004.0014-betaFix #4:Link tag not properly closedv202001.0013-betaFix: Ignore trailing whitespace after closing fence.v202001.0012-betaFix: Remove extraneous whitespace to work better with whitespace: pre.v201912.0011-betaAdd optioninsert_fonts_cssDocument optionsv201910.0010-betaAdd more prominent example to README.mdFix #2: Fix spurious log message when using MkDocsv201908.0009-betaFix #1: Wrong formulas are rendered when multiple formulas are in one doc.v201907.0008-betaFix: don't require typing package for py<35v201905.0007-betaFix: Parsing of inline code when using multiple backticksv201905.0004-betaFix: better error reportingFix: cleanup temp dirv201905.0002-alphaInitial release