1

The problem arose after the solution of : Colouring text doen't work in newcommand definition

I am trying to define a new \note command based on todonotes and changes packages but I'm having troubles with the optional selected text styling. I want it to be coloured when the two packages are enabled and not coloured when todonotes is given the 'disable' option and changes is given the 'final' option.

Heres the code:

\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}

The output looks like this:

enter image description here

but I would like it to be not coloured.

1 Answer 1

1

You should make the coloring to obey the \ifChanges@optiondraft conditional.

\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}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .