I'm curious to find out whether anybody has suggestions for a preprocessor for LaTeX documents. What I'm thinking of is something like cpp. The motivation for my question is that I'm writing a large document in which I insert comments to myself, such as

\textbf{XXX TO DO: need transition paragraph. Make sure to mention xy's work. XXX}

for example. When I periodically release parts of the (unfinished) document to selected people, I comment out the TO DO's and I replace the detailed Subversion version string in the footer (version, date, time, etc.) by a simpler string that asserts my authorship and that the document should not be distributed. I would be glad if these changes could be automated and something like cpp seems an obvious candidate.

I realize that writing a little preprocessor using awk or sed is not that big a deal, but ideally I want to reuse existing software. My digging so far has only found gpp


and filepp


Both of these seem pretty old judging from dates on the websites, however. Any comments, experience, ideas?

  • 5
    Do you want to remove the TODO comments or just hide them. In the latter case you can use the TODO package. Feb 27, 2012 at 9:39
  • Just hiding them would work ok for me. I'll take a look at the TODO package, thanks. Feb 27, 2012 at 9:42
  • 2
    I simply added a small macro so that you can decide how it should report it: \def\todo#1{\message{^^J^^J!!! >>> WARNING <<< !!! #1^^J^^J}\bgroup\color{red} #1\egroup}. You could also use the \warning. When you dont need it, just \def\todo#1{}.
    – nickpapior
    Feb 27, 2012 at 9:45
  • 1
    Please see tex.stackexchange.com/questions/9796/how-to-add-todo-notes. If it answers your question, please post a comment. We can then link this question to the answer and close question. Feb 27, 2012 at 10:00
  • 5
    Since TeX is a macro processor, I would try to do this with TeX by (re)defininig macros. There are a number of packages for this (e.g. todo, ìfdraft). Feb 27, 2012 at 10:05

4 Answers 4


Here is a version using the ifdraft package. In my MWE you have the TODO and no footer (use your subversion code at the marked place to get one) when you compile with \documentclass[draft]{article}, and no TODO and my fake footer without the draft option.




        % insert subversion code here
    \lfoot{Written by Psirus, do not distribute.}


    \mytodo{I have to remember this!}

While the previous answers provide a good solution for the OPs actual problem, the following elaborates a bit more general on the relation between "CPP-like preprocessing" and (La)TeX.

Besides a lot of "internal sanitizing" (removing of comments, whitespaces, ...) the CPP provides three actions that are user-controllable by preprocessor commands:

(1) inclusion of another file`s content into the token stream:

#include "file.ext"

This maps directly to (La)TeXs \input{file} command.

(2) definition and expansion of macros:

#define MAGIC 4711
void main(){
  return MAGIC; // expands to: return 4711;

Well, (La)TeX is all about macros and their expansion, so this maps to \def or \newcommand or one of its flavors. In fact, (La)TeXs macro processing is a lot more powerful.

(3) conditional compilation:

#define DRAFT

void main() {
  #ifdef DRAFT
    printf("DBG: in main()\n");

This is the only CPP primitive that does not directly map to some (La)TeX concept. While it can, in many cases be emulated by some \if ... \fi construct (or a respective command, as the \ifdraft{}{} in the answer if Psirus), there is a subtle difference: With conditional compilation we are really at meta-level, that is, we alter the program text before it is fed into the compiler: The code lines of conditional blocks are removed if the condition evaluates to false, that is, the compiler does not even see them. Hence, they might contain "weird syntax", such as unbalanced braces or control structures. A secondary effect (if the conditional parts are very large) is that the compilation time is reduced as there is less program text to lex and parse.

For (La)TeX, real conditional compilation can be accomplished with the comment package:




\includecomment{todos}      % #define todos
\excludecomment{svninfo}    % #undef svninfo


\lfoot{Written by Psirus, do not distribute.}
    \lfoot{SVN STUFF}



    \mytodo{I have to remember this!}

For simple operations with todo, the todonotes package will do, as mentioned in the comments. Also @Prirus' idea is excellent. For more advanced edits, I would suggest two different main tex documents. You probably include/input all the content anyway, so you can create two different layouts and compile them separately using a simple Makefile. Or both at the same time if you wish.

Check out these answers, some more sophisticated suggestions can be found there. Also look at topics with the Makefile tag here.


Try Pandoc:

pandoc -o preprocessed_output.tex LaTeX_input.tex
  • Well, can you please explain why that could be a solution for the given question?
    – Mensch
    Aug 21, 2019 at 23:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .