10

I have defined some custom commands that I use for TODO-notes. If I write a note i use the command \stefan{}.

Now I want to define a new command, for example \supervisor{}.

I need a way to get LaTeX to ignore either one of the commands. When \supervisor is disabled I will want the \stefan command to get compiled.

Is this even possible?

Peter Grill
  • 223,288
thilemann
  • 369
  • 3
  • 11

3 Answers3

7

If I understand you correctly, one way would be to use \ifdefined\supervisor to test if \supervisor was defined, and if so redefine the \stefan macro:

enter image description here

Notes:

  • If you are using the todonotes package, you can use \usepackage[disable]{todonotes}

Code:

\documentclass{article}
\usepackage{xcolor}

\newcommand{\stefan}[1]{\textcolor{red}{Stefan's Comment: #1}}

\newcommand{\supervisor}[1]{}

\begin{document} Some text. \stefan{Correct this!!}

\ifdefined\supervisor \renewcommand{\stefan}[1]{} \fi

Some text. \stefan{Correct this also!!} \end{document}

Peter Grill
  • 223,288
  • Thank you for your suggestion. Yes, I am using the todonotes package. The problem with the disable option, is that it will disable every todonote in the document. I am working in a team on a project where we have a superviser assigned. Each member of the team have their own \name command to write a todo note. Whenever we want to turn in our document for comments by our supervisor, we do not want our todo notes to be visible. So we need a way to disable our own notes where we will still be able to write a note for our supervisor. I hope it makes a little more sense with my explanation. – thilemann Nov 09 '12 at 09:49
  • Ok, but does the rest of the answer solve your issue? – Peter Grill Nov 09 '12 at 09:53
6

You could do this from the command line. Take @PeterGrill's basic document:

\documentclass{article}
\usepackage{xcolor}
\newcommand{\stefan}[1]{\textcolor{red}{#1}}
\newcommand{\supervisor}[1]{\textcolor{red}{#1}}

\begin{document}
Some text. \supervisor{Correct this!!}

Some text. \stefan{Correct this also!!}
\end{document}

This will give you all the comments. Then create a .sty file, which could be as simple as:

% disable various comments
\renewcommand{\stefan}[1]{}

Then, when you want to 'hide' various comments, compile from the command line:

pdflatex "\AtBeginDocument{\input{mycomments.sty}}\input{masterfile.tex}" 

Or compile normally when you want all comments to appear.

Or, perhaps even more elegantly, you could implement @PeterGrill's suggestion:

Use the following (say) file commentcommands.sty:

\ifdefined\SupervisorMode
% re-define various commenting commands to do nothing
\renewcommand{\stephan}[1]{}
% ... etc., etc.
\fi

Then load commentcommands.sty after the original comment commands in the master file:

\usepackage{commentcommands}

Then, when you want to 'disable' the various commands in the document you hand to your supervisor, run the command as:

pdflatex "\def\Supervisormode{}\input{masterfile.tex}"

This does have the advantage of a clearer call to pdflatex, which you could also put into a makefile if you were so inclined.

jon
  • 22,325
  • Excellent idea. A slight implement would be to use \ifdefined\SupervisorMode \renewcommand{\stefan}[1]{} \fi in the .sty file and then use def\SupervisorMode{} on the command line. Same idea, but you don't need two files, and the command line is more readable. – Peter Grill Nov 09 '12 at 19:21
  • @PeterGrill -- Very true. Your suggestion is a clear improvement, so I added it to the original answer. – jon Nov 12 '12 at 09:46
3

You could use some boolean too.

For example:

\documentclass{article}

\makeatletter
\newif\if@supervisor 
\newcommand\stefan[1]{\if@supervisor\else#1\fi}
\newcommand\supervisor[1]{\if@supervisor#1\fi}

% toggle supervisor mode
\newcommand\supervisormode{\@supervisortrue}
\newcommand\notsupervisormode{\@supervisorfalse}
\notsupervisormode

\makeatother

\begin{document}

  \supervisormode
  \stefan{This is stefan comment}
  \supervisor{This is supervisor comment}

\end{document}