\(\LaTeX\)+伪代码

August 26th, 2021 | 分类: 【部署】

How to write algorithms/pseudo-code ?

参考:https://stackoverflow.com/questions/15994354/how-to-write-algorithms-pseudo-code-in-html

【方案: pseudocode.js + MathJax 】

《使用 pseudocode.js 搭配 MathJax 更好地展示伪代码》
参考:http://cncc.bingj.com/cache.aspx?q=mathjax+%e4%bc%aa%e4%bb%a3%e7%a0%81&d=4545733493196907&mkt=zh-CN&setlang=zh-CN&w=i3Rdm5TpNjsTKWB6xVC0FEyjTbD3y2Su

pseudocode.js 通过 MathJax 或 KaTex 渲染数学公式。

源码:https://github.com/SaswatPadhi/pseudocode.js

代码:

    % This quicksort algorithm is extracted from Chapter 7, Introduction to Algorithms (3rd edition)
    \begin{algorithm}
    \caption{Quicksort}
    \begin{algorithmic}
    \PROCEDURE{Quicksort}{$A, p, r$}
        \IF{$p < r$} 
            \STATE $q = $ \CALL{Partition}{$A, p, r$}
            \STATE \CALL{Quicksort}{$A, p, q - 1$}
            \STATE \CALL{Quicksort}{$A, q + 1, r$}
        \ENDIF
    \ENDPROCEDURE
    \PROCEDURE{Partition}{$A, p, r$}
        \STATE $x = A[r]$
        \STATE $i = p - 1$
        \FOR{$j = p$ \TO $r - 1$}
            \IF{$A[j] < x$}
                \STATE $i = i + 1$
                \STATE exchange
                $A[i]$ with $A[j]$
            \ENDIF
            \STATE exchange $A[i]$ with $A[r]$
        \ENDFOR
    \ENDPROCEDURE
    \end{algorithmic}
    \end{algorithm}

问题:怎样在WordPress中实现呢?

参考:https://stackoverflow.com/questions/21192606/can-i-add-latex-packages-to-mathjax
参考:https://github.com/mathjax/MathJax-third-party-extensions

【方案:algorithm2e + LaTex 】

文档:http://tug.ctan.org/macros/latex/contrib/algorithm2e/doc/algorithm2e.pdf
文档:https://mirrors.hit.edu.cn/CTAN/macros/latex/contrib/algorithm2e/doc/algorithm2e.pdf

参考:https://jishuin.proginn.com/p/763bfbd2a73d
参考:https://cloud.tencent.com/developer/article/1827328
参考:https://zhuanlan.zhihu.com/p/266241159