2

This question already has an answer here:

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?

marked as duplicate by user31729 Jan 18 at 14:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Welcome to TeX.Stackexchange! – user36296 Jan 18 at 13:28
  • I'm not sure if you want something like this to track changes for every author in a collaborative work. Just a wild guess ! – Partha D. Jan 18 at 13:34
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

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