![将注释切换设置为 false,错误:未定义的控制序列](https://linux22.com/image/319786/%E5%B0%86%E6%B3%A8%E9%87%8A%E5%88%87%E6%8D%A2%E8%AE%BE%E7%BD%AE%E4%B8%BA%20false%EF%BC%8C%E9%94%99%E8%AF%AF%EF%BC%9A%E6%9C%AA%E5%AE%9A%E4%B9%89%E7%9A%84%E6%8E%A7%E5%88%B6%E5%BA%8F%E5%88%97.png)
我想打开和关闭评论。关闭可以,但是当我将切换设置为 true 时,出现错误:
./main.tex:36: Undefined control sequence.
\endtcolorbox ->\unskip \tcb@after@box
\end {tcb@savebox}\tcb@draw@color@box...
l.36 \end{tcolorbox}
以下是重现该错误的示例文档:
\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}
有什么建议吗,如何修复此错误?
我很感谢您的回答!
答案1
语法\iftoggle
是
\iftoggle{togglevariable}{true branch}{false branch}
宏
\newcommand{\notemp}[1]{\iftoggle{comments}{\todo[color=yellow]{{[}MP{]} #1}{}}}
\newcommand{\notecorr}[1]{\iftoggle{comments}{\todo[color=green]{{[}COR.{]} #1}{}}}
“正确”地关闭了真正的分支,但没有{false}
分支,因为 实际上#1}{}}
应该是#1}}{}
——第一个}
结束了\todo
争论,第二个结束了真正的分支,接下来是\iftoggle
(空的)假分支!{}
为了跟踪这些{}
对,最好(以我的观点来看)将切换部分写在不同的行中:
\iftoggle{togglevariable}{%
code for true branch}{%
code for false branch%
}% end of false branch and `\iftoggle`
这简化了错误搜索。
\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
括号混淆了您的定义\notemp
:您应该做的是
\newcommand{\notemps}[1]{
\iftoggle{comments}{
% when the toggle is on
\todo[color=yellow]{{[}MP{]} #1}
}{ % else
{}
}
}
相反,你可以像这样闭合括号:
\newcommand{\notemps}[1]{
\iftoggle{comments}{
% when the toggle is on
\todo[color=yellow]{{[}MP{]} #1}
{}
}
}
因此,的第二个参数\iftoggle
取自接下来的任何内容,这就是在中出现错误的原因tcolorbox
。
这是固定的定义。
\newcommand{\notemp}[1]{\iftoggle{comments}{\todo[color=yellow]{{[}MP{]} #1}}{}}
\newcommand{\notecorr}[1]{\iftoggle{comments}{\todo[color=green]{{[}COR.{]} #1}}{}}