मैं mathjax प्रारूप में एक कुछ HTML पाठ है:माणिक regexp समीकरणों को बदलने के लिए
text = "an inline \\(f(x) = \frac{a}{b} \\) equation, a display equation \\[ F = m a \\] \n and another inline \\(y = x\\)"
(नोट: समीकरणों, एकल स्लैश द्वारा सीमांकित कर रहे हैं जैसे \(
, नहीं \\(
, अतिरिक्त \
सिर्फ पहले एक भागने है रूबी पाठ के लिए)।
मैं आउटपुट प्राप्त करना चाहता हूं जो इसे प्रतिस्थापित करता है, देर से 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
लेकिन यह असफल है, केवल मूल इनपुट लौटा रहा है। मुझसे क्या छूट गया? मैं इस सवाल को उचित तरीके से कैसे बना सकता हूं?
मामले किसी को भी इसके लिए लग रही है में, Jekyll प्लगइन मैं छवियों के साथ mathjax समीकरणों को बदलने के लिए है यहाँ लिखा है: https://github.com/cboettig/labnotebook/blob/32fcfcbc6f8d83b51d33d8d606ee1e51052dc4b0/_plugins/jekyll-labnotebook-plugins /codecogs.rb मदद के लिए @ जस्टिन-को धन्यवाद! – cboettig