latex3 / tagging-project

Issues related to the tagging project
https://latex3.github.io/tagging-project/
LaTeX Project Public License v1.3c
41 stars 15 forks source link

`\newtheorem` does not use trivlist settings #767

Open mbertucci47 opened 20 hours ago

mbertucci47 commented 20 hours ago

I know there is some discrepancy expected in output between the tagging code \newtheorem and the usual one. However, I think with minimal effort they could look much closer than they currently do. Right now \@begintheorem calls \UseInstance{block}{theorem}{} but this could be changed to \UseInstance{blockenv}{theorem}{par-skip=\parskip,parindent=\parindent}. This makes the heading indented but adding \noindent before \mode_leave_vertical: seems to fix this without affecting tagging (I don't claim this is the correct fix).

\documentclass{article}
\usepackage{kantlipsum}

\newtheorem{theorem}{Theorem}

\begin{document}

\begin{theorem}
\kant[1][1-2]

\kant[2][1-2]
\begin{enumerate}
\item abc
\item \kant[3][1-2]

\kant[4][1-2]
\end{enumerate}
\end{theorem}

\end{document}

Here's the output without tagging.

test-1

Now adding

\DocumentMetadata
  {
    lang=en-US,
    pdfversion=2.0,
    pdfstandard=ua-2,
    testphase={phase-III,math,title,table,firstaid}
  }

to the example above gives

test-1

With the proposed fix:

% !TeX TXS-program:compile = txs:///lualatex
\DocumentMetadata
  {
    lang=en-US,
    pdfversion=2.0,
    pdfstandard=ua-2,
    testphase={phase-III,math,title,table,firstaid}
  }
\documentclass{article}

\usepackage{kantlipsum}

\makeatletter
\ExplSyntaxOn
\def\@begintheorem#1#2{
  \UseInstance{blockenv}{theorem}{par-skip=\parskip,parindent=\parindent} % Changed
  \tagpdfparaOff
  \noindent % Added
  \mode_leave_vertical:
  \MakeLinkTarget{\l__block_thm_current_counter_tl}
  \tag_struct_begin:n{tag=Caption}
   \group_begin:
   \bfseries
   \tag_mc_begin:n {}
     #1\
   \tag_mc_end:
    \tag_struct_begin:n{tag=Lbl}
      \tag_mc_begin:n {}
          #2
      \tag_mc_end:
    \tag_struct_end:
    \group_end:
  \tag_struct_end:
  \tagpdfparaOn
  \__block_start_para_structure_unconditionally:n { \PARALABEL }
  \itshape
  \hskip\labelsep
  \ignorespaces
}
\ExplSyntaxOff
\makeatother

\newtheorem{theorem}{Theorem}

\begin{document}

\begin{theorem}
\kant[1][1-2]

\kant[2][1-2]
\begin{enumerate}
\item abc
\item \kant[3][1-2]

\kant[4][1-2]
\end{enumerate}
\end{theorem}

\end{document}

test-1

Similar changes would need to be made for the amsthm firstaid.

Edit

Hmm I see the proposed fix also affects the indent in enumerate. Not sure about that at the moment.