I'm trying to write a script (in emacs lisp) to convert TeX display math style like, e.g.,
$$
x + y = z
$$
into the LaTeX
\begin{equation*}
x + y = z
\end{equation*}
To get my purpose I imagined this algorithm:
While scanning the file for the
"$$"strings, I would replace temporarily, once at time, the"$$"string with"$$\TESTIFDISPLAYMATH"where\TESTIFDISPLAYMATHis something like:\newcommand{\TESTIFDISPLAYMATH}{\mathchoice{\wlog{DISPLAY MATH OK}}{}{}{}}(this is necessary to avoid false positives like "$x,$$y,$")
At this point I'd compile my
.texfile to generate the.logfile and scanning it for my target string.After removing the
"\TESTIFDISPLAYMATH"string, if "DISPLAY MATH OK" I would perform my replacement.
My questions are:
Can I approach my task in a faster way? I mean, e.g., without the need to fully compile my
.texfile for each instance of"$$".Is there a tool that can do it already?
I'm open to any suggestion.
$$in a form like above what prevents you from simply using search & replace to transform$$\ninto\[\n(or something different)? – TeXnician Jan 15 '19 at 17:48.texfile. In emacs I would have used the syntactic highlighting but it not enough strong. – Gabriele Jan 15 '19 at 19:24\$\$\([^$]+\)\$\$→\\begin{equation}\1\\end{equation}. This does not match the false positive you mention because it only searches for$$…$$with no$between them. (It does fail for$x,$$y,$$z,$, but it seems unlikely something like that would appear in your document.) – Circumscribe Jan 15 '19 at 20:14\mathchoiceis executed (but only one is printed). This means that you'll see "DISPLAY MATH OK" in your log irrespective of whether the\TESTIFDISPLAYMATHoccurs in a display environment or not. – Circumscribe Jan 15 '19 at 21:12\everydisplay\expandafter{\the\everydisplay\GenericWarning{\relax}{DISPLAY MATH}}to your preamble TeX will printDISPLAY MATH on input line <line number>.for every display equation though. – Circumscribe Jan 15 '19 at 21:26\newcommand{\TESTIFDISPLAYMATH}{}together with\everydisplay\expandafter{\the\everydisplay\renewcommand{\TESTIFDISPLAYMATH}{\wlog{DISPLAY MATH OK}}}would work. This way\TESTIFDISPLAYMATHdoes nothing, but it is redefined to print your message when it is used inside a display environment. (It will also print this message if used inside atext{…}in a display environment though.) – Circumscribe Jan 15 '19 at 21:38$$ ... $$macro with the\[ ... \]macros? - Prefer the way LaTeX lays it out, but$are faster to write - TeX - LaTeX Stack Exchange – user202729 Oct 19 '22 at 18:35