2

My purpose is to create visual steps in proofs.

I cooked this from the environment description:

\documentclass{article}

\newcounter{subproofcount}
\newcommand{\thesubproffcount}{\arabic{subproofcount}}
\newcommand{\subprooflabel}[1]{\refstepcounter{subproofcount}(\roman{subproofcount}) \underline{\bf #1}}

\newenvironment{subproof}{\let\Olddescriptionlabel\descriptionlabel\let\descriptionlabel\subprooflabel \begin{description}\setcounter{subproofcount}{0}}{\end{description}\let\descriptionlabel\Olddescriptionlabel}



\begin{document}
    Here is a proof.
    \section{Title 1}
    \section{Title 2}
    \begin{subproof}
        \item[\( A\) is open]       \label{ITEMone}
            Let \( \epsilon>0\) etc.
        \item[\( A\) is bounded] 
            Suppose etc. Using \ref{ITEMone}
    \end{subproof}
\end{document}

The items are correctly numbered:

output

My problem is that \ref{ITEMone} creates a reference to the section (i.e. "2" in this example) instead of a reference to the subproof item (i.e. (i) in the example).

EDIT: Best answer for my use case here : https://tex.stackexchange.com/a/697316/109167

3
  • 1
    Why are you using a description environment instead of an enumerate environment?
    – Mico
    Commented Apr 11, 2022 at 11:00
  • The most logical explanation is that \refstepcounter is inside a group and \@currentlable is local to that group. It would probably be easier to create a new list environment from scratch. Commented Apr 11, 2022 at 13:24
  • 1
    @Mico Honestly I don't remember. I did it several years ago; I remember to have tried both description and enumerate. Commented Apr 13, 2022 at 19:23

2 Answers 2

4

This uses a new list environment. Note that the default \item does not increment the counter when an optional argument is used.

The only remaining question is whether to place the left margin to the left or right of the optional argument.

\documentclass{article}
\usepackage{showframe}% alignment tool

\newcounter{subproofcount}
\renewcommand{\thesubproofcount}{\roman{subproofcount}}
\newcommand{\subprooflabel}[1]{\hbox to \leftmargin{\hfill(\thesubproofcount)\hspace\labelsep}\underline{\bf #1}}
\newcommand{\subproofitem}[1][]{\refstepcounter{subproofcount}\csname @item\endcsname[#1]}

\newenvironment{subproof}{\let\item=\subproofitem
  \list{subproofcount}{\usecounter{subproofcount}\let\makelabel=\subprooflabel}}%
  {\endlist}

\begin{document}
    Here is a proof.
    \section{Title 1}
    \section{Title 2}
    \begin{subproof}
        \item[\( A\) is open]       \label{ITEMone}
            Let \( \epsilon>0\) etc.\\
            Add another line.
        \item[\( A\) is bounded] 
            Suppose etc. Using \ref{ITEMone}
    \end{subproof}
\end{document}
3
  • If I do two subproofs in the same document, I get warnings: "destination with the same identifier (name{subproofcount.2}) has been already used". So if I refer to the point (iii), in fact it refer to point (iii) of the first subproof. hyperref makes a wrong link, but this is not big deal. Commented Apr 13, 2022 at 19:57
  • 1
    Hyperref redefines \item to activate the target name Item.\theitem. However, I have to bypass \item and go directly to \@item. So when using hyperref you need need to add \@hyper@itemtrue to \subproofitem. (use \makeatletter) Commented Apr 14, 2022 at 1:51
  • Works fine. Thanks. Commented Apr 14, 2022 at 19:38
3

Since the numbers -- (i), (ii), etc -- in the step-by-step proof are at least as visible as the associated descriptive labels, I would create a bespoke enumerated environment called subproof with the help of the enumitem package and its \newlist and \setlist macros. That way, cross-referencing items via \label and \ref is completely straightforward.

enter image description here

\documentclass{article}
\usepackage[normalem]{ulem}  % for \uline macro
\newcommand\descr[1]{{\boldmath\bfseries\uline{#1}}\hphantom{.}}

\usepackage{enumitem}
\newlist{subproof}{enumerate}{1}
\setlist[subproof]{label=(\roman*)}

\begin{document}
\section{Title 1}
\section{Title 2}

\begin{subproof}
    \item \label{ITEMone}
    \descr{\( A\) is open} Let \( \epsilon>0\). Then \dots
    \item 
    \descr{\( A\) is bounded} Using subproof \ref{ITEMone}, we \dots
\end{subproof}
\end{document}

You must log in to answer this question.

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