3

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}}
\newcommand{\alertB}[1]{\alert[red]{\thectrB}{#1}}

The use in the text should be simply

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

... after a lot of text\alertB{more 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{alert}
\newcounter{ctrA}
\newcounter{ctrD}
\newcounter{ctrM}
\newcounter{ctrT}
\setcounter{alert}{1}
\setcounter{ctrA}{1}
\setcounter{ctrD}{1}
\setcounter{ctrM}{1}
\setcounter{ctrT}{1}

\newcommand{\alert}[3][black]{% #3=texto, #2=ctr #1=color
\renewcommand{\thealert}{#2}
\rlap{\textsuperscript{\textsuperscript{\textcolor{#1}{\textbf{\thealert}}}}}%
\marginpar{\raggedright\footnotesize\textcolor{#1}{\llap{\textsuperscript{\textit{\thealert}}}#3}}%
\stepcounter{alert}%
}

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

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

... after a lot of text\alertD{more comments here} and so on...

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

... after a lot of text\alertD{more comments here} and so on...

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

... after a lot of text\alertD{more comments here} and so on...

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

... after a lot of text\alertD{more comments here} and so on...

\end{document}

enter image description here

3

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

enter image description here

\documentclass{article}
\usepackage{xcolor}

\newcounter{ctrA}
\newcounter{ctrB}

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

\newcommand{\alert}[3][black]{% #3=text, #2=ctr #1=colour
  \textcolor{#1}{\textsuperscript{#2}}%
  \marginpar{\raggedright\footnotesize\textcolor{#1}{\textsuperscript{#2}~#3}}%
}

\newcommand{\alertA}[2][clrA]{\refstepcounter{ctrA}\alert[#1]{\thectrA}{#2}}
\newcommand{\alertB}[2][clrB]{\refstepcounter{ctrB}\alert[#1]{\thectrB}{#2}}

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

... after a lot of text\alertB{more comments here} and so on...

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

... after a lot of text\alertB{more comments here} and so on...

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

... after a lot of text\alertB{more comments here} and so on...

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

... after a lot of text\alertB{more comments here} and so on...

\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
  • 1
    @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
1

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}

\newcommand{\thealert}{} % initialize

\newcommand{\alert}[3][black]{% #3=texto, #2=ctr #1=color
  \stepcounter{#2}%
  \renewcommand{\thealert}{\csname the#2\endcsname}%
  \makebox[0pt][l]{\raisebox{1.4ex}[0pt]{\tiny\bfseries\color{#1}\thealert}}%
  \marginpar{%
    \raggedright\footnotesize\color{#1}%
    \makebox[0pt][r]{\textsuperscript{\itshape\thealert}}#3%
  }%
}

\newcommand{\alertA}[1]{\alert[red]{ctrA}{#1}}
\newcommand{\alertD}[1]{\alert[blue]{ctrD}{#1}}

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

... after a lot of text\alertD{more comments here} and so on...

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

... after a lot of text\alertD{more comments here} and so on...

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

... after a lot of text\alertD{more comments here} and so on...

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

... after a lot of text\alertD{more comments here} and so on...

\end{document}

enter image description here

  • 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
  • 1
    @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
0

Try replace your code after defining counters width:

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

\newcommand{\alert}[3][black]{% #3=texto, #2=ctr #1=color
%    \renewcommand{\thealert}{#2}
\stepcounter{alert}%
\rlap{\textsuperscript{\textsuperscript{\textcolor{#1}{\textbf{\thealert}}}}}%
\marginpar{\raggedright\footnotesize\textcolor{#1}{\llap{\textsuperscript{\textit{\thealert}}}#3}}%
}

With it I got: enter image description here

  • Thanks for your effort but your code has a single enumeration. I wish two independent. – Sigur Jun 2 '15 at 19:34
  • Hm, I miss this. I'm just curios, why you not use todo package for this? – Zarko Jun 2 '15 at 19:42
  • as I wrote, I'd like to have a very different list of comments for each author. See the output. I can use different colours and numbers. – Sigur Jun 2 '15 at 19:50

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.