Skip to main content

md4mathjax

this is a python-markdown extension. basicly learning from the pelican plugin render-math. and i think inside its code, the mathjax extension split would be better.

原插件做了很多额外的工作,但现在mathjax对于数学公式写法上的支持已经很强大了,很多额外的工作都是没有必要的了。

本插件做的两个工作一就是检测markdown文档里面是否有数学公式,如果有则插入mathjax的js支持代码。

本插件还有一个工作就是因为markdown的EscapeInlineProcessor机制存在, \(...\) \[...\) 这两个写法会被安全处理为(...) [...],按照markdown文档转义字符设计,这是没有问题的,应该不会变动了。本插件通过正则判定某段确实是数学字符,行 \(...\) 会更改为 \\(...\\) ,而 \[...\] 会被更改为 $$...$$。

很简单直观的一个插件,同时又完成了必要的工作。tests文件夹下可以有输出html文件参考。

Usage

This Extension is writing in the Python-Markdown Recommend way, so basically it's usage can reference the Python-Markdown Extension Usage document.

本插件在写法是Python-Markdown的统一写法,因此使用可以参看Python-Markdown的插件使用文档。

in pelican

MARKDOWN = {
    'extensions': [
        'md4mathjax'
    ],
}

参数

mathjax_src

default: https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js

mathjax_id

default: MathJax-script

mathjax_settings

default:

DEFUALT_MATHJAX_SETTING = r"""
window.MathJax = {}
"""

In python assign this value do not forget the prefix r .

CHANGELOG

0.2.0

程序处理流程进一步简化,不再用span或者div封装,只专注于解决因为转义而出现的问题和mathjax相关js代码的自动注入。

不再对 $...$ 这样的写法默认支持,这样的写法也不是很推荐,如果之前有大量的文档采用了这种写法,那么配置需要做如下更改:

{'md4mathjax': {
    'mathjax_settings': r"""
    window.MathJax = {
              tex: {
                inlineMath: {'[+]': [['$', '$']]}
              }
            };
         """
     }}

来继续保持对 $...$ 原来写法的支持。

原来默认增加了对 mhchem 的支持,现在默认没有增加了,你需要按照mathjax官方文档的说明,增加这样的配置:

window.MathJax = {
  loader: {load: ['[tex]/mhchem']},
  tex: {packages: {'[+]': ['mhchem']}}
};

然后现在默认源使用的mathjax的V4版本。

0.1.3

fix escape issue.

0.1.2

README

0.1.1

解决了和toc插件不兼容的问题。

fixed a problem which is conflicted with the toc extension

0.1.0

初步编写完成

project started

Metadata

Release files for md4mathjax 0.2.0

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

Source distribution (sdist)

Source distribution for md4mathjax 0.2.0
File Size Uploaded
md4mathjax-0.2.0.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for md4mathjax 0.2.0
File Interpreter ABI Platform
md4mathjax-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.8 kB

Release files / md4mathjax-0.2.0.tar.gz

Download URL md4mathjax-0.2.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
758f99d3f05c411e54749100e262eb47665ed3e3469eb62708847a7fac5168e1
BLAKE2b-256 checksum
How to use checksums
ca8915a475a51ea1ae28c7b05398bfd851db6b9036aaf8c15f41fa3ee1be7183
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / md4mathjax-0.2.0-py3-none-any.whl

Download URL md4mathjax-0.2.0-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4adc2ed9ed7191e72a327b03462e23f632a005bcd3f8251d8f34f112e6da944
BLAKE2b-256 checksum
How to use checksums
d08b4c9e36c1d421211c1ed01444561eba3a113dca69e2a279777421cd18a155
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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