I have a some HTML text in mathjax format:
text = \"an inline \\\\( f(x) = \\frac{a}{b} \\\\) equation, a display equation \\\\[ F = m a \\\\] \\n and anothe
Try:
desired = text.gsub(/\\\[\s*(.*?)\s*\\\]/, "<img src=\"http://latex.codecogs.com/png.latex?\\1\"/>")
desired = desired.gsub(/\\\(\s*(.*?)\s*\\\)/, "<img src=\"http://latex.codecogs.com/png.latex?\\1\inline\"/>")
desired
The important changes that had to happen:
gsub
should be a regex (as Anthony mentioned)\\2
(instead of just \2
) (see the rdoc)\
There were a couple of other minor formatting things (spaces, etc).
Not sure if your regexp is right - but in Ruby, Regexp are delimited by //
, try like this :
desired = text.gsub(/(\\[)(.*?)(\\])/, "<img src=\"http://latex.codecogs.com/png.latex?\2\" />")
You were trying to do string substition, and of course gsub wasn't finding a string containing (\\[)(.*?)(\\])