2

I would like to have, say, two custom comment macro for every author. For example suppose there are two authors Alice and Bob and they would like to have commands:

\newcommand{\acom}[1]{\textcolor{green}{#1}}
\newcommand{\aissue}[1]{\textcolor{red}{\textbf{#1}}}

for Alice a maybe with different color scheme for Bob. Of course, Alice can write these but it is a bit annoying.

Now, suppose Cecil joins our team. Ideally, I would like to have a command

\registerAuthor{Cecil}{yellow}{purple}

since then it is easy to ask Cecil to add his command and everything goes smoothly (otherwise Alice has to do this every time; and imagine if we have 20 different macros). Is there any possible workaround?

1 Answers1

4

The trick is to use \csname:

\documentclass{article}
\usepackage[dvipsnames]{xcolor}

\newcommand{\registerAuthor}[3]{%
  \expandafter\newcommand\csname #1com\endcsname[1]{\textcolor{#2}{##1}}%
  \expandafter\newcommand\csname #1issue\endcsname[1]{\textcolor{#3}{\textbf{##1}}}%
}

\registerAuthor{a}{green}{red}
\registerAuthor{c}{yellow}{purple}

\begin{document}

Alice comment: \acom{something}

Alice issue: \aissue{something}

Cecil comment: \ccom{something}

Cecil issue: \cissue{something}

\end{document}

enter image description here

egreg
  • 1,121,712