# Good tools for LaTeX maintenance tasks?

I have a big bunch of old to new LaTeX documents written by several independent people. I have to bring them up to date, modern and consistent, standardized LaTeX code. In these documents there are a lot of common "mistakes" or quirks. For example:

$$a = b \nonumber$$

instead of just

$a = b$

and similar cases (eqnarray instead of align and so on). Or completly random code linebreaks in text (no output changing breaks, like paragraphs) that could be joined.

What tools are recommended to automate such kind of tasks? Mainly to change code snippets to other code snippets without changing the raw content of the snippet. A find-and-replace that takes care of LaTeX syntax/semantic, so to speak.

Are there such tools? I'm working on Windows.

-
I have used perl to do limited search and replace on certain constructions, but writing regular expressions that cope with all possible idiosyncrasies of TeX is well nigh impossible, so careful hand checking is always necessary. –  Andrew Swann Nov 1 '12 at 16:39
In the past, I had used gema to translate a 700 page book written in plain TeX to LaTeX (I needed some hand-tuning for figures and tables). Gema is more versatile than regular expressions, has a windows port, and includes an example of tranlating LaTeX to HTML –  Aditya Nov 1 '12 at 23:04
@Aditya: can gema read/write utf-8 files? –  mbork Nov 13 '12 at 18:28

## 1 Answer

The first step could be loading the nag package at the beginning of each document, which checks for common mistakes, outdated packages and obsolete commands:

\RequirePackage[l2tabu, orthodox]{nag}

Context aware checks and replacements could be made with regular expressions and tools like perl, php, or sed, for example. But you need to know what to look for.

Furthermore helpful: grep, egrep, find, for example:

find "." -name "*.tex" | xargs grep eqnarray

You could extend this to search whole directory trees for a list of undesired patterns.

I would do this on Linux, as there are all mentioned tools usually preinstalled. On Windows, you could install Cygwin (for shell and tools) and ActiveState Perl, for example.

-
I already use nag. And I'm using Windows (see question). So grep is not available. –  Foo Bar Nov 1 '12 at 16:45
@FooBar Please see my update, on Windows much tools are missing but can be installed. –  Stefan Kottwitz Nov 1 '12 at 16:46
Thanks. I did some further reseacrh myself and waited if someone has a better (more easy) solution. But since there was none and I also found nothing myself, your answer should be the correct one. –  Foo Bar Nov 8 '12 at 9:49