我想打开和关闭评论。关闭可以,但是当我将切换设置为 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}}{}}