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

hyperref and xcolor together lead to a failure with \fbox in \chapter. #207

Closed
pertusus opened this issue Sep 15, 2021 · 2 comments
Closed

Comments

@pertusus
Copy link

hyperref and xcolor together lead to a failure with \fbox in \chapter.

If \usepackage{xcolor} is before \usepackage{hyperref}, error is
! Argument of \boxframe has an extra }.

If \usepackage{hyperref} is before \usepackage{xcolor}, error is
! Undefined control sequence.
<

Either
\robustify\fbox
(with \usepackage{etoolbox})
or
\pdfstringdefDisableCommands{\let\fbox\relax}
make the failure disappear.

An example is attached (as .txt as the issues submitting is too dumb for .tex)

xcolor_hyperref.txt

@u-fischer
Copy link
Member

hyperref tries quite hard to convert the content of heading commands into something sensible for the bookmarks.

But it neither does nor can handle every command which can appear in this context. Various commands will fail with an error like your fbox, some will give unsuitable output.

Actually even without xcolor your fbox doesn't really work:

\documentclass{report}
\usepackage{hyperref}
\begin{document}
\chapter{\fbox{fbox}}
\end{document}

gives

image

Hyperref could add code to avoid the problem, but in my opinion using an \fbox that also wanders into the toc (and so into the bookmark) in a heading is such an unusual case that it doesn't make sense to slow down compilation for everyone to catch this.

Perhaps future development will catch this case automatically, but for now,
if you want to use \fbox (or other boxes) in a heading, I suggest to either use the optional argument:

\chapter[text for toc/header]{\fbox{fbox}}

or \texorpdfstring:

\chapter{\texorpdfstring{\fbox{fbox}}{}}

or to use one of the options you already mentioned in your example. e.g. \pdfstringdefDisableCommands. There you can also adjust the outcome in the bookmarks to your liking:

\documentclass{report}
\usepackage{xcolor}
\usepackage{hyperref}

\pdfstringdefDisableCommands{%
\def\fbox#1{[#1]}%
\def\colorbox#1#2{#2}%
\def\fcolorbox#1#2#3{[#3]}%
}

\begin{document}
\chapter{\fbox{abc}}
\chapter{\colorbox{red}{abc}}
\chapter{\fcolorbox{red}{green}{abc}}
\end{document}

@pertusus
Copy link
Author

pertusus commented Feb 21, 2022 via email

joelsgp pushed a commit to gnu-mirror-unofficial/texinfo that referenced this issue Feb 23, 2022
in heading formatting.  In heading formating, use 'error'
as a string instead of a \fbox for @error formatting in
contents bookmark string using \texorpdfstring{}.
Based on Ulrike Fischer suggestion:
latex3/hyperref#207 (comment)
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

2 participants