3

In a .tex file, there is some self defined command

\newcommand{\mycomment}[1]{\textcolor{red}{#1}}
...
\mycomment{blah blah}
...

I hope to be able to skip the command during compilation in my final version, but still compile it in versions before my final version. Are there any ways to do that?

  • 1
    do you just mean change to \newcommand{\mycomment}[1]{} for the final version? Or something else? – David Carlisle Apr 14 '13 at 23:16
  • @David: In the final version, \mycomment{blah blah} will be ignored during compilation. – Tim Apr 14 '13 at 23:22
  • 1
    The definition I suggested in the first comment does that, it defines the command to take the argument and do nothing with it – David Carlisle Apr 14 '13 at 23:25
4

Another fairly intuitive method, particularly if you have several large blocks of code which you want to include in some compilations but not others is the comment package (also saves a lot of time if you are writing a very large manuscript, but only working on a small bit at a time). However its great for small toggles too.

\usepackage{comment}
 %switches    
\excludecomment{versiona}
\excludecomment{versionb}
\includecomment{versionx}

..

\begin{versiona}
\newcommand{\mycomment}[1]{\textcolor{red}{#1}
etc
\end{versiona}

\begin{versionb}
\newcommand{\mycomment}[1]{\textcolor{red}{#1}
etc
\end{versionb}
| improve this answer | |
3
\newif\iffinal
\newcommand{\mycomment}[1]{\iffinal\else\textcolor{red}{#1}\fi}
...
\mycomment{blah blah}

And you have Boolean values \finaltrue and \finalfalse. For development versions set \finalfalse somewhere in the preamble after \newif\iffinal, for the final compilation set \finaltrue, or set both and comment out the inactive Boolean:

\finalfalse
% \finaltrue
| improve this answer | |
  • 1
    BTW I find the bools or toggles from etoolbox much more convenient. – Speravir Apr 14 '13 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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