2

I want to toggle comments of and on. Off works, but when I set toggle to true, then I get an error:

./main.tex:36: Undefined control sequence.
\endtcolorbox ->\unskip \tcb@after@box 
                                       \end {tcb@savebox}\tcb@draw@color@box...
l.36 \end{tcolorbox}

Here is an example document to reproduce the error:

\documentclass{article}

\usepackage{hyperref}
\usepackage{pdflscape}
\usepackage{afterpage}
\usepackage{capt-of}% or use the larger `caption` package
\usepackage{tikz}                       
\usepackage{todonotes}                  
\usepackage[most]{tcolorbox}            
\usetikzlibrary{arrows,shapes,snakes,
               automata,backgrounds,
               petri,topaths}               %To use diverse features from tikz  
\usepackage{etoolbox}               

%create comment for me
\newtoggle{comments}
%\toggletrue{comments}
\settoggle{comments}{true} %set true to show all comments, set false to hide all comments
\newcommand{\notemp}[1]{\iftoggle{comments}{\todo[color=yellow]{{[}MP{]} #1}{}}}
\newcommand{\notecorr}[1]{\iftoggle{comments}{\todo[color=green]{{[}COR.{]} #1}{}}}

\usepackage{lipsum}% dummy text


\begin{document}
\notemp{this is one comment}

\lipsum

\notemp{this is one comment}
\begin{tcolorbox}[colback=orange,colframe=black,enhanced jigsaw, arc=3mm,boxsep=4pt,boxrule=0.5pt,breakable]
\textbf{Notes:}
    \begin{enumerate}
        \item test item
    \end{enumerate}
\end{tcolorbox}
\notecorr{this is another comment}
\lipsum % Text after
\end{document}

Any suggestions, how to fix this error?

I appreciate your answers!

  • Kare: Your toggle false branch is missing, that's why tcolorbox ends prematurely, giving the error message – user31729 Sep 25 '15 at 15:53
4

The syntax of \iftoggle is

\iftoggle{togglevariable}{true branch}{false branch}

The macros

\newcommand{\notemp}[1]{\iftoggle{comments}{\todo[color=yellow]{{[}MP{]} #1}{}}}
\newcommand{\notecorr}[1]{\iftoggle{comments}{\todo[color=green]{{[}COR.{]} #1}{}}}

close the true branch 'correctly', but there's no {false} branch, since #1}{}} should be #1}}{} actually -- the first } ends the \todo argument, the 2nd one ends the true branch of \iftoggle, the (empty) false branch {} will follow!

To keep track of the {} pairs it's better (in my point of view) to write the toggle parts in different lines:

\iftoggle{togglevariable}{%
    code for true branch}{%
    code for false branch%
  }% end of false branch and `\iftoggle`

This simplifies error searching.

\documentclass{article}

\usepackage{hyperref}
\usepackage{pdflscape}
\usepackage{afterpage}
\usepackage{capt-of}% or use the larger `caption` package
\usepackage{tikz}                       
\usepackage{todonotes}                  
\usepackage[most]{tcolorbox}            
\usetikzlibrary{arrows,shapes,snakes,
               automata,backgrounds,
               petri,topaths}               %To use diverse features from tikz  
\usepackage{etoolbox}               

%create comment for me
\newtoggle{comments}
%\toggletrue{comments}
\settoggle{comments}{true} %set true to show all comments, set false to hide all comments
\newcommand{\notemp}[1]{%
  \iftoggle{comments}{%
    \todo[color=yellow]{{[}MP{]} #1}}{% false
  }%
}
\newcommand{\notecorr}[1]{%
  \iftoggle{comments}{%
    \todo[color=green]{{[}COR.{]} #1}}{% false
  }%
}

\usepackage{lipsum}% dummy text


\begin{document}
\notemp{this is one comment}

\lipsum

\notemp{this is one comment}
\begin{tcolorbox}[colback=orange,colframe=black,enhanced jigsaw, arc=3mm,boxsep=4pt,boxrule=0.5pt,breakable]
\textbf{Notes:}
    \begin{enumerate}
        \item test item
    \end{enumerate}
\end{tcolorbox}
\notecorr{this is another comment}
\lipsum % Text after
\end{document}
2

The braces are mixed up in your definition of \notemp: what you should do is

\newcommand{\notemps}[1]{
  \iftoggle{comments}{
    % when the toggle is on
    \todo[color=yellow]{{[}MP{]} #1}
  }{ % else
    {}
  }
}

Instead, you closed the braces like this:

\newcommand{\notemps}[1]{
  \iftoggle{comments}{
    % when the toggle is on
    \todo[color=yellow]{{[}MP{]} #1}
    {}
  }
}

Thus, the second argument to \iftoggle is taken from whatever you have next, and that's why it had an error in the tcolorbox.

Here are the fixed definitions.

\newcommand{\notemp}[1]{\iftoggle{comments}{\todo[color=yellow]{{[}MP{]} #1}}{}}
\newcommand{\notecorr}[1]{\iftoggle{comments}{\todo[color=green]{{[}COR.{]} #1}}{}}

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.