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

recent update (2023-10-21 v7.01c) leads to warnings with amsthm #304

Closed
mbertucci47 opened this issue Oct 27, 2023 · 13 comments
Closed

recent update (2023-10-21 v7.01c) leads to warnings with amsthm #304

mbertucci47 opened this issue Oct 27, 2023 · 13 comments

Comments

@mbertucci47
Copy link
Contributor

The recent update seems to have broken hyperref support for amsthm. Here's an example file showing the issue with referencing a theorem (no issue with referencing a section):

\documentclass{article}

\usepackage{amsthm}
\usepackage{hyperref}

\newtheorem{theorem}{Theorem}

\begin{document}

\section{bla} \label{foo}

\ref{foo}

\begin{theorem} \label{thm:lab}
bla
\end{theorem}

\ref{thm:lab}

\end{document}

This results in the warning

pdfTeX warning (dest): name{theorem.1} has been referenced but does not exist, 
replaced by a fixed one
Here's the log:
This is pdfTeX, Version 3.141592653-2.6-1.40.25 (TeX Live 2023) (preloaded format=pdflatex 2023.10.26)  26 OCT 2023 21:54
entering extended mode
 restricted \write18 enabled.
 %&-line parsing enabled.
**test1.tex
(./test1.tex
LaTeX2e <2023-06-01> patch level 1
L3 programming layer <2023-10-23>
(c:/texlive/2023/texmf-dist/tex/latex/base/article.cls
Document Class: article 2023/05/17 v1.4n Standard LaTeX document class
(c:/texlive/2023/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2023/05/17 v1.4n Standard LaTeX file (size option)
)
\c@part=\count186
\c@section=\count187
\c@subsection=\count188
\c@subsubsection=\count189
\c@paragraph=\count190
\c@subparagraph=\count191
\c@figure=\count192
\c@table=\count193
\abovecaptionskip=\skip48
\belowcaptionskip=\skip49
\bibindent=\dimen140
)
(c:/texlive/2023/texmf-dist/tex/latex/amscls/amsthm.sty
Package: amsthm 2020/05/29 v2.20.6
\thm@style=\toks17
\thm@bodyfont=\toks18
\thm@headfont=\toks19
\thm@notefont=\toks20
\thm@headpunct=\toks21
\thm@preskip=\skip50
\thm@postskip=\skip51
\thm@headsep=\skip52
\dth@everypar=\toks22
)
(c:/texlive/2023/texmf-dist/tex/latex/hyperref/hyperref.sty
Package: hyperref 2023-10-21 v7.01c Hypertext links for LaTeX

(c:/texlive/2023/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty
Package: ltxcmds 2020-05-10 v1.25 LaTeX kernel commands for general use (HO)
)
(c:/texlive/2023/texmf-dist/tex/generic/iftex/iftex.sty
Package: iftex 2022/02/03 v1.0f TeX engine tests
)
(c:/texlive/2023/texmf-dist/tex/generic/pdftexcmds/pdftexcmds.sty
Package: pdftexcmds 2020-06-27 v0.33 Utility functions of pdfTeX for LuaTeX (HO
)

(c:/texlive/2023/texmf-dist/tex/generic/infwarerr/infwarerr.sty
Package: infwarerr 2019/12/03 v1.5 Providing info/warning/error messages (HO)
)
Package pdftexcmds Info: \pdf@primitive is available.
Package pdftexcmds Info: \pdf@ifprimitive is available.
Package pdftexcmds Info: \pdfdraftmode found.
)
(c:/texlive/2023/texmf-dist/tex/latex/graphics/keyval.sty
Package: keyval 2022/05/29 v1.15 key=value parser (DPC)
\KV@toks@=\toks23
)
(c:/texlive/2023/texmf-dist/tex/latex/kvsetkeys/kvsetkeys.sty
Package: kvsetkeys 2022-10-05 v1.19 Key value parser (HO)
)
(c:/texlive/2023/texmf-dist/tex/generic/kvdefinekeys/kvdefinekeys.sty
Package: kvdefinekeys 2019-12-19 v1.6 Define keys (HO)
)
(c:/texlive/2023/texmf-dist/tex/generic/pdfescape/pdfescape.sty
Package: pdfescape 2019/12/09 v1.15 Implements pdfTeX's escape features (HO)
)
(c:/texlive/2023/texmf-dist/tex/latex/hycolor/hycolor.sty
Package: hycolor 2020-01-27 v1.10 Color options for hyperref/bookmark (HO)
)
(c:/texlive/2023/texmf-dist/tex/latex/letltxmacro/letltxmacro.sty
Package: letltxmacro 2019/12/03 v1.6 Let assignment for LaTeX macros (HO)
)
(c:/texlive/2023/texmf-dist/tex/latex/auxhook/auxhook.sty
Package: auxhook 2019-12-17 v1.6 Hooks for auxiliary files (HO)
)
(c:/texlive/2023/texmf-dist/tex/latex/hyperref/nameref.sty
Package: nameref 2023-10-05 v2.54 Cross-referencing by name of section

(c:/texlive/2023/texmf-dist/tex/latex/refcount/refcount.sty
Package: refcount 2019/12/15 v3.6 Data extraction from label references (HO)
)
(c:/texlive/2023/texmf-dist/tex/generic/gettitlestring/gettitlestring.sty
Package: gettitlestring 2019/12/15 v1.6 Cleanup title references (HO)

(c:/texlive/2023/texmf-dist/tex/latex/kvoptions/kvoptions.sty
Package: kvoptions 2022-06-15 v3.15 Key value format for package options (HO)
))
\c@section@level=\count194
)
(c:/texlive/2023/texmf-dist/tex/latex/etoolbox/etoolbox.sty
Package: etoolbox 2020/10/05 v2.5k e-TeX tools for LaTeX (JAW)
\etb@tempcnta=\count195
)
\@linkdim=\dimen141
\Hy@linkcounter=\count196
\Hy@pagecounter=\count197

(c:/texlive/2023/texmf-dist/tex/latex/hyperref/pd1enc.def
File: pd1enc.def 2023-10-21 v7.01c Hyperref: PDFDocEncoding definition (HO)
Now handling font encoding PD1 ...
... no UTF-8 mapping file for font encoding PD1
)
(c:/texlive/2023/texmf-dist/tex/generic/intcalc/intcalc.sty
Package: intcalc 2019/12/15 v1.3 Expandable calculations with integers (HO)
)
\Hy@SavedSpaceFactor=\count198

(c:/texlive/2023/texmf-dist/tex/latex/hyperref/puenc.def
File: puenc.def 2023-10-21 v7.01c Hyperref: PDF Unicode definition (HO)
Now handling font encoding PU ...
... no UTF-8 mapping file for font encoding PU
)
Package hyperref Info: Hyper figures OFF on input line 4168.
Package hyperref Info: Link nesting OFF on input line 4173.
Package hyperref Info: Hyper index ON on input line 4176.
Package hyperref Info: Plain pages OFF on input line 4183.
Package hyperref Info: Backreferencing OFF on input line 4188.
Package hyperref Info: Implicit mode ON; LaTeX internals redefined.
Package hyperref Info: Bookmarks ON on input line 4435.
\c@Hy@tempcnt=\count199

(c:/texlive/2023/texmf-dist/tex/latex/url/url.sty
\Urlmuskip=\muskip16
Package: url 2013/09/16  ver 3.4  Verb mode for urls, etc.
)
LaTeX Info: Redefining \url on input line 4773.
\XeTeXLinkMargin=\dimen142

(c:/texlive/2023/texmf-dist/tex/generic/bitset/bitset.sty
Package: bitset 2019/12/09 v1.3 Handle bit-vector datatype (HO)

(c:/texlive/2023/texmf-dist/tex/generic/bigintcalc/bigintcalc.sty
Package: bigintcalc 2019/12/15 v1.5 Expandable calculations on big integers (HO
)
))
\Fld@menulength=\count266
\Field@Width=\dimen143
\Fld@charsize=\dimen144
Package hyperref Info: Hyper figures OFF on input line 6052.
Package hyperref Info: Link nesting OFF on input line 6057.
Package hyperref Info: Hyper index ON on input line 6060.
Package hyperref Info: backreferencing OFF on input line 6067.
Package hyperref Info: Link coloring OFF on input line 6072.
Package hyperref Info: Link coloring with OCG OFF on input line 6077.
Package hyperref Info: PDF/A mode OFF on input line 6082.

(c:/texlive/2023/texmf-dist/tex/latex/base/atbegshi-ltx.sty
Package: atbegshi-ltx 2021/01/10 v1.0c Emulation of the original atbegshi
package with kernel methods
)
\Hy@abspage=\count267
\c@Item=\count268
\c@Hfootnote=\count269
)
Package hyperref Info: Driver (autodetected): hpdftex.

(c:/texlive/2023/texmf-dist/tex/latex/hyperref/hpdftex.def
File: hpdftex.def 2023-10-21 v7.01c Hyperref driver for pdfTeX

(c:/texlive/2023/texmf-dist/tex/latex/base/atveryend-ltx.sty
Package: atveryend-ltx 2020/08/19 v1.0a Emulation of the original atveryend pac
kage
with kernel methods
)
\Fld@listcount=\count270
\c@bookmark@seq@number=\count271

(c:/texlive/2023/texmf-dist/tex/latex/rerunfilecheck/rerunfilecheck.sty
Package: rerunfilecheck 2022-07-10 v1.10 Rerun checks for auxiliary files (HO)

(c:/texlive/2023/texmf-dist/tex/generic/uniquecounter/uniquecounter.sty
Package: uniquecounter 2019/12/15 v1.4 Provide unlimited unique counter (HO)
)
Package uniquecounter Info: New unique counter `rerunfilecheck' on input line 2
85.
)
\Hy@SectionHShift=\skip53
)
\c@theorem=\count272

(c:/texlive/2023/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def
File: l3backend-pdftex.def 2023-10-23 L3 backend support: PDF output (pdfTeX)
\l__color_backend_stack_int=\count273
\l__pdf_internal_box=\box51
)
(./test1.aux)
\openout1 = `test1.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 8.
LaTeX Font Info:    ... okay on input line 8.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 8.
LaTeX Font Info:    ... okay on input line 8.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 8.
LaTeX Font Info:    ... okay on input line 8.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 8.
LaTeX Font Info:    ... okay on input line 8.
LaTeX Font Info:    Checking defaults for TS1/cmr/m/n on input line 8.
LaTeX Font Info:    ... okay on input line 8.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 8.
LaTeX Font Info:    ... okay on input line 8.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 8.
LaTeX Font Info:    ... okay on input line 8.
LaTeX Font Info:    Checking defaults for PD1/pdf/m/n on input line 8.
LaTeX Font Info:    ... okay on input line 8.
LaTeX Font Info:    Checking defaults for PU/pdf/m/n on input line 8.
LaTeX Font Info:    ... okay on input line 8.
Package hyperref Info: Link coloring OFF on input line 8.
 (./test1.out) (./test1.out)
\@outlinefile=\write3
\openout3 = `test1.out'.

 [1

{c:/texlive/2023/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] (./test1.aux)
 ***********
LaTeX2e <2023-06-01> patch level 1
L3 programming layer <2023-10-23>
 ***********
Package rerunfilecheck Info: File `test1.out' has not changed.
(rerunfilecheck)             Checksum: 2FBBC15B2FCE2780E565228D6D7F96A9;58.
 ) 
Here is how much of TeX's memory you used:
 7625 strings out of 474403
 118281 string characters out of 5754430
 1924036 words of memory out of 5000000
 29659 multiletter control sequences out of 15000+600000
 559328 words of font info for 40 fonts, out of 8000000 for 9000
 1141 hyphenation exceptions out of 8191
 75i,5n,79p,542b,432s stack positions out of 10000i,1000n,20000p,200000b,200000s

pdfTeX warning (dest): name{theorem.1} has been referenced but does not exist, 
replaced by a fixed one

<c:/texlive/2023/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx10.pfb><c:/texli
ve/2023/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx12.pfb><c:/texlive/2023/t
exmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb><c:/texlive/2023/texmf-dist/
fonts/type1/public/amsfonts/cm/cmti10.pfb>
Output written on test1.pdf (1 page, 38036 bytes).
PDF statistics:
 41 PDF objects out of 1000 (max. 8388607)
 29 compressed objects within 1 object stream
 4 named destinations out of 1000 (max. 500000)
 9 words of extra memory for PDF output out of 10000 (max. 10000000)
@kozyakin
Copy link

Apparently, the appearance of warnings like "pdfTeX warning (dest):" or "pdfTeX warning (ext4):" that appeared (as in my case) in abundance in hyperref v7.01c is caused by the following code fragment implemented in version 7.01c

\AddToHookNext{cmd/item/before}
  {\AddToHookNext{para/begin}
    {\let\Hy@tempa\@currentHref
     \MakeLinkTarget*{\Hy@dth@currentHref}%
     \global\let\@currentHref\Hy@tempa
    }%
  }%

in the command definition \newcommand\Hy@theorem@refstepcounter[1].

This fragment differs from the corresponding fragment in version 7.01b by the presence of the hook \AddToHookNext{cmd/item/before}.

A temporary fix for this situation until a fixed version of hyperref becomes available is this:

  1. put a copy of hyperref.sty in the directory of your tex-file and comment out the line \AddToHookNext{cmd/item/before} in it

or

  1. place the following code behind \usepackage[...]{hyperref} in your tex-file

\makeatletter
\renewcommand\Hy@theorem@refstepcounter[1]
{%
\H@refstepcounter{#1}%
\hyper@makecurrent{#1}%
\global\let\Hy@dth@currentHref@currentHref
\AddToHookNext{para/begin}
{\let\Hy@tempa@currentHref
\MakeLinkTarget*{\Hy@dth@currentHref}%
\global\let@currentHref\Hy@tempa
}%
}
\makeatother

In both cases, compilation will proceed without additional warnings like pdfTeX warning (dest): or pdfTeX warning (ext4):

@u-fischer
Copy link
Member

Sorry for the delay, I was a bit busy. I just sent a new version to ctan which should reinstate the old behaviour if amsthm is used.

But generally a better solution for targets in theorems is needed. Depending on which package(s) are used you loose the targets or they are on the wrong page or they affect spacing and if one repairs one case it breaks something else. I will try to convince the various players here to support hyperref directly so that hyperref can stop to patch around.

@mbertucci47
Copy link
Contributor Author

Thanks!

@ivanovakur
Copy link

7.01d still produces a warning

pdfTeX warning (ext4): destination with the same identifier (name{thmx.2}) has 
been already used, duplicate ignored
<argument> ...shipout:D \box_use:N \l_shipout_box 
                                                  \__shipout_drop_firstpage_...

when a theorem contains enumerate in amsart. Here is a minimal example:

\documentclass{amsart}
\usepackage{hyperref}

\newtheorem{thmx}{Theorem}

\begin{document}

\begin{thmx}
   a
\end{thmx}

\begin{thmx}
aaa
    \begin{enumerate}
        \item bb
        \item cc
    \end{enumerate}   
\end{thmx}

\end{document}

@mbertucci47 mbertucci47 reopened this Nov 2, 2023
@kozyakin
Copy link

kozyakin commented Nov 2, 2023

Confirm @ivanovakur .

My recepy with commenting the line \AddToHookNext{cmd/item/before} in the copy of hyperref.sty still recovered the warning in this case (for version 7.01d), too

@mbertucci47
Copy link
Contributor Author

@ivanovakur I see, the patch added in d3b8d4a only applies to amsthm. If you add the same patch to the preamble for amsart (or any other ams class), it works.

\makeatletter
\AddToHook{class/amsart/after}
 {
  \renewcommand\Hy@theorem@refstepcounter[1]
   {%
    \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
       }%
     }%  
   }
 }
\makeatother

@u-fischer Would it be better to change \Hy@theorem@refstepcounter whenever \deferred@thm@head is defined? It doesn't seem the kernel \newtheorem or ntheorem defines \deferred@thm@head.

@ivanovakur
Copy link

@kozyakin Thanks, that fixed the "duplicate" warning. Now I see the "does not exist" warning when using \marginpar in theorems, which I probably missed before.

pdfTeX warning (dest): name{thmx.1} has been referenced but does not exist, rep
laced by a fixed one

MWE is below, same warning with and without your \AddToHook.

\documentclass{amsart}
\usepackage{hyperref}

\newtheorem{thmx}{Theorem}

\begin{document}

\begin{thmx}\label{t:a}
\marginpar[ aaa ]{ aaa }
   a
\end{thmx}

By \ref{t:a} 

\end{document}

@kozyakin
Copy link

kozyakin commented Nov 7, 2023

Dear @ivanovakur

I noticed a long ago that warnings like

pdfTeX warning (dest): name{thmx.1} has been referenced but does not exist, replaced by a fixed one

very often can be “cured” by adding the following command to the preamble of the tex file

\AddToHook{cmd/label/before}{\phantomsection}

In your case, it also works: the following tex-code

\documentclass{amsart}
\usepackage{hyperref}

\newtheorem{thmx}{Theorem}

\AddToHook{cmd/label/before}{\phantomsection}

\begin{document}

\begin{thmx}\label{t:a}
\marginpar[ aaa ]{ aaa }
    a
\end{thmx}

By\ref{t:a}

\end{document}

in my system was compiled without warning pdfTeX warning (dest): name{thmx.1} has been referenced but does not exist, replaced by a fixed one

@kozyakin
Copy link

kozyakin commented Nov 7, 2023

By the way, the hook \AddToHook{cmd/label/before}{\phantomsection} often recoveres other problematic situations with hyperref, e.g. when \pageref points to wrong page

u-fischer added a commit that referenced this issue Nov 7, 2023
@ivanovakur
Copy link

@kozyakin Thanks, \phantomsection cures that warning in my real document as well.

@mbertucci47 @kozyakin I messed up the attribution of the fix in my previous message, sorry. Just to avoid confusion, what I meant is that the fix by @mbertucci47

\makeatletter
\AddToHook{class/amsart/after}
 {
  \renewcommand\Hy@theorem@refstepcounter[1]
   {%
    \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
       }%
     }%  
   }
 }
