latex3 / tagging-project

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

amsthm firstaid style issues #733

Open mbertucci47 opened 6 days ago

mbertucci47 commented 6 days ago

The amsthm firstaid seems to work well. I tested the amsthm file thmtest.tex and found only two issues. It seems the "space above" and "space below" parameters of \newtheoremstyle are not respected at all. Also, if a custom head spec is given in \newtheoremstyle, then the head punctuation is ignored and parent-child warnings are produced. Here's an example.

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

\newtheoremstyle{citing}% name
  {20pt}%      Space above, empty = `usual value'
  {3pt}%      Space below
  {\itshape}% Body font
  {}%         Indent amount (empty = no indent, \parindent = para indent)
  {\bfseries}% Thm head font
  {.}%        Punctuation after thm head
  {.5em}%     Space after thm head: " " = normal interword space;
        %       \newline = linebreak
  {\thmnumber{#2 }\thmname{#1}\thmnote{: #3}}% Thm head spec

\theoremstyle{citing}
\newtheorem{theorem}{Theorem}

\begin{document}

\begin{theorem}
text
\end{theorem}
text
\begin{theorem}[some note]
text
\end{theorem}

\end{document}

As you can see, the 20pt space above is ignored, and there is no period after the theorem head.

mbertucci47 commented 6 days ago

I think the space parameters are ignored because they are used to set \@topsep and \@topsepadd which the firstaid code doesn't use because the theorem is no longer implemented as a trivlist (please correct me if I'm wrong).

FrankMittelbach commented 6 days ago

that sounds like a very likely cause (not being able to look right now)

mbertucci47 commented 6 days ago

And I think the head punctuation is ignored because \the\thm@headpunct was moved into \thmhead@plain but is not accounted for with other \thmheads.

u-fischer commented 6 days ago

@FrankMittelbach handling the topspace is rather easy, I simply need to pass the value to the instance call. But I'm not sure what to do about the space below. end-skip seems to do nothing:

\DocumentMetadata
  {
    lang=en-US,
    pdfversion=2.0,
    pdfstandard=ua-2,
    testphase={phase-III,math,table,title,firstaid}
  }
\documentclass{article}
\begin{document}
xxxxx
\begin{enumerate}[end-skip=50pt]
\item blub
\end{enumerate}
xxxxx

\end{document}
mbertucci47 commented 6 days ago

The firstaid code defines \thmname etc. to tag their contents but does not wrap it in a Caption struct if \thmhead is not \thmhead@plain, since \tag_struct_begin:n{tag=Caption} is set in \thmhead@plain but not otherwise.

mbertucci47 commented 6 days ago

So that chunk of code could instead be

    \def\@begintheorem##1##2[##3]{%
      \UseInstance{blockenv}{theorem}{}
      \tagpdfparaOff
      \mode_leave_vertical:
      \MakeLinkTarget{\l__block_thm_current_counter_tl}
      \group_begin:
      \normalfont
      \the\thm@headfont \thm@indent
        \@ifempty{##1}
         {\let\thmname\@gobble}
         {\def\thmname####1{\tag_mc_begin:n {}####1\tag_mc_end:}}%
        \@ifempty{##2}
         {\let\thmnumber\@gobble}
         {\def\thmnumber####1
           {\tag_struct_begin:n{tag=Lbl}\tag_mc_begin:n {}
             ####1
            \tag_mc_end:\tag_struct_end:}}%
        \@ifempty{##3}
         {\let\thmnote\@gobble}
         {\def\thmnote####1{\tag_mc_begin:n{}####1\tag_mc_end:}}%
        \tag_struct_begin:n{tag=Caption}
        \thm@swap\swappedhead\thmhead{##1}{##2}{##3}%
        \tag_mc_begin:n{}\the\thm@headpunct\tag_mc_end:
        \tag_struct_end:
        \thmheadnl % possibly a newline.
        \hskip\thm@headsep
      \group_end:
       \tagpdfparaOn
       \UseTaggingSocket{para/begin}  %
      \ignorespaces}
    \def\thmhead@plain##1##2##3{%
      \thmname{##1}
      \thmnumber{
        \@ifnotempty{##1}{~}\@upn{##2}
       }%
      \thmnote{\pdffakespace\space{\the\thm@notefont(##3)}}
      }
    \let\thmhead\thmhead@plain
    \def\swappedhead##1##2##3{%
      \thmnumber{##2}
      \thmname{\@ifnotempty{##2}{\nobreakspace}##1}
      \thmnote{\pdffakespace\space{\the\thm@notefont(##3)}}
     }

where \tag_struct_begin:n{tag=Caption} and \tag_struct_end: are moved inside \@begintheorem, out of \thmhead@plain and \swappedhead, and the same for \tag_mc_begin:n{}\the\thm@headpunct\tag_mc_end:.