$...$を数式に変換するPopupMenu
script.jsscrapbox.PopupMenu.addButton({
title: 'LaTeX→Scb',
onClick: (text) => text.replace(
// $...$ -> [$ ... ]
// /\$([^\$\n]+)\$/g, '[$ $1 ]'
/\$(.+?)\$/g, '[$ $1 ]'
こういうのを置換
script.js ).replace(
// \(...\) -> [$ ... ]
/\\\((.+?)\\\)/g, '[$ $1 ]'
こういうのを置換
script.js ).replace(
// > $$
// > ...
// > $$
// -> >[$ ... ]
/\$\$(.+?)\$\$/gs, (match, p1) => '[$ ' + p1.replace(/\n/g, ' ').replace(/\s*>/g, '') + ' ]'
こういうのを置換
マッチした文字列の改行をスペースに置換
script.js ).replace(
// > \[
// > ...
// > \]
// -> [$ ... ]
/\\\[(.+?)\\\]/gs, (match, p1) => '[$ ' + p1.replace(/\n/g, ' ').replace(/\s*>/g, '') + ' ]'
こういうのを置換
script.js )//.replace(
// /\[([^$\[]+)\]/g, '[$ [$1] ]'
// ),
残った [...]
を数式にしたい
一旦除去
TODO
中に \left[ ... \right]
が入っている場合に対応
\[
\]
うまくいかない例

複数行の数式
$$
\begin{aligned}
\dot{\sigma}(t) & \stackrel{\text { def }}{=}-\frac{\partial}{\partial t} \boldsymbol{D}_{\mathrm{KL}}\left(P(\boldsymbol{x}, t) \mid P_{\mathrm{eq}}(\boldsymbol{x}, t)\right) \\
\end{aligned}
$$

複数ある場合
$$
\sin x = 1
$$
$$
\cos x = 0
$$