# How to alternate labels' styles in enumerated lists?

How can I alternate the display of an enumerated list's counter according to which command I've used? E.g., I want \foo{poor Yorick!} to look like (9) poor Yorick! but I want \bar{Joelle} to have a label like [8] Joelle.

## Details and Motivation

(so that we can avoid the XY problem)

I previously asked a question about LaTeX packages for writing Structured Derivations: Which packages/practices are relevant for writing Structured Derivations? (similar to Dijkstra's calculational style of proofs). I'm now working small solution, inspired by the help I received.

One of the researchers behind SD simply described their proof format as a two-column list: a small one on the left for the relation symbols, and a larger one on the right for the explanations. As a result, I'm trying to implement SD as an enumerated list with enumitem to help with any formatting. It seems like if I can keep the definition to something as simple as an extended list environment, then nesting SDs should be natural.

Here are some pieces of what I have so far:

\ProvidesPackage{structured_derivations}
\RequirePackage{xparse, enumitem}

\item[\textbullet] #1 % not numbered. i.e., also not mutating the counter
}

\NewDocumentCommand{\assumption}{s m}{
\IfBooleanTF{#1} % determines if command was used with a star
{\item[$-$]} % \assumption*{…
{\item} % \assumption{…
% label=(\arabic*)
#2 % content of assumption
}

\NewDocumentCommand{\observation}{s m m}{

\IfBooleanTF{#1}
{\item[$+$]}
{\item} % label=\lbrack\arabic*\rbrack
\{ #2 \} % justification

\item[] #3 % actual observation
}
% TODO maybe abstract out the common structure between \observation and \assumption?

% anyway, there are more command definitions and then I probably need something like
\newlist{structured_derivation}{enumerate}{5} % picking this number pretty arbitrarily
\setlist[structured_derivation]{label={}} % because I'll be overriding it anyway?


Ideally, the solution to this problem will be compatible with my goal of also being able to optionally reset the counter upon nesting a derivation (to indicate that the assumptions are not inherited).

This is all toward the end of being able to write proofs like this:

% (btw, also using the exercise package)
\begin{Exercise} [number=4]
Assume that $n,m \in \naturals$. \      Show: ($m$ is odd $\land$ $n$ is odd) $\implies$ $m + n$ is even.
\end{Exercise}
\begin{structured_derivation}
\task{Prove that $m + n$ is necessarily even if $m$ and $n$ are both odd.}
\assumption*{$n \in \naturals$}
\assumption*{$m \in \naturals$}
\isProvedBy{assume $m$ and $n$ are odd, and then derive that $m + m$ is even to demonstrate implication}
\begin{structured_derivation}
\task{Prove that $m + n$ is even when:}
\assumption{$m$ is odd}
\assumption{$n$ is odd}
\observation
{definition of odd-ness}
{$\exists{x} \in \integers \suchthat m = 2x + 1$}
\observation
{definition of odd-ness}
{$\exists{y} \in \integers \suchthat n = 2y + 1$}
% continues...
\end{structured_derivation}
\end{structured_derivation}


And I will find a genie to grant you wishes if you also know how to make the brackets unnecessary like how \item is:

\task blah
\assumption* blah
\assumption* blah
\observation blah
\begin{structured_derivation}

-

### Updated Solution:

Instead of using different macros (as in the earlier version below), I think it makes more sense to have a single macro that is flexible enough to do what you want. Here I have defined the macro \MyItem[<left>][<right>]{<content>}, which accepts two optional parameters:

• If none of the optional parameters are specified, the enumerated item is printed as 2.
• If both optional parameters are specified, they are treated as being the left and right delimiters to be placed around the enumerated item. So the enumerated item will be typeset as <left>2<right>.
• If only one of the optional parameters is provided then that is used as as itemized label and the enumeration is paused.

Here are some of the possibilities:

## Further Enhancements:

• If you have more than one of these in your document you will need to have a method to reset the counter use by the enumeration, or use a different series name.

## Code:

\documentclass{article}
\usepackage{enumitem}
\usepackage{xparse}

\NewDocumentCommand{\MyItem}{o o m}{%
% If #2, second optional second parameter, is provided then
%    use an enumerated item with #1 = left, #2 = right
% else if the
%    use #1, first optional parameter is provided
%       use #1 as the itemize label
% else use enumerated number
%
% #3 = content
%
\IfNoValueTF{#2}{%
\IfNoValueTF{#1}{%
\begin{enumerate}[series=MyItem,resume=*,label={\arabic*.}]%
\item #3%
\end{enumerate}%
}{%
\begin{itemize}[label={#1}]%
\item #3%
\end{itemize}%
}%
}{%
\begin{enumerate}[series=MyItem,resume=*,label={#1\arabic*#2}]%
\item #3%
\end{enumerate}%
}%
}%

\begin{document}
\MyItem{no parameter}
\MyItem[(][)]{use round braces}
\MyItem[{[}][{]}]{use square braces}
\MyItem[$\langle$][$\rangle$]{use angle braces}
\MyItem{no parameter - numbering continues}
\MyItem[{[}][$\rangle$]{use mixed braces}
\MyItem[$-$]{custom symbol}
\MyItem[][)]{no left bracket}
\MyItem[][]{no symbol for left and right}
\MyItem[$\ast$][]{no symbol for right}
\MyItem[$\circ$]{another custom symbol!}
\MyItem{no parameter - numbering continues}
\end{document}


If I understand you correctly this should do what you want. It uses the resume feature available with the enumitem package.

So, \Foo{poor Yorick!} uses () with the current enumerate number to provide the label. But it also accepts an optional first parameter in where you can provide your own label to use (in which case the itemize environment is used with the provided label so as not increment the enumerate counter. Similarly for \Bar{} but that uses the [] for the enumerate label by default.

When the optional parameter is provided to either of the two macros, \Foo and \Bar behave identically.

## Further Enhancements:

• Use more meaningful names for \Foo, and \Bar.

## Code:

\documentclass{article}
\usepackage{enumitem}
\usepackage{xparse}

\NewDocumentCommand{\Foo}{o m}{%
\IfNoValueTF{#1}{%
\begin{enumerate}[series=Questions,resume=*,label={(\arabic*)}]%
\item #2%
\end{enumerate}%
}{%
\begin{itemize}[label={#1}]%
\item #2%
\end{itemize}%
}%
}%

\NewDocumentCommand{\Bar}{o m}{%
\IfNoValueTF{#1}{%
\begin{enumerate}[series=Questions,resume=*,label={[\arabic*]}]%
\item #2%
\end{enumerate}%
}{%
\begin{itemize}[label={#1}]%
\item #2%
\end{itemize}%
}%
}%

\begin{document}
\Foo{poor Yorick!}
\Foo[$+$]{poor Yorick!}
\Bar{Joelle}
\Bar[$-$]{Joelle}
\Foo[$\circ$]{poor Yorick!}
\Foo{poor Yorick!}
\end{document}

\end{document}

-
Thank you very much! I had started down a similar path to your solution earlier on, but then was worried that sequences of single-item lists could be some sort of LaTeX antipattern. So are they actually kosher? –  Josh Tilles Jun 16 '12 at 19:01
If there are any spacing issues that you notice, they should be adjustable with the enumitem package. –  Peter Grill Jun 16 '12 at 20:40
@user600510: I was not very happy with the earlier solution and have provided another one that uses a single macro. –  Peter Grill Jun 17 '12 at 4:53