# Automatic alternating labels in the description list

I need to use the description environment in such a way that I don't have to write alternating labels over and over again (as shown in the example below). Is there any way that these labels become automatic? It will save a lot of time and hassle. Thanks.

\begin{description}
\item[A:] text
\item[B:] text
\item[A:] text
\item[B:] text
\item[A:] text
\item[B:] text
\item[A:] text
\item[B:] text
\item[A:] text
\item[B:] text
\end{description}

• Welcome to TeX - LaTeX! This looks like a dialog… – clemens Nov 8 '15 at 16:39
• If you just have \item[A: ] and \item[B: ], you can define new shortcuts for them: \def\itema{\item[A: ]} and \def\itemb{\item[B: ]}. – Hoang-Ngan Nguyen Nov 8 '15 at 17:56

## 2 Answers

A variant, based on the enumerate environment, with enumitem and etoolbox:

\documentclass{article}
\usepackage{enumitem}
\usepackage{etoolbox}
\newlist{alternate}{enumerate}{1}
\renewcommand\labelalternatei{\bfseries\protect\ifnumodd{\value{alternatei}}{A:}{B:}}

\begin{document}

Some text some text some text some text some text some text some text some text some text some text some text some text some text.
\begin{alternate}[wide=0pt]
\item First
\item Second
\item Third
\item Fourth
\item Fifth
\item Sixth
\end{alternate}

\end{document}


With the help of package enumitem and some black magic which I am unable to explain.

\documentclass{article}

\usepackage{enumitem}
\protected\def\mylabel#1{\ifodd#1A:\else B:\fi}
\AtBeginDocument{\sbox0{\bfseries A:\hspace\labelsep}%
%\edef\Ahmad{\dimexpr\number\wd0 sp\relax}% pleasing but slower
\edef\Ahmad{\the\wd0}%
}

\begin{document}

\begin{enumerate}[label=\bfseries\mylabel{\value*},
itemindent=\dimexpr-\leftmargin+\Ahmad\relax,
labelwidth=\Ahmad]
\item text
\item text
\item text
\item text
\item text
\item text
\item text
\item text
\item text
\item text
\end{enumerate}

\begin{description}
\item[A:] text
\item[B:] text
\item[A:] text
\item[B:] text
\item[A:] text
\item[B:] text
\item[A:] text
\item[B:] text
\item[A:] text
\item[B:] text
\end{description}
\end{document}


• Why not \dimexpr\the\wd0\relax or simply \the\wd0? Also it should be \sbox0{...} instead of \setbo0=\hbox{...} and it should be done, together with the definition of \Ahmad in \AtBeginDocument, so LaTeX has already executed \normalfont\normalsize. – egreg Nov 8 '15 at 21:17
• @egreg because I don't like points and prefer integers. I suspect it is faster with sp but I have often been proved wrong in my expectations regarding TeX innards... – user4686 Nov 8 '15 at 21:19
• @egreg for \AtBeginDocument yes I wanted to do it, had started doing it, then I felt it would make too scary an approach. But will edit. – user4686 Nov 8 '15 at 21:20
• I tried to test with one million assignments \dimen0=65536sp and \dimen0=1pt. TeX was slower with sp by 27% – egreg Nov 8 '15 at 21:24
• 65536 has five tokens. But in real life with \the\wd0 there will also be more tokens in \number. Ok, I will test. – user4686 Nov 8 '15 at 21:25