Emacs Proofing LaTeX

⇠ Back to Blog:Hacks

I often need to clean out the proofing notes one makes for editors and co-authors in $\mathrm{\LaTeX}$ prose:

Screenshot 20240518 132554.png

The corresponding text looks like this in emacs:

Screenshot 20240518 132949.png

One needs to replace \textcolor{red}{changed text} by changed text and to remove \st{removed text}. This is fairly easy with no complications:

M-x query-replace-regexp or C-M-%
\\textcolor{red}{\(.*?\)} at first prompt
\1 at second prompt

or to include new lines, replace first prompt by:

\\textcolor{red}{\([\a-z0-9_ 
]+\)}

where the physical newline in the first prompt is entered as C-q C-j

Similarly to remove strike-out text:

\\st{\([\a-z0-9_ 
]+\)}

This will work if there are no enclosed braces, which is however frequent in $\mathrm{\LaTeX}$ code, or punctuations characters when using the \a-z0-9_ listing to include the newline (can't find how to do that with .*

So while this can sort a fairly big number of cases, this is still not satisfactory.

Someone (itsjeyd) appears to offer an option at this link but I couldn't get it to work even on the case they tackle, nor understand much of what they propose. This remains to be polished.