$...$を数式に変換するPopupMenu
code:script.js
scrapbox.PopupMenu.addButton({
title: 'LaTeX→Scb',
onClick: (text) => text.replace(
// $...$ -> $ ...
// /\$(^\$\n+)\$/g, '$ $1 '
/\$(.+?)\$/g, '$ $1 '
こういうのを置換
$ x $ and $y$
一行に複数ある場合に備えてlazy match
s (single line) (dotall) オプションをつけていないので、\nを除外する処理は不要
code:script.js
).replace(
// \(...\) -> $ ...
/\\\((.+?)\\\)/g, '$ $1 '
こういうのを置換
\( x \) and \(y\)
code:script.js
).replace(
// > $$
// > ...
// > $$
// -> >$ ...
/\$\$(.+?)\$\$/gs, (match, p1) => '$ ' + p1.replace(/\n/g, ' ').replace(/\s*>/g, '') + ' '
こういうのを置換
$$
\begin{aligned}
x & = r \cos \theta \\
y & = r \sin \theta
\end{aligned}
$$
s (single line)オプションをつけることで、.が\nにもマッチする
マッチした文字列の改行をスペースに置換
code:script.js
).replace(
// > \[
// > ...
// > \]
// -> $ ...
/\\\(.+?)\\\/gs, (match, p1) => '$ ' + p1.replace(/\n/g, ' ').replace(/\s*>/g, '') + ' '
こういうのを置換
\[
\begin{aligned}
x & = r \cos \theta \\
y & = r \sin \theta
\end{aligned}
\]
code:script.js
)//.replace(
// /\[([^$\[]+)\]/g, '$ [$1] '
// ),
残った[...]を数式にしたい
一旦除去
code:script.js
});
Mathpix Snipping Tool用
TODO
中に\left[ ... \right]が入っている場合に対応
とりあえず$...$を数式に変換するPopupMenu#6528ea63e5172d000070b719をコメントアウト
$\sin \left \Theta \right$
\[
\sin \left \Theta \right
\]
うまくいかない例
done.icon複数行の数式
$$
\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) \\
& =\beta \int_{-\infty}^{\infty} d \boldsymbol{x}^{\prime}\left\boldsymbol{v}\left(\boldsymbol{x}^{\prime}, t\right)\right^2 P\left(\boldsymbol{x}^{\prime}, t\right)
\end{aligned}
$$
done.icon複数ある場合
$$
\sin x = 1
$$
$$
\cos x = 0
$$
数式