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.

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.

|improve this answer|||||
  • 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! – LadyGodiva2 Feb 18 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}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.