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

wrong spacing above theorems #29

Open
blumens opened this issue Jul 10, 2022 · 16 comments
Open

wrong spacing above theorems #29

blumens opened this issue Jul 10, 2022 · 16 comments

Comments

@blumens
Copy link

blumens commented Jul 10, 2022

I noticed that sometimes there is too much spacing above a theorem. I found two cases where this occurs:

If the preceding paragraph ends in a line that is exactly as long as the \textwidth. (In this case, adding a % at the end of the paragraph solves the issue.)

If the theorem is preceded by an align* environment.

@muzimuzhi
Copy link
Owner

Does the following example reproduces the problem you reported? If so I'm afraid that's the default behavior inherited from LaTeX2e format.

\documentclass{article}
\usepackage{lipsum}
\usepackage{amsmath}

% case 1: LaTeX2e's \newtheorem
\newtheorem{theorem}{Theorem}

% case 2: amsthm's \newtheorem
% \usepackage{amsthm}
% \newtheorem{theorem}{Theorem}

% case 3: thmtools' \declaretheorem, with amsthm loaded
% \usepackage{amsthm, thmtools}
% \declaretheorem{theorem}

\parindent=0pt
\def\dummy{%
  Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
  vestibulumut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
  \hfill mauris.}

\begin{document}
\dummy
\begin{theorem}
  preceded by a paragraph ends in a full-line
\end{theorem}
\dummy
\begin{align*}
  a + b = c
\end{align*}
\begin{theorem}
  preceded by an \verb|align*|
\end{theorem}
\dummy
\begin{align*}
  a + b = c
\end{align*}
\dummy

\bigskip
Accumulated natural height of the current page: \the\pagetotal
\end{document}

image

Accumulated natural height of the current page:

  • latex2e, 219.94444pt
  • amsthm, 219.94444pt
  • amsthm + thmtools, 220.06pt

@blumens
Copy link
Author

blumens commented Jul 10, 2022

No, everything looks fine. Unfortunately, the only examples I do have use commercial fonts. Here are two pictures of how it looks like. The difference is just a % at the end of the line.

bad

good

@muzimuzhi
Copy link
Owner

I suspect the text before lemma wraps to the second line and leaves the second line empty. Can you check if the problem persists when the lemma env is replaced with other trivlist wrappers, for example center env?

Please share a short but complete latex example. If free fonts can't reproduce problem, commercial fonts are ok.

@blumens
Copy link
Author

blumens commented Jul 10, 2022

A center environment works fine. No additional space if I remove the %. I'll try to find a small example to reproduce, but it might take some time.

@blumens
Copy link
Author

blumens commented Jul 10, 2022

Okay, I found a small example using Computer Modern. It seems to be an interaction between thmtools and hyperref.

\PassOptionsToPackage{a5paper,pagesize}{typearea}                                                
\documentclass[a5paper,10pt,fleqn,DIV9]{scrbook}                                                 
\usepackage[fleqn]{amsmath}                                                                      
\usepackage[hidelinks]{hyperref}                                                                 
\usepackage{microtype}                                                                           
\usepackage{amsthm,thmtools}                                                                     
                                                                                                 
\declaretheorem[name=Lemma]{Lem}                                                    
                                                                                                 
\typearea{9}                                                                                     
                                                                                                 
\begin{document}                                                                                 
Finally, let us consider morphisms between polynomial functors.                                  
\begin{Lem}                                                                                      
foo                                                                                              
\end{Lem}                                                                                        
\end{document}                                                                                   

@blumens
Copy link
Author

blumens commented Jul 10, 2022

PS: If I run my example with amsthm only, it works as expected.

@muzimuzhi
Copy link
Owner

Thank you for the example. Starting from it I got a further simplified one:

\documentclass{article}
% \usepackage{showframe}
\usepackage{thmtools}
\usepackage{hyperref}

\newtheorem{Lem}{Lemma}

% \AddToHook{env/Lem/begin}{\unskip} % workaround

\begin{document}
Finally, let us consider morphisms between polynomial functors functors ab.
\begin{Lem}
foo
\end{Lem}
Finally, let us consider morphisms between polynomial functors functors ab.
\begin{center}
foo
\end{center}
\end{document}

A thorough analysis and fix would need more time. Before that, can you test if the workaround \AddToHook{env/Lem/begin}{\unskip} works for you?

@blumens
Copy link
Author

blumens commented Jul 11, 2022

I tried it with the large document I'm working on, and it seems to fix the spacing issue. But now I get a lot of errors:

! You can't use `\unskip' in vertical mode.

@muzimuzhi
Copy link
Owner

Then \AddToHook{env/Lem/begin}{\ifvmode\else\unskip\fi}.

@blumens
Copy link
Author

blumens commented Jul 11, 2022

That seems to fix the issue.

@blumens
Copy link
Author

blumens commented Jul 11, 2022

I spoke too soon: The issue is fixed after paragraphs with full lines, but it persists after align* environments.

@blumens
Copy link
Author

blumens commented Jul 11, 2022

Here is a test case:

\documentclass{article}
% \usepackage{showframe}
\usepackage{amsmath} 
\usepackage{thmtools}
\usepackage{hyperref}

\newtheorem{Lem}{Lemma}

\AddToHook{env/Lem/begin}{\unskip} % workaround                

\begin{document}
Finally, let us consider morphisms between polynomial functors functors ab.
\begin{Lem}
foo
\end{Lem}
Finally, let us consider morphisms between polynomial functors functors ab.
\begin{center}
foo
\end{center}
Finally, let us consider morphisms between polynomial functors functors ab.
\begin{align*}
  foo
\end{align*}
\begin{Lem}
foo
\end{Lem}

\end{document}

@muzimuzhi
Copy link
Owner

Hmm the align* case is reproducible with LaTeX2e's vanilla \newtheorem, but not amsthm.

@blumens
Copy link
Author

blumens commented Aug 20, 2022

Do you need more input from me?

It is clearly a bug, not only in thmtools but also for the vanilla version, that is fixed in amsthm.

@muzimuzhi
Copy link
Owner

Hope it will be resolved by latex3/latex2e#990.

@mbertucci47
Copy link
Collaborator

Hmm the align* case is reproducible with LaTeX2e's vanilla \newtheorem, but not amsthm.

I am able to reproduce the extra space with both the vanilla \newtheorem and amsthm. It goes away if you put an empty line (i.e. a \par) before the theorem, but elsewhere it is bad advice to put an empty line after align*.

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

No branches or pull requests

3 participants