考虑以下情况:
两位作者 A、B(实际上是四位)在
tex
文件上插入评论。每个作者都有自己的命令
\alertA
和\alertB
插入评论。每个作者都应该有自己的计数器
\ctrA
并\ctrB
在评论时使用。该命令应该在位置
\alert<?>{foo}
打印的值,并在边缘再次插入计数器的值,后跟。\ctr<?>
foo
每位作者都有自己的颜色
\clr<?>
用于输出其评论。
部分代码
我尝试定义一个\alert
带有 3 个参数的全局命令:clr
、ctr
和text
。
应clr
为可选的,具有默认值black
。如果没有传递颜色,则注释应为黑色。
\alert[red]{A}{foo}
应该利用计数器\thectrA
插入foo
,当然还要踩计数器。
此外,我只需定义\alert<?>
要传递给的一个参数(注释)的命令\alert
。
\newcommand{\alertA}[1]{\alert[blue]{\thectrA}{#1}}
\newcommand{\alertB}[1]{\alert[red]{\thectrB}{#1}}
文中的用法应该简单
... as we have\alertA{comments here} and so on...
... after a lot of text\alertB{more comments here} and so on...
最后,我希望有两组独立的评论,带有两个枚举和两种颜色。
M(非工作)WE
正如您所看到的,计数器存在问题。它们始终等于 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}
答案1
不需要alert
计数器。只需使用每个作者的计数器即可。以下是我会做的事情:
\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}
每位作者都有一个关联的计数器和颜色(使用 定义\colorlet
)。每个作者计数器都通过调用相应的\alert
:进行步进\alertA
,对于作者 A 和\alertB
作者 B。
答案2
您永远不会踩下计数器。alert
不需要计数器:只需重新定义\thealert
为即可\the<counter>
。我还简化了代码。
\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}
答案3
尝试在定义计数器宽度后替换您的代码:
\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}}%
}
有了它我得到了: