由于我自己有时把博客一些文章转过来论坛,通常都带一大堆公式,而且KaTex里的行内公式使用的“$”并不适用于论坛的"\("和"\)",于是码了个脚本(据说论坛会有支持,等站长调bug了hhh)


with open('input.md', 'r', encoding='utf-8') as f:
    data = f.read()

result = ''
isLeft = 1
brackets = {1: '\(', -1: '\)'}

for i in range(len(data)):
    if i == 0 or i == len(data)-1: 
        continue
    if data[i] == '$':
        if data[i-1] != '$' and data[i+1] != '$' and data[i-1] != '\\':
            result += brackets[isLeft]
            isLeft = -isLeft
            continue
    result += data[i]
    
with open('out.md', 'w', encoding='utf-8') as f:
    f.write(result)

大概意思是输入input.md的内容,逐字匹配$,并且筛除$$和\$,替换成\(或\),然后输出到out.md

    1 个月 后
    9 个月 后

    随着时间的推移和 Flarum 社区的完善,论坛现在支持 $1+1$ 这样的模式了,刚试了下可以 Tover @MingLLuo

    例子:已知 a>0, b> 0, c>0a^2 + b^2 = c^2,那么 c = \sqrt{a^2 + b^2}

      试一试......

      \mathcal{A}是一个非空集合的非空集合,\bigcup \mathcal{A} = \bigcup_{\forall A \in \mathcal{A}} A
      称函数f : \mathcal{A}\mapsto \bigcup \mathcal{A}\mathcal{A}的选择函数,如果
      函数f满足:\forall A \in \mathcal{A}f(A) \in A

      选择公理. 设\mathcal{A}是一个非空集合的非空集合,则存在集合\mathcal{A}的选择函数。

      Great!

      测试

      考虑向量 \vec x = \begin{bmatrix} x \\ y \end{bmatrix} ,水平扭曲矩阵 A = \begin{bmatrix} 1 & \tan(-\frac\theta 2) \\ 0 & 1 \end{bmatrix} ,则 A\vec x = \begin{bmatrix} x + y \tan(-\frac\theta 2) \\ y \end{bmatrix}

      联立化简 \left\{ \begin{matrix}\begin{aligned} &x_1 = x_0 + y_0 * \tan(-\frac\theta 2) \\ &y_1 = y_0 + x_1 * \tan(\varphi) \\ &x_2 = x_1 + y_1 * \tan(-\frac\theta 2) \end{aligned}\end{matrix}\right.\left\{ \begin{matrix}\begin{aligned} &x_0 = 0,\ y_0 = 1 \\ &\tan(-\theta) = \frac{x_2}{y_1} \end{aligned}\end{matrix}\right.\displaystyle\frac{\tan(\frac\theta 2)[\sec(\theta)\tan(\varphi) - \tan(\theta)]}{\tan(\frac\theta 2)\tan(\varphi) - 1} = 0

      \left[ \begin{matrix} \begin{aligned} &&\cdots &&\color{Red}{A[i-2]} &&\mathbf{\color{Red}{A[i-1]}} &&\mathbf{\color{Blue}{A[i']}} && \\\\ &&\cdots &&\color{Red}{B[j-2]} &&\mathbf{\color{Red}{B[j-1]}} &&\mathbf{\color{Blue}{B[j]}} && \end{aligned}\end{matrix} \right]

      lev_{A,\ B}(i,\ j) = \left\{ \begin{matrix} \begin{aligned} &i, &&when\ j=0 \\ &j, &&when\ i=0 \\ &min\left\{\begin{matrix}\begin{aligned} &lev_{a,\ b}(i,\ j-1) &+\ &1 \\ &lev_{a,\ b}(i-1,\ j) &+\ &1 \\ &lev_{a,\ b}(i-1,\ j-1) &+\ &1_{(a_i\neq b_i)} \end{aligned}\end{matrix}\right\}, &&otherwise \end{aligned}\end{matrix}\right.

      嗯没啥毛病, KaTeX 渲染的 html 一如既往的好用

        hsxfjames 考虑向量 \vec x = \begin{bmatrix} x \\ y \end{bmatrix} ,水平扭曲矩阵 A = \begin{bmatrix} 1 & \tan(-\frac\theta 2) \\ 0 & 1 \end{bmatrix} ,则 A\vec x = \begin{bmatrix} x + y \tan(-\frac\theta 2) \\ y \end{bmatrix}

        引用回帖测试


        0x0001 如果在编辑记录的 preview 模式里也支持下就更好了(逃

          hsxfjames 这个支持怕是有点难度,我回头先整个好跑的本地开发环境,有兴趣可以自己改(?然后顺便贡献上游社区哈哈!

          © 2018-2025 0xFFFF