1

I'm trying to replace a single option (e.g., width=2mm or colour=green or dotted) with a simple \newcommand. I`m imagining something short like \w2, \cg, or \qst, just for typing speed (especially with the option=something ones).

What I'm specifically trying to do:

\usepackage{todonotes}

\newcommand{\q}{color=green}

\todo[\q]{my text goes here}

I'm given an error that reads "Package xkeyval Error: `color=green' undefined in families todonotes'.

Now, the package gives an alternative to this, which is to fully write out the whole line as a new command, i.e.:

\newcommand{\q}{\todo[color=green]{my text goes here}}
\newcommand{\q}[1]{\todo[color=green]{#1}}

Which is not terrible, but now I'm just curious how I can set one option as a command, since I haven't been able to find it anywhere, and I'm sure I'll want to do this in the future.

Update Looks like my speediest version is to do:

\newcommand{\q}[2][]{\todo[color=green, #1]{#1}}

So I can still change other options as normal.

2 Answers 2

1

The keyval parser goes to some lengths not to expand macros so that you can use them in values without them being expanded at the wrong time.

So you could force \q to expand before being passed in by

 \expandafter\todo\expandafter[\q]

But that isn't very convenient,

 \newcommand\q{\todo[color=green]}

is likely to be the simplest version.

1
  • Simple and speedy was what I was hoping for - this explains why all the other answers I was seeing when looking this up were so complex. Thanks! Feb 18, 2020 at 20:35
3

You can define new keys.

\documentclass{article}
\usepackage{todonotes}

\makeatletter
\newcommand\newtodooption[2]{%
  \define@key{todonotes}{#1}[]{%
    \setkeys{todonotes}{#2}%
  }%
}
\makeatother

\newtodooption{q}{color=green}

\begin{document}

Abc \todo[q]{text goes here}

Abc \todo[color=green]{text goes here}

\end{document}

You must log in to answer this question.

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