Adding Math and Graphviz to Pelican

In the AI era, I felt that math was too important for my next studies and work, so I decided to give Pelican the ability to display mathematical expressions.

MathJax Mathematical Formula

Option selection

Pelican shows mathematical formulas, which can be achieved in three ways:

Programme Plugin Modalities
KaTeX Rendering pelican-katex Convert formulae to HTML/MathML on generation
MathJax Browser render pelican-render-math Browser loads MathJax.js dynamic rendering
LaTeX to SVG pelican-math-svg Call LaTeX to compile the formula into a SVG image embedded page

I compared it to the second.pelican-render-mathIt is easier to do so, using the original operating environment of Pelican.

Install Configuration

UsepipInstallation:

pip install pelican-render-math

If it's working,uvUse:

uv add pelican-render-math

And then..pelicanconf.py, and add:

PLUGINS = ["render_math"]
MATH_JAX = {
    "align": "center",
    "auto_insert": True,
    "process_escapes": True,
    "latex_preview": "TeX",
    "color": "inherit",
    "linebreak_automatic": False,
    "responsive": True,
    "responsive_break": 768,
    "process_summary": True,
}

Comments on parameters

Examples of effects

Now we'll try the effect:

A mathematical formula for the same line:\(\dfrac{1}{1+x^2}\)

The code is:

同一行数学公式:$\dfrac{1}{1+x^2}$

Independent line complex mathematical formula:

$$ \begin{pmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{n1} & a_{n2} & \cdots & a_{nn} \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \end{pmatrix} = \lambda \begin{pmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \end{pmatrix} $$

The code is:

独立行复杂数学公式:

$$
\begin{pmatrix}
a_{11} & a_{12} & \cdots & a_{1n} \\
a_{21} & a_{22} & \cdots & a_{2n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{n1} & a_{n2} & \cdots & a_{nn}
\end{pmatrix}
\begin{pmatrix}
x_1 \\ x_2 \\ \vdots \\ x_n
\end{pmatrix}
=
\lambda
\begin{pmatrix}
x_1 \\ x_2 \\ \vdots \\ x_n
\end{pmatrix}
$$

Graphviz Chart

Besides the mathematical formula, I added the function of the Graphviz diagram, because I felt it was important.

Install a Grampviz program

First of all, you need to install the Graphviz application itself.

scoop install graphviz
brew install graphviz
apt install graphviz

Install Pelican-graphviz plugin

If usedpipInstallation:

pip install pelican-graphviz

If it's working,uvUse:

uv add pelican-graphviz

Yes.pelicanconf.py, and amend:

PLUGINS = ["graphviz", "render_math"]

Examples of effects

A more complex example:

finite_state_machine

Look at the effect. It's code:

一个比较复杂的例子:

..graphviz dot
digraph finite_state_machine {
    rankdir=LR;
    size="8,5";
    fontsize=10;
    ranksep=1.5;
    nodesep=1.0;
    overlap=false;
    splines=true;
    node [fontsize=14];
    edge [fontsize=12];
    node [shape = doublecircle]; S3 [color=red, style=filled, fillcolor=lightpink];
    node [shape = circle];
    S1 [color=blue, style=filled, fillcolor=lightblue];
    S2 [color=darkgreen, style=filled, fillcolor=lightgreen];
    subgraph cluster_guard {
        label = "守护条件:计数 < 3";
        style=dashed;
        fontsize=10;
        color=purple;
        C1 [shape=box, label="错误计数器", style=filled, fillcolor=gold, fontsize=8];
    }
    S1 -> S2 [ label = "开始", xlabel="动作:重置计数器", fontsize=10, color=blue ];
    S2 -> S1 [ label = "停止", fontsize=10, color=darkgreen ];
    S2 -> S3 [ label = "错误", xlabel="条件:增加计数器", fontsize=10, color=red ];
    S3 -> S2 [ label = "恢复", fontsize=10, color=red ];
    S2 -> C1 [style=dotted, arrowhead=none, color=purple];
}

Attention.:..graphviz dotYou can't be free in the code block.