Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble when \begin{proof} commences with a displayed equation #790

Open
alexanderperlis opened this issue Jan 29, 2025 · 3 comments
Open

Comments

@alexanderperlis
Copy link

[This report concerns LaTeX2e <2025-06-01> pre-release-1 (develop 2025-1-27 branch) L3 programming layer <2025-01-18>.]

The document

\DocumentMetadata{testphase=latest}
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\begin{document}

\begin{proof}
\[
x=y=z
\]
\end{proof}

\end{document}

fails with

Package tagpdf Warning: nested marked content found - mcid 1

! Package tagpdf Error: The number of automatic begin (2) and end (0)
(tagpdf)                text-unit para hooks differ!

Putting some text (or even just \leavevmode) before the equation avoids the issue: \begin{proof} \leavevmode \[x=y=z\] \end{proof}

@u-fischer
Copy link
Member

I think there is \par missing in the amsthm definition of proof.

\DocumentMetadata{testphase=latest}
\documentclass{article}
\usepackage{amsthm}
\usepackage{amsmath}
\makeatletter
\renewenvironment{proof}[1][\proofname]{\par
  \pushQED{\qed}%
  \normalfont \topsep6\p@\@plus6\p@\relax
  \trivlist
  \item[\hskip\labelsep
        \itshape
    #1\@addpunct{.}]\ignorespaces
}{%
  \popQED\endtrivlist\par\@endpefalse %<-- par inserted
}
\makeatother
\begin{document}

\begin{proof}
\[
x=y=z
\]
\end{proof}

\end{document}

@alexanderperlis
Copy link
Author

The location of the repair surprises me — I was expecting a repair would need to occur in the \proof portion rather than the \endproof portion — after all, when I precede the display math with some text (or with \leavevmode), the original problem went away. Therefore I would have expected a solution to somehow involve the forcing of horizontal mode after the item label. (It seems proof expands to a \trivlist and the italic word “Proof” is an \item label, and TeX is not in horizontal mode after that label: \begin{proof} \ifvmode Vertical! \fi \end{proof}.)

Why not force horizontal mode after the proof item label? Or we should first ask, why in general is TeX in vertical mode after any list item label? Is this just an artifact of how \trivlist was originally created, or was this an intentional design? I would guess intentional, since it allows for constructs like

\begin{itemize}

\item
\begin{itemize}
\item 1
\item 2
\end{itemize}

\item 3
\end{itemize}

without introducing an empty line before the sublist.

Image

On the other hand, the consequence is that constructs like

\begin{theorem}
\begin{itemize}
\item First
\item Second
\end{itemize}
\end{theorem}

\begin{proof}
\begin{itemize}
\item First
\item Second
\end{itemize}
\end{proof}

place the first bulleted item on the same line as the theorem or proof label, which strikes me as more of an awkward-looking annoyance than a feature (and is avoided by adding some text, or at least a \leavevmode).

Image

Thus it might be okay to patch the proof environment so that TeX is in horizontal mode after the label. In fact, the current testphase=latest does just that for the theorem environment! The behavior of \begin{theorem} \ifvmode Vertical! \fi \end{theorem} changes when testphase=latest is specified; in particular, the code above then places the first theorem item on a line by itself:

Image

Is that a bug? Or if intentional, then should the same approach be used with proof?

I note that the insert-\par-into-proof patch also takes care of another case:

\trivlist
\item[Label.] This is an item.
\endtrivlist

\begin{proof}
This is a proof.
\end{proof}

This is a curious case, because \begin{proof} This is a proof. \end{proof} was not broken by itself, yet breaks (document won't compile) when preceded by a \trivlist as shown here, but is (somehow magically) fixed by the proof patch! I do wonder whether there might be an issue with \trivlist itself leaving an incorrect state that can cascade, which is simply being masked by the patch? The following is also broken:

\trivlist
\item[Label.] This is an item.
\endtrivlist

\begin{theorem}
This is a theorem.
\end{theorem}

Without knowing what I'm doing, I tried to mimic your patch with

\def\@endtheorem{\endtrivlist\par\@endpefalse } %<-- par inserted

but this did not work.

In summary, this comment is bringing up several potential bugs or issues:

  • The post-item-label TeX mode inside theorem has changed from vertical to horizontal.
  • The existence of a \trivlist...\endtrivlist earlier in a document causes subsequent trouble for theorem. Is there a tagging-related bug in \trivlist, or in theorem, or perhaps in both?
  • In particular, if the \endtrivlist\@endpefalse occurring in the \endproof portion of proof needs a \par to be inserted (per the proof-patch), is the same not true of the \endtrivlist\@endpefalse occurring in \@endtheorem?

@car222222
Copy link

In addition to the bug found by @u-fischer, there may be a need for more fundamental investigation of a mismatch between expectations and reality here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants