Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

\begin{equation}
  a = b
\nonumber
\end{equation}

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.

share|improve this question
1  
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
1  
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
add comment

1 Answer

up vote 7 down vote accepted

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.

share|improve this answer
    
I already use nag. And I'm using Windows (see question). So grep is not available. –  Foo Bar Nov 1 '12 at 16:45
1  
@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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.