# Saving counters

Consider the situation:

1. Two authors A,B (in fact, it will be four) inserting comments on a tex file.

2. Each author has his own command \alertA and \alertB to insert comments.

3. Each author should has his own counter \ctrA and \ctrB which will be used during the comments.

4. The command \alert<?>{foo} should print the value of \ctr<?> at the position and insert at the margin again the value of the counter followed by foo.

5. Each author has his own colour \clr<?> to be used for the output of his comments.

Partial code

I tried to define a global command \alert with 3 arguments: clr, ctr and text.

The clr should be optional, with default value black. If no colour is passed, the comments should be black.

\alert[red]{A}{foo} should make use of the counter \thectrA to insert foo and of course, step the counter.

Further, I simply have to define the commands \alert<?> with one argument (the comment) to be passed to \alert.

\newcommand{\alertA}[1]{\alert[blue]{\thectrA}{#1}}


The use in the text should be simply

... as we have\alertA{comments here} and so on...



At the end I'd like to have two independent sets of comments with two enumerations and two colours.

M(non working)WE

As you can see there is a problem with the counters. They are constant equal to 1.

\documentclass{report}
\usepackage{xcolor}

\newcounter{ctrA}
\newcounter{ctrD}
\newcounter{ctrM}
\newcounter{ctrT}
\setcounter{ctrA}{1}
\setcounter{ctrD}{1}
\setcounter{ctrM}{1}
\setcounter{ctrT}{1}

}

\begin{document}

\end{document}


There is no need for an alert counter. Just use a counter-per-author. Here is what I would do:

\documentclass{article}
\usepackage{xcolor}

\newcounter{ctrA}
\newcounter{ctrB}

\colorlet{clrA}{red}% Author A colour
\colorlet{clrB}{blue}% Author B colour

\textcolor{#1}{\textsuperscript{#2}}%
\marginpar{\raggedright\footnotesize\textcolor{#1}{\textsuperscript{#2}~#3}}%
}

\begin{document}

\end{document}


Each author have an associated counter and colour (defined using \colorlet). Each author-counter is stepped with a call to the appropriate \alert: \alertA for author A and \alertB for author B.

• I didn't know about the \colorlet. Thanks so much. – Sigur Jun 2 '15 at 19:37
• only \textsuperscript will affect the formatting of the text. So I decided to use \rlap. But a zero width box is more appropriate. – Sigur Jun 2 '15 at 20:18
• @Sigur: The formatting within the text and margin paragraphs were not really a concern in the question nor my answer. As such, I've removed all that. You can format them however you want them. – Werner Jun 2 '15 at 20:19

You're never stepping the counters. The alert counter is not needed: just redefine \thealert to be \the<counter>. I also simplified the code.

\documentclass{report}
\usepackage{xcolor}

\newcounter{ctrA}
\newcounter{ctrD}
\newcounter{ctrM}
\newcounter{ctrT}

\stepcounter{#2}%
\marginpar{%
\raggedright\footnotesize\color{#1}%
}%
}

\begin{document}

\end{document}


• Ow, I tried to use \the#2 but I see that the trick is \csname the#2\endcsname. Nice! – Sigur Jun 2 '15 at 19:36
• @Sigur If you do \renewcommand{\thealert}[1]{\the#1}, then when \thealert is called you get \the•c•t•r•A (I use • for separating tokens): five tokens, not one. With \csname the#1\endcsname one token is formed, equivalent to \thectrA. – egreg Jun 2 '15 at 19:41

Try replace your code after defining counters width:

\setcounter{alert}{0}
\setcounter{ctrA}{0}
\setcounter{ctrD}{0}
\setcounter{ctrM}{0}
\setcounter{ctrT}{0}


• Hm, I miss this. I'm just curios, why you not use todo package for this? – Zarko Jun 2 '15 at 19:42