I have a TXT file with LaTeX math equations where a single $ delimiter is used before and after each inline equation.
I would like to find each of the equations within a paragraph and replace the delimiters with XML opening and closing tags ....
E.g.,
The following paragraph:
This is the beginning of a paragraph $first equation$ ...and here is some text... $second equation$ ...and here is more text... $third equation$ ...and here is yet more text... $fourth equation$
should become:
This is the beginning of a paragraph <equation>first equation</equation> ...and here is some text... <equation>second equation</equation> ...and here is more text... <equation>third equation</equation> ...and here is yet more text... <equation>fourth equation</equation>
I have tried the sed and perl commands such as the following:
perl -p -e 's/(\$)(.*[^\$])(\$)/<equation>$2<\/equation>/'
But these commands result in the first and last instances of equations being converted but none of the equations between these two:
This is the beginning of a paragraph <equation>first equation$ ...and here is some text... $second equation$ ...and here is more text... $third equation$ ...and here is yet more text... $fourth equation</equation>
I also would like a robust solution that could take into account the presence of a single $ that is not used as a LaTeX delimiter. E.g.,
This is the beginning of a paragraph $first equation$ ...and here is some text that includes a single dollar sign: He paid $2.50 for a pack of cigarettes... $second equation$ ...and here is more text... $third equation$ ...and here is yet more text... $fourth equation$
does not become:
This is the beginning of a paragraph <equation>first equation$ ...and here is some text that includes a single dollar sign: He paid <equation>2.50 for a pack of cigarettes... $second equation$ ...and here is more text... $third equation$ ...and here is yet more text... $fourth equation</equation>
Note: I am writing in Bash.