\makeatother

fixes "duplicate" warning.

@u-fischer
Copy link
Member

@kozyakin @ivanovakur if you plant \phantomsection everywhere you break autoref. And you get also wrong target location. Here the first link will jump below the chapter title.

\documentclass{book}
\usepackage{hyperref}
\begin{document}
\chapter{The Pythagoras Theorem} 
\phantomsection\label{sec:pythagoras} 

\autoref{sec:pythagoras} 


\chapter{The Euclid Theorem} 
\label{sec:euclid} 

\autoref{sec:euclid} 

\end{document}

Apart from this, I guess you now realize how complicated it is to properly support theorems. And do not believe that it worked previously properly. E.g. it could happen (and still can happen if you use cleveref) that the target is on the page before the actual theorem. And in other cases targets were lost. I will sent a new version to ctan which will support also the ams-classes. But generally it would be better if the classes would support that natively, so write their maintainer too.

@kozyakin
Copy link

kozyakin commented Nov 7, 2023

@u-fischer I absolutely argee with you that putting \phantomsection before every \label is not the best idea. My advice was just for immediate closing the @ivanovakur problem. Will eagerly wait for your new submission.

@u-fischer
Copy link
Member

This should be resolved in version 7.01f (but I take no bets that all theorem variants behave).

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

No branches or pull requests

4 participants