Mathjax 形式の HTML テキストがあります。
text = "an inline \\( f(x) = \frac{a}{b} \\) equation, a display equation \\[ F = m a \\] \n and another inline \\(y = x\\)"
(注: 方程式は単一のスラッシュで区切られます。たとえば\(
、 ではなく\\(
、余分な部分\
はルビ テキストの最初のスラッシュをエスケープするだけです)。
これを代用する出力を取得したい、たとえばlatex.codecogsによって作成された画像など
desired_output = "an inline <img src="http://latex.codecogs.com/png.latex?f(x) = \frac{a}{b}\inline"/> equation, a display equation <img src="http://latex.codecogs.com/png.latex?F = m a"/> \n and another inline <img src="http://latex.codecogs.com/png.latex?y = x\inline"/> "
ルビー使用。私は試します:
desired = text.gsub("(\\[)(.*?)(\\])", "<img src=\"http://latex.codecogs.com/png.latex?\2\" />")
desired = desired.gsub("(\\()(.*?)(\\))", "<img src=\"http://latex.codecogs.com/png.latex?\2\\inline\")
desired
しかし、これは失敗し、元の入力のみが返されます。私は何を取りこぼしたか?このクエリを適切に作成するにはどうすればよいですか?