2

As addressed in Temporarily change font encoding with fontenc, I need to switch to T1 encoding to get certain T1 glyphs. This compiles fine with hyperref:

\documentclass{article}
\usepackage[T1, OT1]{fontenc}
\usepackage{hyperref}
\begin{document}
Har{\fontencoding{T1}\selectfont{\dh}}arson
\end{document}

As addressed in \renewcommand and \newcommand for accented letters, I'm redefining some T1 macros in my preamble. In this case, however, hyperref seems to insist that the encoding is still in OT1 (it compiles fine without hyperref).

\documentclass{article}
\usepackage[T1, OT1]{fontenc}
\renewcommand{\dh}{\fontencoding{T1}\selectfont{\symbol{240}}}
\usepackage{hyperref}
\begin{document}
Har{\dh}arson
\end{document}

LaTeX Error: Command \dh unavailable in encoding OT1.

What is going on here ... ?


EDIT:

It turns out that it works fine if the macro is redefined after hyperref is loaded:

\documentclass{article}
\usepackage[T1, OT1]{fontenc}
\usepackage{hyperref}
\renewcommand{\dh}{\fontencoding{T1}\selectfont{\symbol{240}}}
\begin{document}
Har{\dh}arson
\end{document}

So this now begs the question why hyperref causes this behavior.

Sverre
  • 20,729

1 Answers1

5

hyperref loads pd1enc.def which set up the encodings for the bookmarks and overwrite your definition. Moving the definition behind hyperref will avoid the error but you will not be able to use the command e.g. in bookmarks.

LaTeX is trying hard to set up such definitions in a way that works with various encodings. You should not destroy this system by redefining LICR-commands in this way. Use the correct commands.

\documentclass{article}
\usepackage[T1, OT1]{fontenc}
\DeclareTextSymbolDefault{\dh}{T1}
\usepackage{hyperref}
\begin{document}
\section{Har{\dh}arson } %to test bookmarks
Har{\dh}arson 
\end{document}
Ulrike Fischer
  • 327,261
  • Great - didn't know about \DeclareTextSymbolDefault! :) – Sverre Sep 06 '13 at 11:43
  • I can't do that with macros that already exist in OT1, apparently, like \DeclareTextSymbolDefault{\aa}{T1}. Then I get a TeX capacity exceeded, sorry [grouping levels=255]. error. – Sverre Sep 06 '13 at 11:52
  • 2
    @Sverre \aa is not an "encoding dependent" command; it just expands to \r{a} and it's \r to be encoding dependent. – egreg Sep 06 '13 at 12:16
  • 1
    @egreg Would this then be the "correct command": \DeclareTextCompositeCommand{\r}{OT1}{a}{{\fontencoding{T1}\selectfont\aa}}? – Sverre Sep 06 '13 at 12:20
  • 1
    @Sverre Yes; and \aa would work also for bookmarks. – egreg Sep 06 '13 at 12:33