[latex3-commits] [latex3/latex2e] lab-review-01: correct targets with natbib (c9f97f11)
github at latex-project.org
github at latex-project.org
Wed Jun 7 12:19:03 CEST 2023
Repository : https://github.com/latex3/latex2e
On branch : lab-review-01
Link : https://github.com/latex3/latex2e/commit/c9f97f1117ec8b536822f28338c3369d1a42a2c0
>---------------------------------------------------------------
commit c9f97f1117ec8b536822f28338c3369d1a42a2c0
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date: Wed Jun 7 12:19:03 2023 +0200
correct targets with natbib
>---------------------------------------------------------------
c9f97f1117ec8b536822f28338c3369d1a42a2c0
required/latex-lab/latex-lab-bib.dtx | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/required/latex-lab/latex-lab-bib.dtx b/required/latex-lab/latex-lab-bib.dtx
index d9128d58..ac36f947 100644
--- a/required/latex-lab/latex-lab-bib.dtx
+++ b/required/latex-lab/latex-lab-bib.dtx
@@ -171,9 +171,13 @@
% we store the target name for the label.
% \begin{macrocode}
\tl_set:Nn\l_@@_bib_citekey_tl{#2}
+ }
% \end{macrocode}
-% The target is added at the begin of the paragraph.
+% The target is added at the begin of the paragraph. We give that a label as
+% it perhaps need to be removed by packages
% \begin{macrocode}
+\AddToHookWithArguments{cmd/@lbibitem/before}[latex-lab-testphase-bib/target]
+ {
\AddToHookNext{para/begin}
{
\makebox[0pt][r]{\MakeLinkTarget*{cite.#2\@extra at b@citeb}\hspace{\leftmargin}}
@@ -198,9 +202,14 @@
% we store the target name for the label.
% \begin{macrocode}
\tl_set:Nn\l_@@_bib_citekey_tl{#1}
+ }
% \end{macrocode}
-% The target is added at the begin of the paragraph.
+%
+% The target is added at the begin of the paragraph. We give that a label as
+% it perhaps need to be removed by packages
% \begin{macrocode}
+\AddToHookWithArguments{cmd/@bibitem/before}[latex-lab-testphase-bib/target]
+ {
\AddToHookNext{para/begin}
{
\makebox[0pt][r]{\MakeLinkTarget*{cite.#1\@extra at b@citeb}\hspace{\leftmargin}}
@@ -290,6 +299,16 @@
\newcommand\hyper at natlinkstart[1]{}
\newcommand\hyper at natlinkend{}
% \end{macrocode}
+% With natbib we need to change the hooks to avoid duplicated target as it sets
+% the anchor too. We can not simply empty \cs{hyper at natanchorstart} as that is
+% used by biblatex.
+% \begin{macrocode}
+\AddToHook{package/natbib/after}
+ {
+ \RemoveFromHook{cmd/@bibitem/before} [latex-lab-testphase-bib/target]
+ \RemoveFromHook{cmd/@lbibitem/before}[latex-lab-testphase-bib/target]
+ }
+% \end{macrocode}
% This can be shared by both packages: it will work with natbib with and without hyperref.
% With biblatex it will work without hyperref as long as \cs{@extra at b@citeb} is empty
% \begin{macrocode}
More information about the latex3-commits
mailing list.