Preprocessor for LaTeX?
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}
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}
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.