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

\newtheorem does not use trivlist settings #767

Open
mbertucci47 opened this issue Nov 21, 2024 · 3 comments
Open

\newtheorem does not use trivlist settings #767

mbertucci47 opened this issue Nov 21, 2024 · 3 comments
Assignees
Labels
area: block environments area: theorems and similar structures bug Something isn't working in code we maintain (directly) fixed in branch fixed in a branch different to develop

Comments

@mbertucci47
Copy link
Contributor

mbertucci47 commented Nov 21, 2024

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.

@FrankMittelbach
Copy link
Member

Your examples, seem to be a white lie @mbertucci47 :-). You say Now adding ... which fooled me at first. In reality, I think your first display was typeset with pdftex and the second with tagging was typeset with luatex. It is a bit surprising that we see so much change in the paragraphs, but I guess that is CM to LM.

Anyhow, your proposed solution goes in the wrong direction in my opinion. You do not want to hardwire such settings somewhere in the middle of the code (this is worse than allowing \@listi to mess things up, I would say). What you want to do instead is to make use of the template/instance machinery.

So a better solution, in my opinion, might be this:

\DeclareInstance{blockenv}{theorem}{display}
{
  env-name       = theorem-like,
  tag-name       = theorem-like,
  tag-class      = ,
  tagging-recipe = standalone,
  inner-level-counter  = ,
  level-increase = false,
  setup-code     = ,
  block-instance = theoremblock ,   % <--- do not reuse the displayblock, use your own
}

\DeclareInstance{block}{theoremblock-0}{display}
  {
    parindent      = \parindent ,
    par-skip        = \parskip ,
  } 

That doesn't solve this, unfortunately:

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

That is a bug in the code; I guess I confused myself trying to support the various legacy setting possibilities. For the moment that could be (partly) repaired with

\DeclareInstance{block}{list-1}{display}{  parindent  = 0pt } 

but this way you can't alter the \listparindent globally any longer. The correct fix has to happen in the code.

@FrankMittelbach FrankMittelbach added bug Something isn't working in code we maintain (directly) area: theorems and similar structures area: block environments labels Nov 23, 2024
@FrankMittelbach FrankMittelbach self-assigned this Nov 23, 2024
@mbertucci47
Copy link
Contributor Author

In reality, I think your first display was typeset with pdftex and the second with tagging was typeset with luatex.

@FrankMittelbach Wow I did not even notice that, yes you are right. Sorry about that!

What you want to do instead is to make use of the template/instance machinery.

Yes that's definitely better. When I naively add your proposed code to my example it seems to indent the entire block, but I suspect some other changes being made in latex3/latex2e#1561 might fix this.

@FrankMittelbach
Copy link
Member

but I suspect some other changes being made in latex3/latex2e#1561 might fix this.

It needed more than my handwaving reply (due to one or two bugs discovered this way. I think it is now correct and will show up in the next dev release in a couple of days.

@FrankMittelbach FrankMittelbach added the fixed in branch fixed in a branch different to develop label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: block environments area: theorems and similar structures bug Something isn't working in code we maintain (directly) fixed in branch fixed in a branch different to develop
Projects
None yet
Development

No branches or pull requests

2 participants