tcolorbox: Potential bug with duplicate label for hyperref link
I noticed that a 'tcolorbox' with auto counter including the section number causes a warning in the log file and the respective hyperref links point only to the first occurence.
MWE:
documentclass{scrartcl}
usepackage{tcolorbox}
newtcolorbox[auto counter,number within=section]{mybox}[1]{title=MyBox~thetcbcounter,#1}
usepackage{hyperref}
begin{document}
Mybox~ref{mybox1}; Mybox~ref{mybox2}
clearpage
section{Section}
begin{mybox}[label=mybox1]
The counter name is texttt{tcbcounter}.
end{mybox}
clearpage
section{Section}
begin{mybox}[label=mybox2]
The counter name is texttt{tcbcounter}.
end{mybox}
end{document}
The warning in the log file reads
warning (pdf backend): ignoring duplicate destination with the name 'tcb@cnt@mybox.1'
So somehow the 'tcbcounter' is properly reset for the second section, but the internal counter 'tcb@cnt@mybox' does not contain the section number, so that the reference link to the second box points to the first.
Is this known or maybe a bug? Or can I, as the user, fix this easily? Thanks!
hyperref tcolorbox
add a comment |
I noticed that a 'tcolorbox' with auto counter including the section number causes a warning in the log file and the respective hyperref links point only to the first occurence.
MWE:
documentclass{scrartcl}
usepackage{tcolorbox}
newtcolorbox[auto counter,number within=section]{mybox}[1]{title=MyBox~thetcbcounter,#1}
usepackage{hyperref}
begin{document}
Mybox~ref{mybox1}; Mybox~ref{mybox2}
clearpage
section{Section}
begin{mybox}[label=mybox1]
The counter name is texttt{tcbcounter}.
end{mybox}
clearpage
section{Section}
begin{mybox}[label=mybox2]
The counter name is texttt{tcbcounter}.
end{mybox}
end{document}
The warning in the log file reads
warning (pdf backend): ignoring duplicate destination with the name 'tcb@cnt@mybox.1'
So somehow the 'tcbcounter' is properly reset for the second section, but the internal counter 'tcb@cnt@mybox' does not contain the section number, so that the reference link to the second box points to the first.
Is this known or maybe a bug? Or can I, as the user, fix this easily? Thanks!
hyperref tcolorbox
add a comment |
I noticed that a 'tcolorbox' with auto counter including the section number causes a warning in the log file and the respective hyperref links point only to the first occurence.
MWE:
documentclass{scrartcl}
usepackage{tcolorbox}
newtcolorbox[auto counter,number within=section]{mybox}[1]{title=MyBox~thetcbcounter,#1}
usepackage{hyperref}
begin{document}
Mybox~ref{mybox1}; Mybox~ref{mybox2}
clearpage
section{Section}
begin{mybox}[label=mybox1]
The counter name is texttt{tcbcounter}.
end{mybox}
clearpage
section{Section}
begin{mybox}[label=mybox2]
The counter name is texttt{tcbcounter}.
end{mybox}
end{document}
The warning in the log file reads
warning (pdf backend): ignoring duplicate destination with the name 'tcb@cnt@mybox.1'
So somehow the 'tcbcounter' is properly reset for the second section, but the internal counter 'tcb@cnt@mybox' does not contain the section number, so that the reference link to the second box points to the first.
Is this known or maybe a bug? Or can I, as the user, fix this easily? Thanks!
hyperref tcolorbox
I noticed that a 'tcolorbox' with auto counter including the section number causes a warning in the log file and the respective hyperref links point only to the first occurence.
MWE:
documentclass{scrartcl}
usepackage{tcolorbox}
newtcolorbox[auto counter,number within=section]{mybox}[1]{title=MyBox~thetcbcounter,#1}
usepackage{hyperref}
begin{document}
Mybox~ref{mybox1}; Mybox~ref{mybox2}
clearpage
section{Section}
begin{mybox}[label=mybox1]
The counter name is texttt{tcbcounter}.
end{mybox}
clearpage
section{Section}
begin{mybox}[label=mybox2]
The counter name is texttt{tcbcounter}.
end{mybox}
end{document}
The warning in the log file reads
warning (pdf backend): ignoring duplicate destination with the name 'tcb@cnt@mybox.1'
So somehow the 'tcbcounter' is properly reset for the second section, but the internal counter 'tcb@cnt@mybox' does not contain the section number, so that the reference link to the second box points to the first.
Is this known or maybe a bug? Or can I, as the user, fix this easily? Thanks!
hyperref tcolorbox
hyperref tcolorbox
edited Apr 17 at 10:42
FlorianL
asked Apr 17 at 9:06
FlorianLFlorianL
7961513
7961513
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
hyperref
has a built-in mechanism for this. If for a counter the command theH<counter>
is defined, then it is used for internal anchor names instead of the<counter>
.
documentclass{scrartcl}
usepackage{tcolorbox}
usepackage{hyperref}
newtcolorbox[auto counter,number within=section]{mybox}[1]{%
title=MyBox~thetcbcounter,
#1
}
providecommand{theHtcbcounter}{thesection.arabic{tcbcounter}}
begin{document}
Mybox~ref{mybox1}; Mybox~ref{mybox2}
clearpage
section{Section}
begin{mybox}[label=mybox1]
The counter name is texttt{tcbcounter}.
end{mybox}
clearpage
section{Section}
begin{mybox}[label=mybox2]
The counter name is texttt{tcbcounter}.
end{mybox}
end{document}
This way the two links will have distinct anchor names and all is well.
If you want this to work with later loading of hyperref
, you have to plunge in the internals:
makeatletter
providecommandtheHtcb@cnt@mybox{thesection.arabic{tcb@cnt@mybox}}
makeatother
because tcolorbox
associates that counter to the color box.
This seems to require loadinghyperref
before the definition(s) oftcolorbox
s. So I would need to loadhyperref
pretty early on in my classes/packages. On the other hand, I read one should loadhyperref
at the end of the preamble. So what would you recommend?
– FlorianL
Apr 17 at 10:40
1
@FlorianL Delay the definitions of the boxes at begin document. The “fault” is intcolorbox
that doesn't actually donewcounter{tcbcounter}
.
– egreg
Apr 17 at 10:53
@FlorianL I added the workaround
– egreg
Apr 17 at 10:59
After playing around a bit, I think delaying the definitions of the boxes withAtBeginDocument
is what matters. The MWE works with loadinghyperref
before the box definition, even without theprovidecommand
. Could you point this out in your answer such that I can mark it as such?
– FlorianL
Apr 17 at 11:15
add a comment |
Based on @egreg's answer, it seems that one only needs to define new tcolorbox
es after loading package hyperref
. If both should be done from inside a custom package or a more complicated preamble structure, the AtEndPreamble
and AtBeginDocument
from the etoolbox
package can be used.
Loading package auxhook
early prevents an error message when using a koma-scrip
class (see etoolbox + koma-script: Warning 'seems someone has broken package auxhook').
So a functional MWE would be:
documentclass{scrartcl}
usepackage{tcolorbox}
usepackage{etoolbox, auxhook}
AtEndPreamble{
usepackage{hyperref}
}
AtBeginDocument{
newtcolorbox[auto counter,number within=section]{mybox}[1]{%
title=MyBox~thetcbcounter,#1}
}
begin{document}
Mybox~ref{mybox1}; Mybox~ref{mybox2}
clearpage
section{Section}
begin{mybox}[label=mybox1]
The counter name is texttt{tcbcounter}.
end{mybox}
clearpage
section{Section}
begin{mybox}[label=mybox2]
The counter name is texttt{tcbcounter}.
end{mybox}
end{document}
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f485251%2ftcolorbox-potential-bug-with-duplicate-label-for-hyperref-link%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
hyperref
has a built-in mechanism for this. If for a counter the command theH<counter>
is defined, then it is used for internal anchor names instead of the<counter>
.
documentclass{scrartcl}
usepackage{tcolorbox}
usepackage{hyperref}
newtcolorbox[auto counter,number within=section]{mybox}[1]{%
title=MyBox~thetcbcounter,
#1
}
providecommand{theHtcbcounter}{thesection.arabic{tcbcounter}}
begin{document}
Mybox~ref{mybox1}; Mybox~ref{mybox2}
clearpage
section{Section}
begin{mybox}[label=mybox1]
The counter name is texttt{tcbcounter}.
end{mybox}
clearpage
section{Section}
begin{mybox}[label=mybox2]
The counter name is texttt{tcbcounter}.
end{mybox}
end{document}
This way the two links will have distinct anchor names and all is well.
If you want this to work with later loading of hyperref
, you have to plunge in the internals:
makeatletter
providecommandtheHtcb@cnt@mybox{thesection.arabic{tcb@cnt@mybox}}
makeatother
because tcolorbox
associates that counter to the color box.
This seems to require loadinghyperref
before the definition(s) oftcolorbox
s. So I would need to loadhyperref
pretty early on in my classes/packages. On the other hand, I read one should loadhyperref
at the end of the preamble. So what would you recommend?
– FlorianL
Apr 17 at 10:40
1
@FlorianL Delay the definitions of the boxes at begin document. The “fault” is intcolorbox
that doesn't actually donewcounter{tcbcounter}
.
– egreg
Apr 17 at 10:53
@FlorianL I added the workaround
– egreg
Apr 17 at 10:59
After playing around a bit, I think delaying the definitions of the boxes withAtBeginDocument
is what matters. The MWE works with loadinghyperref
before the box definition, even without theprovidecommand
. Could you point this out in your answer such that I can mark it as such?
– FlorianL
Apr 17 at 11:15
add a comment |
hyperref
has a built-in mechanism for this. If for a counter the command theH<counter>
is defined, then it is used for internal anchor names instead of the<counter>
.
documentclass{scrartcl}
usepackage{tcolorbox}
usepackage{hyperref}
newtcolorbox[auto counter,number within=section]{mybox}[1]{%
title=MyBox~thetcbcounter,
#1
}
providecommand{theHtcbcounter}{thesection.arabic{tcbcounter}}
begin{document}
Mybox~ref{mybox1}; Mybox~ref{mybox2}
clearpage
section{Section}
begin{mybox}[label=mybox1]
The counter name is texttt{tcbcounter}.
end{mybox}
clearpage
section{Section}
begin{mybox}[label=mybox2]
The counter name is texttt{tcbcounter}.
end{mybox}
end{document}
This way the two links will have distinct anchor names and all is well.
If you want this to work with later loading of hyperref
, you have to plunge in the internals:
makeatletter
providecommandtheHtcb@cnt@mybox{thesection.arabic{tcb@cnt@mybox}}
makeatother
because tcolorbox
associates that counter to the color box.
This seems to require loadinghyperref
before the definition(s) oftcolorbox
s. So I would need to loadhyperref
pretty early on in my classes/packages. On the other hand, I read one should loadhyperref
at the end of the preamble. So what would you recommend?
– FlorianL
Apr 17 at 10:40
1
@FlorianL Delay the definitions of the boxes at begin document. The “fault” is intcolorbox
that doesn't actually donewcounter{tcbcounter}
.
– egreg
Apr 17 at 10:53
@FlorianL I added the workaround
– egreg
Apr 17 at 10:59
After playing around a bit, I think delaying the definitions of the boxes withAtBeginDocument
is what matters. The MWE works with loadinghyperref
before the box definition, even without theprovidecommand
. Could you point this out in your answer such that I can mark it as such?
– FlorianL
Apr 17 at 11:15
add a comment |
hyperref
has a built-in mechanism for this. If for a counter the command theH<counter>
is defined, then it is used for internal anchor names instead of the<counter>
.
documentclass{scrartcl}
usepackage{tcolorbox}
usepackage{hyperref}
newtcolorbox[auto counter,number within=section]{mybox}[1]{%
title=MyBox~thetcbcounter,
#1
}
providecommand{theHtcbcounter}{thesection.arabic{tcbcounter}}
begin{document}
Mybox~ref{mybox1}; Mybox~ref{mybox2}
clearpage
section{Section}
begin{mybox}[label=mybox1]
The counter name is texttt{tcbcounter}.
end{mybox}
clearpage
section{Section}
begin{mybox}[label=mybox2]
The counter name is texttt{tcbcounter}.
end{mybox}
end{document}
This way the two links will have distinct anchor names and all is well.
If you want this to work with later loading of hyperref
, you have to plunge in the internals:
makeatletter
providecommandtheHtcb@cnt@mybox{thesection.arabic{tcb@cnt@mybox}}
makeatother
because tcolorbox
associates that counter to the color box.
hyperref
has a built-in mechanism for this. If for a counter the command theH<counter>
is defined, then it is used for internal anchor names instead of the<counter>
.
documentclass{scrartcl}
usepackage{tcolorbox}
usepackage{hyperref}
newtcolorbox[auto counter,number within=section]{mybox}[1]{%
title=MyBox~thetcbcounter,
#1
}
providecommand{theHtcbcounter}{thesection.arabic{tcbcounter}}
begin{document}
Mybox~ref{mybox1}; Mybox~ref{mybox2}
clearpage
section{Section}
begin{mybox}[label=mybox1]
The counter name is texttt{tcbcounter}.
end{mybox}
clearpage
section{Section}
begin{mybox}[label=mybox2]
The counter name is texttt{tcbcounter}.
end{mybox}
end{document}
This way the two links will have distinct anchor names and all is well.
If you want this to work with later loading of hyperref
, you have to plunge in the internals:
makeatletter
providecommandtheHtcb@cnt@mybox{thesection.arabic{tcb@cnt@mybox}}
makeatother
because tcolorbox
associates that counter to the color box.
edited Apr 17 at 10:59
answered Apr 17 at 9:12
egregegreg
736k8919353261
736k8919353261
This seems to require loadinghyperref
before the definition(s) oftcolorbox
s. So I would need to loadhyperref
pretty early on in my classes/packages. On the other hand, I read one should loadhyperref
at the end of the preamble. So what would you recommend?
– FlorianL
Apr 17 at 10:40
1
@FlorianL Delay the definitions of the boxes at begin document. The “fault” is intcolorbox
that doesn't actually donewcounter{tcbcounter}
.
– egreg
Apr 17 at 10:53
@FlorianL I added the workaround
– egreg
Apr 17 at 10:59
After playing around a bit, I think delaying the definitions of the boxes withAtBeginDocument
is what matters. The MWE works with loadinghyperref
before the box definition, even without theprovidecommand
. Could you point this out in your answer such that I can mark it as such?
– FlorianL
Apr 17 at 11:15
add a comment |
This seems to require loadinghyperref
before the definition(s) oftcolorbox
s. So I would need to loadhyperref
pretty early on in my classes/packages. On the other hand, I read one should loadhyperref
at the end of the preamble. So what would you recommend?
– FlorianL
Apr 17 at 10:40
1
@FlorianL Delay the definitions of the boxes at begin document. The “fault” is intcolorbox
that doesn't actually donewcounter{tcbcounter}
.
– egreg
Apr 17 at 10:53
@FlorianL I added the workaround
– egreg
Apr 17 at 10:59
After playing around a bit, I think delaying the definitions of the boxes withAtBeginDocument
is what matters. The MWE works with loadinghyperref
before the box definition, even without theprovidecommand
. Could you point this out in your answer such that I can mark it as such?
– FlorianL
Apr 17 at 11:15
This seems to require loading
hyperref
before the definition(s) of tcolorbox
s. So I would need to load hyperref
pretty early on in my classes/packages. On the other hand, I read one should load hyperref
at the end of the preamble. So what would you recommend?– FlorianL
Apr 17 at 10:40
This seems to require loading
hyperref
before the definition(s) of tcolorbox
s. So I would need to load hyperref
pretty early on in my classes/packages. On the other hand, I read one should load hyperref
at the end of the preamble. So what would you recommend?– FlorianL
Apr 17 at 10:40
1
1
@FlorianL Delay the definitions of the boxes at begin document. The “fault” is in
tcolorbox
that doesn't actually do newcounter{tcbcounter}
.– egreg
Apr 17 at 10:53
@FlorianL Delay the definitions of the boxes at begin document. The “fault” is in
tcolorbox
that doesn't actually do newcounter{tcbcounter}
.– egreg
Apr 17 at 10:53
@FlorianL I added the workaround
– egreg
Apr 17 at 10:59
@FlorianL I added the workaround
– egreg
Apr 17 at 10:59
After playing around a bit, I think delaying the definitions of the boxes with
AtBeginDocument
is what matters. The MWE works with loading hyperref
before the box definition, even without the providecommand
. Could you point this out in your answer such that I can mark it as such?– FlorianL
Apr 17 at 11:15
After playing around a bit, I think delaying the definitions of the boxes with
AtBeginDocument
is what matters. The MWE works with loading hyperref
before the box definition, even without the providecommand
. Could you point this out in your answer such that I can mark it as such?– FlorianL
Apr 17 at 11:15
add a comment |
Based on @egreg's answer, it seems that one only needs to define new tcolorbox
es after loading package hyperref
. If both should be done from inside a custom package or a more complicated preamble structure, the AtEndPreamble
and AtBeginDocument
from the etoolbox
package can be used.
Loading package auxhook
early prevents an error message when using a koma-scrip
class (see etoolbox + koma-script: Warning 'seems someone has broken package auxhook').
So a functional MWE would be:
documentclass{scrartcl}
usepackage{tcolorbox}
usepackage{etoolbox, auxhook}
AtEndPreamble{
usepackage{hyperref}
}
AtBeginDocument{
newtcolorbox[auto counter,number within=section]{mybox}[1]{%
title=MyBox~thetcbcounter,#1}
}
begin{document}
Mybox~ref{mybox1}; Mybox~ref{mybox2}
clearpage
section{Section}
begin{mybox}[label=mybox1]
The counter name is texttt{tcbcounter}.
end{mybox}
clearpage
section{Section}
begin{mybox}[label=mybox2]
The counter name is texttt{tcbcounter}.
end{mybox}
end{document}
add a comment |
Based on @egreg's answer, it seems that one only needs to define new tcolorbox
es after loading package hyperref
. If both should be done from inside a custom package or a more complicated preamble structure, the AtEndPreamble
and AtBeginDocument
from the etoolbox
package can be used.
Loading package auxhook
early prevents an error message when using a koma-scrip
class (see etoolbox + koma-script: Warning 'seems someone has broken package auxhook').
So a functional MWE would be:
documentclass{scrartcl}
usepackage{tcolorbox}
usepackage{etoolbox, auxhook}
AtEndPreamble{
usepackage{hyperref}
}
AtBeginDocument{
newtcolorbox[auto counter,number within=section]{mybox}[1]{%
title=MyBox~thetcbcounter,#1}
}
begin{document}
Mybox~ref{mybox1}; Mybox~ref{mybox2}
clearpage
section{Section}
begin{mybox}[label=mybox1]
The counter name is texttt{tcbcounter}.
end{mybox}
clearpage
section{Section}
begin{mybox}[label=mybox2]
The counter name is texttt{tcbcounter}.
end{mybox}
end{document}
add a comment |
Based on @egreg's answer, it seems that one only needs to define new tcolorbox
es after loading package hyperref
. If both should be done from inside a custom package or a more complicated preamble structure, the AtEndPreamble
and AtBeginDocument
from the etoolbox
package can be used.
Loading package auxhook
early prevents an error message when using a koma-scrip
class (see etoolbox + koma-script: Warning 'seems someone has broken package auxhook').
So a functional MWE would be:
documentclass{scrartcl}
usepackage{tcolorbox}
usepackage{etoolbox, auxhook}
AtEndPreamble{
usepackage{hyperref}
}
AtBeginDocument{
newtcolorbox[auto counter,number within=section]{mybox}[1]{%
title=MyBox~thetcbcounter,#1}
}
begin{document}
Mybox~ref{mybox1}; Mybox~ref{mybox2}
clearpage
section{Section}
begin{mybox}[label=mybox1]
The counter name is texttt{tcbcounter}.
end{mybox}
clearpage
section{Section}
begin{mybox}[label=mybox2]
The counter name is texttt{tcbcounter}.
end{mybox}
end{document}
Based on @egreg's answer, it seems that one only needs to define new tcolorbox
es after loading package hyperref
. If both should be done from inside a custom package or a more complicated preamble structure, the AtEndPreamble
and AtBeginDocument
from the etoolbox
package can be used.
Loading package auxhook
early prevents an error message when using a koma-scrip
class (see etoolbox + koma-script: Warning 'seems someone has broken package auxhook').
So a functional MWE would be:
documentclass{scrartcl}
usepackage{tcolorbox}
usepackage{etoolbox, auxhook}
AtEndPreamble{
usepackage{hyperref}
}
AtBeginDocument{
newtcolorbox[auto counter,number within=section]{mybox}[1]{%
title=MyBox~thetcbcounter,#1}
}
begin{document}
Mybox~ref{mybox1}; Mybox~ref{mybox2}
clearpage
section{Section}
begin{mybox}[label=mybox1]
The counter name is texttt{tcbcounter}.
end{mybox}
clearpage
section{Section}
begin{mybox}[label=mybox2]
The counter name is texttt{tcbcounter}.
end{mybox}
end{document}
answered Apr 17 at 14:19
FlorianLFlorianL
7961513
7961513
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f485251%2ftcolorbox-potential-bug-with-duplicate-label-for-hyperref-link%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown