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 · 11 comments
Open

\newtheorem does not use trivlist settings #767

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

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 fixed in branch fixed in a branch different to develop fixed in release issue is fixed and will be deployed in the next release of package or kernel and removed fixed in branch fixed in a branch different to develop labels Nov 25, 2024
@FrankMittelbach
Copy link
Member

@mbertucci47 Its now in the dev release an that should be available by now, so please give it a try and see if my additions and changes have improved the situation

@mbertucci47
Copy link
Contributor Author

@FrankMittelbach Looks good to me. The only difference I see in my example between tagging and no tagging is with tagging, the distance between the theorem name and number is slightly less than without tagging. With pdflatex (so computer modern, not latin modern), it's enough to change line breaks.

@mbertucci47
Copy link
Contributor Author

mbertucci47 commented Nov 28, 2024

To clarify, I think that issue was there before the most recent change.

Here are screenshots showing the difference. Both were compiled with pdflatex-dev.

Without tagging

notagging

With tagging

withtagging

The Theorem 1 with tagging looks a little cramped to me. The issue is still there with lualatex-dev but due to font metrics it's not enough to change the line break.

@FrankMittelbach
Copy link
Member

Here are screenshots showing the difference. Both were compiled with pdflatex-dev.

it is not the \labelsep; it is the fact that pdflatex by default still uses OT1 fonts, but tagging always T1 fonts and they are different. If you run both with \usepackage[T1]{fontenc} the linebreaking changes not so much. But there is another difference in that the text body is somewhat offset on the page. Nothing to do with the list stuff, that looks like something entirely different (and should probably get some test file and an issue for itself.

@mbertucci47
Copy link
Contributor Author

mbertucci47 commented Nov 28, 2024

Good point, but I don't know what you mean by "the linebreaking changes not so much". If I load \usepackage[T1]{fontenc} explicitly I get identical-looking output to the images above (still cramped with tagging, not cramped without).

But there is another difference in that the text body is somewhat offset on the page.

I'm not able to replicate this. Adding \usepackage{showframe} they both look aligned to the left and right.

To avoid confusion, here is the test file I'm using.

\DocumentMetadata
  {
    lang=en-US,
    pdfversion=2.0,
    pdfstandard=ua-2,
    testphase={phase-III,math,title,table,firstaid}
  }
\documentclass{article}
\usepackage{showframe}
\usepackage[T1]{fontenc}
\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}

and commenting/uncommenting the \DocumentMetadata declaration.

@FrankMittelbach
Copy link
Member

Good point, but I don't know what you mean by "the linebreaking changes not so much". If I load \usepackage[T1]{fontenc} explicitly I get identical-looking output to the images above (still cramped with tagging, not cramped without).

hmm, probably means I'm not able to compare the right files :-) yes, confirmed there is this difference and it looks like an incompatibility: we don't box the theorem heading so the space inside contributes to the line strech and that seems to be enough to alter the line breaking a lot (actually for the better in my opinion in that case, but that isn't the point here)

But there is another difference in that the text body is somewhat offset on the page.

I'm not able to replicate this. Adding \usepackage{showframe} they both look aligned to the left and right.

That looks like a typical Heisenberg: showframe makes the problem go away for me. But the cause is that your document is letterpaper (implicitly) but by distribution default on a4paper pdf over hre and if tagging is loaded it becomes real letterpaper on letterpaper PDF. Since your system default is letterpaper output both are identical at your end.
And if showframe is loaded that loads graphics which also fixes everything to letterpaper at my end.

So all in all what remains is put an \mbox around the heading of the theorem.

@FrankMittelbach FrankMittelbach removed the fixed in release issue is fixed and will be deployed in the next release of package or kernel label Nov 28, 2024
@mbertucci47
Copy link
Contributor Author

mbertucci47 commented Nov 29, 2024

Ah apologies for the confusion caused by my silly American defaults :)

I can replicate the shifting issue by setting a4paper. It seems like it's not the tagging code but the backend code because if I leave \DocumentMetadata but comment out testphase=... then the shift is still there. And like you said, loading showframe (rather graphics) makes the problem go away.

@mbertucci47
Copy link
Contributor Author

With my letter paper default and lualatex-dev, toggling the commented lines in the example that follows gives the following behavior.

Bad output

  • No \DocumentMetadata{}, no \usepackage{graphics}. This prints a4-sized text on letter-sized paper.

Good output

  • No \DocumentMetadata{}, yes \usepackage{graphics}. Correctly prints a4-sized text on a4-sized paper.
  • Yes \DocumentMetadata{}, no \usepackage{graphics}. Same as above.
  • Yes \DocumentMetadata{}, yes \usepackage{graphics}. Same as above.

With my letter-default, the shifted text only occurs with the first, bad output. I don't know if this is expected behavior so I will let someone else open an issue if needed.

%\DocumentMetadata{} % toggle
\documentclass[a4paper]{article}
%\usepackage{graphics} % toggle
\usepackage{kantlipsum}

\begin{document}

\kant[1-4]

\end{document}

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)
Projects
None yet
Development

No branches or pull requests

2 participants