Linux Libertine ligatures / T1

The libertine package documentation says

It is recommended that the font encoding be set to T1 or LY1 but the default OT1 encoding is also supported.

\documentclass{article}
% \usepackage[T1]{fontenc}
\usepackage[lining, tabular]{libertine}
\usepackage[libertine, cmintegrals]{newtxmath}

\begin{document}
\Huge The \{ stuffing \} 123 $f(x) = \int \sqrt{x}\,dx$
\end{document}


(Using pdflatex.)

With \usepackage[T1]{fontenc}:

Without T1:

LaTeX Font Warning: Font shape OMS/LinuxLibertineT-TLF/m/n' undefined
LaTeX Font Warning: Some font shapes were not available, defaults substituted.

The "Th" ligature is desirable, but the { and } characters are wrong without T1. What can I do about this?

(If using XeLaTeX is the only solution, what is the simplest set of packages and settings commands that I need?)

-
With the OT1 encoding the braces are taken from the math font, which is not the case in T1. –  egreg Jan 26 '13 at 17:36
@egreg Is that the expected behavior? I suppose not, since warnings are produced. In any case, it looks wrong since Libertine has its own braces... –  jtbandes Jan 26 '13 at 17:39
The warning is because LaTeX tries the current font family in OMS encoding, but such font doesn't exist, so the default math font is chosen (which is OMS/ntxsy/m/n). –  egreg Jan 26 '13 at 17:43
For XeLaTeX, I think you can actually keep everything as it is, i.e. don’t use fontenc. You’ll get the ⟨Th⟩ ligatures and I think the braces look right, but I’m not entirely sure. –  doncherry Jan 26 '13 at 18:06
@jtbandes: Yes this is the expected behaviour: OT1-encoding has only 128 positions and so no place for braces. The Th-ligature on the other side is not the expected behaviour: it is an undocumentated (as far as I can see) bonus of the OT1 version of libertine. If you want both (ligature and braces) you will either have to switch between T1 and OT1, or create your own encoding, or use xelatex. –  Ulrike Fischer Jan 26 '13 at 18:08

The OT1 encoding has no slot for the braces, because the normally allocated ones are for different symbols (the en-dash and the closing double quotes respectively). Instead, the braces are in a T1 encoded font.

Jump to the end for a short summary; otherwise, read on.

TeXnical details

When the encoding is OT1, \{ and \} choose a different font. Let's see; I assume that xpatch is loaded for \xshowcmd:

\show\{

> \{=macro:
->\x@protect \{\protect \{  .

\xshowcmd\{

> \{ =\long macro:
->\ifmmode \lbrace \else \textbraceleft \fi .


Since we are in text mode, \textbraceleft is expanded:

\show\textbraceleft

> \textbraceleft=macro:
->\OMS-cmd \textbraceleft \OMS\textbraceleft .


This one is harder: one has to know what to show: here it is

\expandafter\show\csname OMS\string\textbraceleft\endcsname

> \OMS\textbraceleft=\char"66.


However first of all LaTeX tries to see if \?\textbraceleft is defined, which it is:

\expandafter\show\csname ?\string\textbraceleft\endcsname

> \?\textbraceleft=\long macro:
->\UseTextSymbol {OMS}\textbraceleft .


OK. We're at it! LaTeX executes in a group

{\fontencoding{OMS}\selectfont\textbraceleft}


which will print character 0x66 from the selected font. But font substitutions are at the corner: indeed, the current family is LinuxLibertineT-TLF and there's a message

LaTeX Font Warning: Font shape OMS/LinuxLibertineT-TLF/m/n' undefined
(Font)              using OMS/ntxsy/m/n' instead
(Font)              for symbol textbraceleft' on input line 7.


because there's no external font corresponding to what's in the first line and so LaTeX uses the default font for the OMS encoding, which happens to by ntxsy (NewTXMath, because of your packages). You don't get a warning with the default Computer Modern fonts, because LaTeX knows an OMS/cmr/m/n font, which is precisely the same as OMS/cmsy/m/n (look in the file omscmr.fd to see how this is done).

When the base encoding is T1, you get a different answer from \show\textbraceleft, namely

> \textbraceleft=macro:
->\T1-cmd \textbraceleft \T1\textbraceleft .


and now we can do

\expandafter\show\csname T1\string\textbraceleft\endcsname


to get

> \T1\textbraceleft=\char"7B.


so LaTeX prints the character in slot 0x7B in the current font.

What does the above mean?

The difference is due to the fact that the braces in NewTXMath are slightly different from those in Linux Libertine. The former are used with the OT1 encoding, the latter with T1.

-
This is really neat! (not that I understand all of it), but doesn't really help me figure out a solution... –  jtbandes Jan 27 '13 at 1:51

you should use XeLaTeX or LuaLaTeX and

\documentclass{article}
\usepackage{unicode-math}
\setmathfont{texgyrepagellamath-regular.otf}
\usepackage[lining,tabular]{libertine}

\begin{document}
\Huge The \{ stuffing \} 123 $f(x) = \int \sqrt{x}\,dx$
\end{document}


-