toro has asked for the wisdom of the Perl Monks concerning the following question:
I'd like to extract LaTeX from between dollar signs. Practically, for a report. Can I do so using the XPath module? Or do I have to use a regex?
Example text:
We find that the generical scale behavior of structure functions in the inertial range is not self-similar $S_n(\ell)\propto \ell^{\zeta_n}$ but includes an “exponential self-similar” behavior $S_n(\ell) \propto \exp\zeta_n\alpha^{-1} \ell^{\alpha}$ where $\alpha$ is a parameter proportional to the inverse of the logarithm of the Reynolds number.
Regexing this is hard. I wrote a loop that counts up dollar signs and kills text to the left of odd \$'s. That seems garish. This is what XPath was made for, no? But $xp->find( "/html/body/p/$/text()" ) is wrong.
Thank you!
PS It would also be great if I could also convert e.g. Schr\"odinger to Schrödinger. The LaTeX package gogol shewed me is v0.01, so I can't use that.
ANSWER: The following one-liner, due to the monks, comprises a script to display equations on your web site (if you don't use mathJAX): $text =~ s#\$([^\$]+\$)#<img src="http://latex.codecogs.com/gif.latex?\\large%20\\dpi{150}%20\\bg_white%20\1" />#gm;. Cheers.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: LaTeX: regex or xpath?
by Corion (Patriarch) on Jun 09, 2011 at 20:09 UTC | |
by Eliya (Vicar) on Jun 09, 2011 at 20:25 UTC | |
by toro (Beadle) on Jun 09, 2011 at 20:26 UTC | |
by Eliya (Vicar) on Jun 09, 2011 at 20:31 UTC | |
by toro (Beadle) on Jun 09, 2011 at 22:14 UTC | |
|
Re: LaTeX: regex or xpath?
by choroba (Cardinal) on Jun 10, 2011 at 07:50 UTC | |
by toro (Beadle) on Jun 12, 2011 at 06:07 UTC |