禁用更改和 todonotes 包:文本仍然被着色

禁用更改和 todonotes 包:文本仍然被着色

解决后出现问题:新命令定义中彩色文本不起作用

我正在尝试根据 todonotes 和 changes 包定义一个新的 \note 命令,但我在可选的选定文本样式方面遇到了麻烦。我希望在启用这两个包时将其着色,而在为 todonotes 提供“禁用”选项并为 changes 提供“最终”选项时不着色。

以下是代码:

\documentclass[12pt]{article}
\usepackage[dvipsnames,svgnames,x11names]{xcolor}
\usepackage[final, markup=underlined]{changes}
\usepackage[disable]{todonotes}

%% https://ctan.org/pkg/xparse
\usepackage{xparse}

\definechangesauthor[color=BrickRed]{MyName}

\NewDocumentCommand{\note}{omo}{%
  % #1 (optional) = addition to Changes@color
  % #2 text for \todo
  % #3 (optional) text for the change%
  \IfValueTF{#1}%
    {%
        \todo[color=Changes@Color#1!20,size=\scriptsize]{#1: \emph{#2}}%
        \IfValueT{#3}{\textcolor{Changes@Color#1}{#3}}%
    }%
    {%
        \todo[color=Changes@Color!20,size=\scriptsize]{\emph{#2}}%
        \IfValueT{#3}{\textcolor{Changes@Color}{#3}}%
    }%
}

\begin{document}
Lorem ipsum dolor sit \note{Just a note without selected text and
without author.} amet, consectetur adipiscing elit, sed do eiusmod tempor 
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis 
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
consequat.\note[MyName]{My comment}[Proin a lectus vestibulum, mollis eros 
id, vehicula mauris.] Duis aute irure dolor in reprehenderit in voluptate 
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat 
cupidatat \note[MyName]{My other comment without text selectd.}non 
proident, sunt in culpa qui officia deserunt mollit anim id est \note{Some 
comment about some selected text.}[laborum}]

\end{document}

输出如下所示:

在此处输入图片描述

但我希望它不是彩色的。

答案1

您应该使着色符合\ifChanges@optiondraft条件。

\documentclass[12pt]{article}
\usepackage[dvipsnames,svgnames,x11names]{xcolor}
\usepackage[final, markup=underlined]{changes}
\usepackage[disable]{todonotes}

%% https://ctan.org/pkg/xparse
\usepackage{xparse}

\definechangesauthor[color=BrickRed]{MyName}

\makeatletter
\NewDocumentCommand{\formatchange}{mm}{%
  \ifChanges@optiondraft
    \textcolor{Changes@Color#1}{#2}%
  \else
    #2%
  \fi
}
\makeatother

\NewDocumentCommand{\note}{omo}{%
  % #1 (optional) = addition to Changes@color
  % #2 text for \todo
  % #3 (optional) text for the change%
  \IfValueTF{#1}%
    {%
        \todo[color=Changes@Color#1!20,size=\scriptsize]{#1: \emph{#2}}%
        \IfValueT{#3}{\formatchange{#1}{#3}}%
    }%
    {%
        \todo[color=Changes@Color!20,size=\scriptsize]{\emph{#2}}%
        \IfValueT{#3}{\formatchange{}{#3}}%
    }%
}

\begin{document}
Lorem ipsum dolor sit \note{Just a note without selected text and
without author.} amet, consectetur adipiscing elit, sed do eiusmod tempor 
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis 
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
consequat. \note[MyName]{My comment}[Proin a lectus vestibulum, mollis eros 
id, vehicula mauris.] Duis aute irure dolor in reprehenderit in voluptate 
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat 
cupidatat \note[MyName]{My other comment without text selectd.}non 
proident, sunt in culpa qui officia deserunt mollit anim id est \note{Some 
comment about some selected text.}[laborum]

\end{document}

在此处输入图片描述

相关内容