8

This is a follow-up from : Custom Enumeration

I'd want to obtain something like :

Axioms list :
A1. First axiom 
A2. Second axiom
A2'. Equivalent version of the second axiom

with cross-reference, and also in a nice content-oriented manner. More specifically, I expect it to give convenient facility for reordering the items, and also it would be nice if it could generate all enumerations of the sort. For example, I wouldn't expect to need a new command for :

Hypothesis list :
H1) First hypothesis
H2) Second
H2') Another version of the second

Redefining variables in the enumerate environment (locally or globally) is fine in this setting.

The best I have so far is : (edited thanks to egreg's answer)

\documentclass{article}

\usepackage{enumitem}

\makeatletter
\def\myEnumCounter#1{\expandafter\@myEnumCounter\csname c@#1\endcsname}
\def\@myEnumCounter#1{\ifcase#1\or \or $'$\or $''$\fi}
\makeatother
\AddEnumerateCounter*{\myEnumCounter}{\@myEnumCounter}{3}

\newlist{axioms}{enumerate}{2}
\setlist[axioms,1]{label=\textbf{A\arabic{axiomsi}.}, ref=A\arabic{axiomsi}}
\setlist[axioms,2]{label=\textbf{A\arabic{axiomsi}\rlap{\myEnumCounter{axiomsii}}.},%
                   ref=A\arabic{axiomsi}\myEnumCounter{axiomsii},%
                   align=parleft,%
                   leftmargin=0em,%
                   itemsep=1.4ex,%
                   before={\stepcounter{axiomsi}}}

\begin{document}

\noindent Fail attempt %(useful to compare indentation and vertical separation): 
\begin{enumerate}[label=\textbf{A\arabic*.}]
  \item \label{item:A1} Axiom 1
  \item \label{item:A2} Axiom 2
  \item[\textbf{A2'}] \label{item:A2prime} Axiom 3
\end{enumerate}

\noindent "Almost there" attempt :
\begin{axioms}
  \item \label{item:B1} Axiom 1
  \item[]
  \begin{axioms}
    \item \label{item:B2} Axiom 2
    \item \label{item:B2prime} Axiom 2'
  \end{axioms}
\end{axioms}

\noindent References : \ref{item:A1}, \ref{item:A2} and \ref{item:A2prime} (last one doesn't work).

\noindent References : \ref{item:B1}, \ref{item:B2} and \ref{item:B2prime}.

\end{document}

The result is : (non totally up-to-date)

Result

However, there are still a few issues :

  • I used the answer to nested enumeration, skipping items to avoid having an extra label in case I need to enter the second enumeration. However, the result somewhat fails to satisfy the "content-oriented" condition.Also, the situation here is a little different, because there is a scheme : I want a label if and only if the item isn't a new axioms environment. I guess there would be a way to do that with enumitem style key, but I can't figure how.
  • There is a 1mm offset of the sub-enumeration I can't suppress (I think I tried all the keys enumitem provides for horizontal spacing)
  • I had to add the itemsep=1.4ex to ensure the sub-enumeration has the same vertical spacing as the main one, but I suspect there is a better way to do this.

1 Answer 1

4

I'd simplify the whole thing:

\documentclass{article}

\usepackage{enumitem}

\newenvironment{axioms}
 {\enumerate[label=\textbf{A\arabic*.}, ref=A\arabic*]}
 {\endenumerate}
\makeatletter
\newcommand\varitem[1]{\item[\textbf{A\arabic{enumi}\rlap{$#1$}.}]%
  \edef\@currentlabel{A\arabic{enumi}{$#1$}}}
\makeatother


\begin{document}

\begin{axioms}
  \item \label{item:A1} Axiom 1
  \item \label{item:A2} Axiom 2
  \varitem{'} \label{item:A2prime} Axiom 2$'$
  \varitem{''} \label{item:A2dprime} Axiom 2$''$
  \item Axiom 3
  \varitem{'} Axiom 3$'$
\end{axioms}

\noindent References : \ref{item:A1}, \ref{item:A2} and \ref{item:A2prime}.

\end{document}

In my opinion, \rlap is better (and primes are surely better than apostrophes), but you can simply get rid of it.


If you want different letters it's better to redefine \varitem as part of the environment:

\providecommand{\varitem}{} % to keep LaTeX quiet
\makeatletter
\newenvironment{axioms}[1]
 {\renewcommand\varitem[1]{\item[\textbf{#1\arabic{enumi}\rlap{$##1$}.}]%
    \edef\@currentlabel{#1\arabic{enumi}{$##1$}}}%
  \enumerate[label=\textbf{#1\arabic*.}, ref=#1\arabic*]}
 {\endenumerate}
\makeatother

You'll have to pass the letter to the environment:

\begin{axioms}{A}
  \item \label{item:A1} Axiom 1
  \item \label{item:A2} Axiom 2
  \varitem{'} \label{item:A2prime} Axiom 2$'$
  \varitem{''} \label{item:A2dprime} Axiom 2$''$
  \item Axiom 3
  \varitem{'} Axiom 3$'$
\end{axioms}

Alternatively, you can define a "generic" environment and other environments based on it

\providecommand{\varitem}{} % to keep LaTeX quiet
\makeatletter
\newenvironment{statements}[1]
 {\renewcommand\varitem[1]{\item[\textbf{#1\arabic{enumi}\rlap{$##1$}.}]%
    \edef\@currentlabel{#1\arabic{enumi}{$##1$}}}%
  \enumerate[label=\textbf{#1\arabic*.}, ref=#1\arabic*]}
 {\endenumerate}
\makeatother

\newenvironment{axioms}{\statements{A}}{\endstatements}
\newenvironment{hypotheses}{\statements{H}}{\endstatements}

so that axioms will be used as before.

8
  • Thanks! This new version has obvious pros (it does work, it is quite content-friendly and it doesn't rely on sublists, avoiding the concerns about spacing), but also one con : you'd need to redefine the \varitem command for each enumeration needing a different letter (imagine I now want to add an hypothesis list H1., H2., H2'...) But this is my fault, I realize now that I forgot to mention it in the question. Both \rlap and the primes are great improvements by themselves, by the way.
    – T. Verron
    Commented Jun 23, 2012 at 21:08
  • Ok, this second version is perfect. The only remaining problem is the reordering, but one could argue that it's easier to reorder items of one single list rather than nested lists.
    – T. Verron
    Commented Jun 24, 2012 at 8:24
  • @T.Verron What do you mean by "reordering"?
    – egreg
    Commented Jun 24, 2012 at 10:13
  • Let's say I have A1, A2, A2', A2'', A3 and A3' (in that order), and I decide that after all, the A3 group would be better mentioned before the A2 group, and also that A2' would be better placed before A2. The first change is easily done with either one list or nested lists, but the second change is more convenient with a nested list. On the other hand, your method allows for lists like A1, A2, A3, A2', A3' which are sometimes wishable.
    – T. Verron
    Commented Jun 24, 2012 at 11:40
  • @T.Verron If you move the whole "A3" group before the "A2", the renumbering will be automatic. You may define a "do nothing" environment, if you feel that it can be semantically more sound.
    – egreg
    Commented Jun 24, 2012 at 12:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .