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.


In reply to LaTeX: regex or xpath? by toro

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.