| |
|
|
|
Sometimes we want to produce two different versions of a book from the same source files. We tried (La)TeX-specific approaches but abandoned these because it was too hard to make sure that the if/else mechanism didn't interfere with the LaTeX code that was to be conditionally included or excluded. An obvious solution is to use a preprocessor like cpp, so we can use #if/#else/#endif to conditionalize chunks of LaTeX. However, cpp has too many capabilities -- it interprets certain C-language contructs as macros, and as these can easily occur in LaTeX code, cpp isn't suitable for our purposes. Nor is m4. However, there is a very limited preprocessor called unifdef. As its manpage states: "The unifdef utility selectively processes conditional cpp(1) directives. It removes from a file both the directives and any additional text that'' they specify should be removed, while otherwise leaving the file alone." unifdef is perfect for our purposes. Here's a simple example:
\documentclass[12pt]{article}
\begin{document}
First
#ifdef MME
Second
Third
#else
Fourth
Fifth
#endif
Sixth
\end{document}
If we are producing the "mass market edition" (MME) of the book we get one output tex file; on the other hand if MME is undefined we get a different variant -- the "normal" version of the book. (The definition or undefinition of MME is in a settings file that we pass to unifdef.) We send the output of unifdef to simple.tex in this example, and then process simple.tex as normal.
|
Latest news
|