Closed Maelan closed 2 years ago
Your redefinition of \th is wrong. This is a command that depends on the font encoding and it should be redefined with the suitable tools. E.g.
\documentclass{article}
\usepackage[T1]{fontenc}
\DeclareTextCommand{\th}{T1}{don't redefine this}
\usepackage{hyperref}
%\DeclareTextCommand{\th}{PU}{th in the bookmarks} %definition of \th in the bookmarks
\begin{document}
\section{\th}
\th
\end{document}
In case you want to use \th for something font independent, you will have to do the redefinition later. And please use \renewcommand to make clear that you are redefining an existing LaTeX command.
I don’t get the explanation that it “depends on the font encoding” (isn’t it just inserting two ASCII letters? the \textrm
bit was just an example of course), but at least I learned that \DeclareTextCommand{\th}{T1}{...}
defines the command just as well and is apparently not overridden by hyperref as far as I’m concerned. So, good enough I guess?
it means that every font encoding can have its own independant definition of such a command. T1-encoding setups \th, and hyperref sets it up for PU encoding. Generally it is not a good idea to overwrite such commands with something completly different. Internal code can depend on \th meaning the th-glyph.
I see, thanks and sorry for the trouble.
hyperref apparently defines or overrides commands such as
\OE
,\oe
,\TH
,\th
,\DH
,\dh
, and I guess many other. I think it is an unexpected side effect and that hyperref shouldn’t do it, because (unless I’m mistaken) it sounds independent of its purpose. It’s especially annoying given that hyperref is supposed to be loaded last.Minimal example:
The definition of
\th
that gets picked in this document is seemingly the initial (La?)TeX definition (i.e. this example produces a þ (the Icelandic letter “thorn”) in text mode and whatever in math mode). Of course, redefining\th
after loading hyperref gives the intended behavior of using our custom definition.Perhaps there is a technical reason for that (for getting the right Unicode character in the PDF?), but if it’s still needed as of 2022, could hyperref at least allow to disable the overriding selectively? Something resembling: