[Tex/LaTex] Temporarily change font encoding with fontenc

font-encodings

Is there a way to temporarily change the font encoding with fontenc inside a document? Something like this:

\documentclass{article}
\usepackage[OT1]{fontenc}
\begin{document}
I'm writing something with OT1 encoding here.
But then I want the character X to be with T1 encoding.
\end{document}

I'm anticipating some "Why do you want to do this?" questions. So here's why:

With OT1 encoding, using the libertine package gives me certain nice ligatures (like the one for Th). I don't with T1 encoding (no idea why). But some characters aren't available with OT1 encoding, such as \dh, so I would like to temporarily switch to T1 encoding to be able to use such characters.

Best Answer

\usepackage[T1,OT1]{fontenc}

then

{\fontencoding{T1}\selectfont  T1 stuff ...}

full example, following comments.

\documentclass{article}

\usepackage[T1,OT1]{fontenc}
\usepackage{libertine}

\showoutput
\begin{document}

That {\fontencoding{T1}\selectfont That}

\end{document}

The log confirms the fonts used and the OT1 ligature

....\OT1/LinuxLibertineT-TLF/m/n/10 � (ligature Th)
....\OT1/LinuxLibertineT-TLF/m/n/10 a
....\OT1/LinuxLibertineT-TLF/m/n/10 t
....\glue 2.5 plus 1.25 minus 0.833
....\T1/LinuxLibertineT-TLF/m/n/10 T
....\T1/LinuxLibertineT-TLF/m/n/10 h
....\T1/LinuxLibertineT-TLF/m/n/10 a
....\T1/LinuxLibertineT-TLF/m/n/10 t
Related Question