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'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

http://en.nothingisreal.com/wiki/GPP

and filepp

http://www.cabaret.demon.co.uk/filepp/

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

share|improve this question
4  
Do you want to remove the TODO comments or just hide them. In the latter case you can use the TODO package. –  Yiannis Lazarides Feb 27 '12 at 9:39
    
Just hiding them would work ok for me. I'll take a look at the TODO package, thanks. –  user1362373 Feb 27 '12 at 9:42
1  
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{}. –  zeroth Feb 27 '12 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. –  Yiannis Lazarides Feb 27 '12 at 10:00
4  
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). –  Martin Schröder Feb 27 '12 at 10:05
show 2 more comments

3 Answers 3

up vote 18 down vote accepted

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.

\documentclass{article}

\usepackage{ifdraft}
\usepackage{blindtext}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}

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

\newcommand\mytodo[1]{
    \ifdraft{
        \textbf{#1}
    }{}
}

\begin{document}
    \blindtext
    \mytodo{I have to remember this!}
\end{document}
share|improve this answer
    
Great, this looks just like what I need. Thanks a lot! –  user1362373 Feb 27 '12 at 10:04
add comment

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.

share|improve this answer
add comment

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");
  #endif
}

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:

\documentclass{article}

\usepackage{comment}
\usepackage{lipsum}
\usepackage{fancyhdr}

\pagestyle{fancy}

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

\fancyhead{}
\renewcommand{\headrulewidth}{0pt}

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


\newcommand\mytodo[1]{}

\begin{todos}
\renewcommand\mytodo[1]{
    \textbf{#1}
}
\end{todos}

\begin{document}
    \lipsum
    \mytodo{I have to remember this!}
\end{document}
share|improve this answer
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.