Skip to content

Commit

Permalink
sort thm-code, issue #304
Browse files Browse the repository at this point in the history
  • Loading branch information
u-fischer committed Nov 7, 2023
1 parent 1456e58 commit e127479
Show file tree
Hide file tree
Showing 10 changed files with 862 additions and 22 deletions.
6 changes: 6 additions & 0 deletions doc/hyperref-doc.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3111,6 +3111,12 @@ \subsubsection{nomencl}
\renewcommand*{\pagedeclaration}[1]{\unskip, \hyperpage{#1}}
\end{verbatim}

\subsubsection{ntheorem}

This package is not fully supported. The \texttt{thref} option should not be used at all as
it breaks the \verb+\label+ command. It also not garantied that links to theorems always work
properly as the package redefines many internals and but offers no proper interface for hyperlinks.


\subsubsection{ntheorem-hyper}
This package is obsolete, use the up-to-date original
Expand Down
86 changes: 64 additions & 22 deletions hyperref.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -10967,48 +10967,90 @@
}
% \end{macrocode}
%
% Support for theorems. We move the target into the para hook to
% avoid spacing problem. The patch will not apply to
% \texttt{cleveref} but hopefully it does the right thing anyway.
% \section{Support for theorems}
%
% Hyperlink support in theorems has to resolve typically three problems:
% \begin{itemize}
% \item The \cs{refstepcounter} can be issued to early. The target it produces
% can be separated from the theorem and then the link if wrong (see testfiles thm-005-xx).
% It can also affect spacing.
% This means that it is better if this \cs{refstepcounter} doesn't produce a target.
%
% \item The natural place for the target (before the theorem label) is normally not printed
% directly but delayed to the next paragraph begin (through the \cs{item} code or by other means).
% and \cs{label} commands used directly at the begin of the environment are perhaps
% processed \emph{before} the target is created
% and so do not know the correct \cs{@currentHref} value. That means that if
% \cs{refstepcounter} does not produce a target, it should nevertheless update the target
% name.
%
% \item The target should be placed (in horizontal mode) before the theorem label to avoid
% side effects on spacing. For this a suitable place must be
% found depending on the actual theorem definition.
% \end{itemize}
%
% Theorems typically issue the \cs{refstepcounter} in \cs{@thm}.
% The first two points can therefore be resolved by patching this command
% and replacing the \cs{refstepcounter}.
%
% The last point is the most complicated. Simply moving at the point \cs{refstepcounter}
% is encountered into the next para hook doesn't work, as this can be in a header if there is page
% break. The next item hook doesn't work for the same reason,
% also not every theorem environment actually use \cs{item} (e.g. \xpackage{amsthm} and ams-classes).
% Patching (or using a hook) \cs{@begintheorem} doesn't work either as \xpackage{ntheorem}
% redefines this on the fly.
%
% For now we move the target creation into the item hook. This is not perfect,
% as it can end up in header or be to much to the right, but there is not really
% a better place.
%
% The patch will not apply to
% \texttt{cleveref}, this means that with cleveref there
% can be a page break between target and theorem but beside this
% it hopefully it does the right thing.
% \cs{@currentHref} is updated directly for labels set before
% the actual start of the paragraph. The target can be behind
% a target created from a following list, so we restore \cs{@currentHref}
% just in case
%
% just in case.
% Later we could use sockets here (or hope that the packages take this over.
%
% \begin{macrocode}
\newcommand\Hy@theorem@refstepcounter[1]
{%
\H@refstepcounter{#1}%
\hyper@makecurrent{#1}%
\global\let\Hy@dth@currentHref\@currentHref
\Hy@theorem@makelinktarget{\Hy@dth@currentHref}%
}
\newcommand\Hy@theorem@makelinktarget[1]
{
\AddToHookNext{cmd/item/before}
{\AddToHookNext{para/begin}
{\let\Hy@tempa\@currentHref
\MakeLinkTarget*{\Hy@dth@currentHref}%
\MakeLinkTarget*{#1}% \Hy@dth@currentHref
\global\let\@currentHref\Hy@tempa
}%
}%
}
}%
}
% \end{macrocode}
% amsthm doesn't issue an item in the theorem, we delay the target into
% \cs{deferred@thm@head} and hope that it always begins a paragraph.
% \begin{macrocode}
\AddToHook{package/amsthm/after}
{
\renewcommand\Hy@theorem@refstepcounter[1]
\AddToHook{begindocument}
{%
\@ifundefined{deferred@thm@head}{}
{%
\H@refstepcounter{#1}%
\hyper@makecurrent{#1}%
\global\let\Hy@dth@currentHref\@currentHref
\AddToHookNext{cmd/deferred@thm@head/before}
{\AddToHookNext{para/begin}
{\let\Hy@tempa\@currentHref
\MakeLinkTarget*{\Hy@dth@currentHref}%
\global\let\@currentHref\Hy@tempa
}%
}%
}
\renewcommand\Hy@theorem@makelinktarget[1]
{%
\AddToHookNext{cmd/deferred@thm@head/before}
{\AddToHookNext{para/begin}
{\let\Hy@tempa\@currentHref
\MakeLinkTarget*{#1}%
\global\let\@currentHref\Hy@tempa
}%
}%
}%
}%
}
\@ifundefined{hyper@nopatch@thm}{%
\AtBeginDocument{%
Expand Down
22 changes: 22 additions & 0 deletions testfiles-pdftex/thm-005-amsthm.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
%check if anchor is on the right page!
\input{regression-test}
\documentclass[12pt]{book}
\usepackage{amsthm}
\newtheorem{theorem}{theorem}

\usepackage{hyperref}
\begin{document}%
\START\showoutput
x

\vspace{30\baselineskip}
x\\x\\x\\x\\x\\x\\x%
\begin{theorem}\label{blub}
xxx
\end{theorem}


\newpage
\ref{blub}

\end{document}
204 changes: 204 additions & 0 deletions testfiles-pdftex/thm-005-amsthm.tlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
Completed box being shipped out [1]
\vbox(630.3738+0.0)x407.0
.\hbox(0.0+0.0)x0.0
.\vbox(0.0+0.0)x0.0, glue set - 18.99626fil
..\kern 0.0
..\kern 20.0
..\kern -1.00374
..\hbox(0.0+0.0)x0.0, glue set - 15.99626fil
...\kern 0.0
...\kern 17.0
...\kern -1.00374
...\pdfdest name{page.1} xyz
...\penalty 10000
...\glue 0.0 plus 1.0fil minus 1.0fil
..\glue 0.0 plus 1.0fil minus 1.0fil
.\glue(\lineskip) 0.0
.\vbox(630.3738+0.0)x407.0
..\glue 20.0
..\vbox(610.3738+0.0)x390.0, shifted 17.0
...\vbox(12.0+0.0)x390.0, glue set 4.26668fil
....\glue 0.0 plus 1.0fil
....\hbox(7.73332+0.0)x390.0
.....\hbox(7.73332+0.0)x390.0, glue set 384.12506fil
......\glue 0.0 plus 1.0fil
......\OT1/cmr/m/n/12 1
...\glue 19.8738
...\glue(\lineskip) 0.0
...\vbox(548.5+0.0)x390.0
....\write-{}
....\pdfdest name{Doc-Start} xyz
....\glue(\topskip) 6.83333
....\hbox(5.16667+0.0)x390.0, glue set 366.17386fil
.....\hbox(0.0+0.0)x17.62482
.....\OT1/cmr/m/n/12 x
.....\penalty 10000
.....\glue(\parfillskip) 0.0 plus 1.0fil
.....\glue(\rightskip) 0.0
....\glue 435.0
....\glue 0.0
....\glue(\parskip) 0.0 plus 1.0
....\glue(\parskip) 0.0
....\glue(\baselineskip) 9.33333
....\hbox(5.16667+0.0)x390.0, glue set 366.17386fil
.....\hbox(0.0+0.0)x17.62482
.....\OT1/cmr/m/n/12 x
.....\penalty 10000
.....\glue 0.0 plus 1.0fil
.....\penalty -10000
.....\glue(\rightskip) 0.0
....\penalty 150
....\glue(\baselineskip) 9.33333
....\hbox(5.16667+0.0)x390.0, glue set 383.79868fil
.....\OT1/cmr/m/n/12 x
.....\penalty 10000
.....\glue 0.0 plus 1.0fil
.....\penalty -10000
.....\glue(\rightskip) 0.0
....\glue(\baselineskip) 9.33333
....\hbox(5.16667+0.0)x390.0, glue set 383.79868fil
.....\OT1/cmr/m/n/12 x
.....\penalty 10000
.....\glue 0.0 plus 1.0fil
.....\penalty -10000
.....\glue(\rightskip) 0.0
....\glue(\baselineskip) 9.33333
....\hbox(5.16667+0.0)x390.0, glue set 383.79868fil
.....\OT1/cmr/m/n/12 x
.....\penalty 10000
.....\glue 0.0 plus 1.0fil
.....\penalty -10000
.....\glue(\rightskip) 0.0
....\glue(\baselineskip) 9.33333
....\hbox(5.16667+0.0)x390.0, glue set 383.79868fil
.....\OT1/cmr/m/n/12 x
.....\penalty 10000
.....\glue 0.0 plus 1.0fil
.....\penalty -10000
.....\glue(\rightskip) 0.0
....\glue(\baselineskip) 9.33333
....\hbox(5.16667+0.0)x390.0, glue set 383.79868fil
.....\OT1/cmr/m/n/12 x
.....\penalty 10000
.....\glue 0.0 plus 1.0fil
.....\penalty -10000
.....\glue(\rightskip) 0.0
....\penalty 150
....\glue(\baselineskip) 9.33333
....\hbox(5.16667+0.0)x390.0, glue set 383.79868fil
.....\OT1/cmr/m/n/12 x
.....\penalty 10000
.....\glue(\parfillskip) 0.0 plus 1.0fil
.....\glue(\rightskip) 0.0
....\glue 0.0
...\glue(\baselineskip) 30.0
...\hbox(0.0+0.0)x390.0
....\hbox(0.0+0.0)x390.0
.\kern 0.0
Completed box being shipped out [2]
\vbox(630.3738+0.0)x452.0
.\vbox(0.0+0.0)x0.0, glue set - 18.99626fil
..\kern 0.0
..\kern 20.0
..\kern -1.00374
..\hbox(0.0+0.0)x0.0, glue set - 60.99626fil
...\kern 0.0
...\kern 62.0
...\kern -1.00374
...\pdfdest name{page.2} xyz
...\penalty 10000
...\glue 0.0 plus 1.0fil minus 1.0fil
..\glue 0.0 plus 1.0fil minus 1.0fil
.\glue(\lineskip) 0.0
.\vbox(630.3738+0.0)x452.0
..\glue 20.0
..\vbox(610.3738+0.0)x390.0, shifted 62.0
...\vbox(12.0+0.0)x390.0, glue set 4.26668fil
....\glue 0.0 plus 1.0fil
....\hbox(7.73332+0.0)x390.0
.....\hbox(7.73332+0.0)x390.0, glue set 384.12506fil
......\OT1/cmr/m/n/12 2
......\glue 0.0 plus 1.0fil
...\glue 19.8738
...\glue(\lineskip) 0.0
...\vbox(548.5+0.0)x390.0, glue set 526.5fil
....\write1{\newlabel{blub}{{1}{\thepage }{}{theorem.0.0.1}{}}}
....\glue(\topskip) 3.66669
....\hbox(8.33331+0.0)x390.0, glue set 305.2165fil
.....\penalty 10000
.....\hbox(0.0+0.0)x0.0
......\hbox(0.0+0.0)x0.0, shifted -14.5
.......\pdfdest name{theorem.0.0.1} xyz
.......\penalty 10000
.....\OT1/cmr/bx/n/12 t
.....\OT1/cmr/bx/n/12 h
.....\OT1/cmr/bx/n/12 e
.....\OT1/cmr/bx/n/12 o
.....\OT1/cmr/bx/n/12 r
.....\OT1/cmr/bx/n/12 e
.....\OT1/cmr/bx/n/12 m
.....\kern 0.0
.....\glue 4.5 plus 2.25 minus 1.5
.....\OT1/cmr/bx/n/12 1
.....\kern 0.0
.....\OT1/cmr/bx/n/12 .
.....\glue 5.0 plus 1.0 minus 1.0
.....\OT1/cmr/m/it/12 x
.....\OT1/cmr/m/it/12 x
.....\OT1/cmr/m/it/12 x
.....\penalty 10000
.....\glue(\parfillskip) 0.0 plus 1.0fil
.....\glue(\rightskip) 0.0
....\penalty -51
....\glue 10.0 plus 4.0 minus 6.0
....\glue 0.0 plus 1.0fil
....\glue 0.0
...\glue(\baselineskip) 30.0
...\hbox(0.0+0.0)x390.0
....\hbox(0.0+0.0)x390.0
Completed box being shipped out [3]
\vbox(630.3738+0.0)x407.0
.\vbox(0.0+0.0)x0.0, glue set - 18.99626fil
..\kern 0.0
..\kern 20.0
..\kern -1.00374
..\hbox(0.0+0.0)x0.0, glue set - 15.99626fil
...\kern 0.0
...\kern 17.0
...\kern -1.00374
...\pdfdest name{page.3} xyz
...\penalty 10000
...\glue 0.0 plus 1.0fil minus 1.0fil
..\glue 0.0 plus 1.0fil minus 1.0fil
.\glue(\lineskip) 0.0
.\vbox(630.3738+0.0)x407.0
..\glue 20.0
..\vbox(610.3738+0.0)x390.0, shifted 17.0
...\vbox(12.0+0.0)x390.0, glue set 4.26668fil
....\glue 0.0 plus 1.0fil
....\hbox(7.73332+0.0)x390.0
.....\hbox(7.73332+0.0)x390.0, glue set 384.12506fil
......\glue 0.0 plus 1.0fil
......\OT1/cmr/m/n/12 3
...\glue 19.8738
...\glue(\lineskip) 0.0
...\vbox(548.5+0.0)x390.0, glue set 536.5fil
....\glue(\topskip) 4.26668
....\hbox(7.73332+0.0)x390.0, glue set 366.50024fil
.....\hbox(0.0+0.0)x17.62482
.....\pdfstartlink(*+*)x* attr{/Border[0 0 1]/H/I/C[1 0 0]} action goto name{theorem.0.0.1}
.....\OT1/cmr/m/n/12 1
.....\pdfendlink
.....\penalty 10000
.....\glue(\parfillskip) 0.0 plus 1.0fil
.....\glue(\rightskip) 0.0
....\glue 0.0 plus 1.0fil
....\glue 0.0
...\glue(\baselineskip) 30.0
...\hbox(0.0+0.0)x390.0
....\hbox(0.0+0.0)x390.0
(thm-005-amsthm.aux)
Package rerunfilecheck Info: File `thm-005-amsthm.out' has not changed.
(rerunfilecheck) Checksum: D41D8CD98F00B204E9800998ECF8427E;0.
21 changes: 21 additions & 0 deletions testfiles-pdftex/thm-005-ntheorem.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
%check if anchor is on the right page!
\input{regression-test}
\documentclass[12pt]{book}
\usepackage{ntheorem}
\newtheorem{theorem}{theorem}
\usepackage{hyperref}
\begin{document}%
\START\showoutput
x

\vspace{30\baselineskip}
x\\x\\x\\x\\x\\x\\x%
\begin{theorem}\label{blub}
xxx
\end{theorem}


\newpage
\ref{blub}

\end{document}
Loading

0 comments on commit e127479

Please sign in to comment.