4

I would like to use the Type1 libertine fonts provided by the package libertine and compile with XeLaTeX. According to the manual under section 4, this can be activated with the option type1:

\documentclass{article}
\usepackage[type1, oldstyle]{libertine}
\begin{document}
This is a test 1234567890 fi ffi fl ffl ft fft fj ffj tt
\end{document}

I would like to use the OpenType fonts, also provided by the libertine package, when I need to access glyphs not included in the Type1 fonts. As mentioned in section 5 in the manual, I can access these with the macro \libertineGlyph{}:

\documentclass{article}
\usepackage{libertine}
\begin{document}
\libertineGlyph{uni025D}
\end{document}

But how do I combine these? As said above, I'd like to stick to Type1 fonts as far as possible (as this renders ligatures and old style numbers copy- and searchable in the pdf), but switch to the OpenType fonts when I need special glyphs. Combining the type1 option with \libertineGlyph{} does not compile:

\documentclass{article}
\usepackage[type1, oldstyle]{libertine}
\begin{document}
This is a test 1234567890 fi ffi fl ffl ft fft fj ffj tt \libertineGlyph{uni025D}
\end{document}

! Undefined control sequence.

l.4 ...ffi fl ffl ft fft fj ffj tt \libertineGlyph{uni025D}?

Sverre
  • 20,729
  • It appears that \libertineGlyph is now only defined when the type1 option is not used. Why do you need to use it? – Thruston Jun 12 '14 at 14:27
  • @Thruston That's mentioned twice in my question: (1) "I would like to use the OpenType fonts [...] when I need to access glyphs not included in the Type1 fonts" (2) "I'd like to [...] switch to the OpenType fonts when I need special glyphs". – Sverre Jun 12 '14 at 14:35
  • OK I see. It's just that your example compiles fine here if I remove the type1 option. But I guess there are other glyphs you need. – Thruston Jun 12 '14 at 14:50
  • Actually no. What I meant was why not use the OTF for everything? Do the Type 1 fonts have any glyph in them that's not in the OTF? – Thruston Jun 12 '14 at 14:52
  • 1
    @Thruston Ah. Actually, the reason for wanting to use Type1 fonts whenever possible is given in my question as well: "this renders ligatures and old style numbers copy- and searchable in the pdf" :P – Sverre Jun 12 '14 at 14:59
  • 1
    The ligatures and old-style numbers from the OpenType fonts are copyable and searchable. The only times I’ve had trouble were when a font’s designer misused the Private Use Area for ligatures. – Thérèse Jun 12 '14 at 17:24
  • @Thérèse Which is the case with the libertine font ... I'm not speaking about OpenType fonts in general. – Sverre Jun 12 '14 at 17:25
  • I tried Herbert’s example with no problem; which ligatures are giving you trouble? – Thérèse Jun 12 '14 at 17:26
  • @Thérèse Are you compiling with XeLaTeX as mentioned in my question? Problems with: Th, 1234567890, ft, fft, fj, ffj, tt. – Sverre Jun 12 '14 at 17:29
  • Sorry, I forgot to change from my default, luatex. Xetex does produce a complete mess here, while luatex gets it right. Is luatex an option for you? – Thérèse Jun 12 '14 at 17:33
  • @Thérèse Eventually, yes, but it's not mature enough yet. As an example, the problem of using combining diacritics addressed in Why choose LuaLaTeX over XeLaTeX? still hasn't been fixed. – Sverre Jun 12 '14 at 17:46

2 Answers2

2

You'll have to combine definitions from libertine.sty:

 \documentclass{article}
\usepackage{fontspec}
\makeatletter
  \def\libertine@base{LinLibertine}
  \def\biolinum@base{LinBiolinum}
  \defaultfontfeatures{
     Ligatures = TeX ,
     Extension = .otf ,
     SmallCapsFeatures={Letters=SmallCaps} ,
  }
  \newfontfamily\libertine
        [ Numbers = {Proportional,OldStyle},
          UprightFont    = *_R,
          ItalicFont     = *_RI,
          BoldFont       = *_RB, 
          BoldItalicFont = *_RBI,
        ] {\libertine@base}
  \def\lib@fxl{LinLibertine_R}
  \def\lib@fxb{LinBiolinum_R}
  \def\lib@fxk{LinBiolinum_K}
  \def\lib@fxi{LinLibertine_I}

  \providecommand*\DeclareTextGlyphY[3]{%
      % \DeclareTextGlyphY{fxl}{s_t}{64262}
      % #1=basefont #2=glyphname, #3=position
      \def\lib@temp{#1}%
      \ifx\lib@temp\lib@fxl \@namedef{#1@#2}{{\libertine\char#3\relax}}\else%
        \ifx\lib@temp\lib@fxb \@namedef{#1@#2}{{\biolinum\char#3\relax}}\else%
          \ifx\lib@temp\lib@fxk \@namedef{#1@#2}{{\biolinumkey\char#3\relax}}\else%
            \ifx\lib@temp\lib@fxi \@namedef{#1@#2}{{\libertineInitial\char#3\relax}}\else%
      \fi\fi\fi\fi}
  %
  \input{LinLibertine_R}
  \input{LinBiolinum_R}
  \input{LinBiolinum_K}
  \input{LinLibertine_I}
  %
  \DeclareRobustCommand*\libertineGlyph[1]{\@nameuse{LinLibertine_R@#1}}
  \DeclareRobustCommand*\biolinumGlyph[1]{\@nameuse{LinBiolinum_R@#1}}
  \DeclareRobustCommand*\biolinumKeyGlyph[1]{\@nameuse{LinBiolinum_K@#1}}
  \DeclareRobustCommand*\libertineInitialGlyph[1]{\@nameuse{LinLibertine_I@#1}}
\makeatother
\usepackage[T1]{fontenc}
\usepackage[type1,oldstyle]{libertine}
\begin{document}

This is a test 1234567890 fi ffi fl ffl ft fft fj ffj tt

{\libertine\libertineGlyph{uni025D}}

\end{document}
user51830
  • 316
  • Can you add some words about what you're doing here, and how/why it works? Also, adding \usepackage[T1]{fontenc} removes many of the ligatures included in my test line. – Sverre Jun 12 '14 at 16:26
  • I took elements from libertine.sty that support \libertineGlyph. You can use LY1 encoding if you want. – user51830 Jun 12 '14 at 16:54
  • or OT1, which seems to give all the ligatures in your test line. – user51830 Jun 12 '14 at 17:02
  • OT1 provides the highest number of ligatures, but it doesn't contain any characters used outside of English, so that's not really an option. I'm curious why \usepackage{fontenc} is necessary at all. It's not needed when just loading \usepackage[oldstyle]{libertine}. – Sverre Jun 12 '14 at 17:04
  • You need fontenc to define \newfontfamily, which is needed to load the otf font. – user51830 Jun 12 '14 at 17:21
  • Sorry, I confused fontenc and fontspec. fontenc is needed to undo the font-encoding setting by fontspec. If you \usepackage{libertine} without fontenc or fontspec, you're getting the default encoding (OT1). – user51830 Jun 12 '14 at 17:35
  • Really? When I compile your code without fontenc, my output has the Latin Modern font rather than libertine. – Sverre Jun 12 '14 at 17:42
  • Look at the log to see why. – user51830 Jun 12 '14 at 18:20
  • @Sverre Probably because it cannot switch to libertine with the EU1 encoding active so it falls back to the default which is Latin Modern if fontspec is loaded. Note that you should still get libertine for the glyph following the \libertine command but the default font hasn't been changed in that case. – cfr Jul 12 '14 at 20:50
2

All glyphs from Type1 are in the OpenType. There is no need to use the Type1 version of Libertine:

\documentclass{article}% xelatex or lualatex
\usepackage{fontspec}
\usepackage[oldstyle]{libertine}
\begin{document}

This is a test 1234567890 fi ffi fl ffl ft fft fj ffj tt

\symbol{"025D}

\end{document}

enter image description here

  • Yes, all the glyphs are included in the OpenType fonts, but ligatures and oldstyle numbers won't be copy- and searchable, as mentioned in my question. – Sverre Jun 12 '14 at 16:24
  • "won't be copy- and searchable" Which pdf viewer are you using? – user51830 Jun 12 '14 at 17:27
  • @user51830 Adobe Acrobat. – Sverre Jun 12 '14 at 17:29
  • "won't be copy- and searchable" What exactly do you mean by that? – user51830 Jun 12 '14 at 18:31
  • I have no problem with searching except the oldstyle figures which are always lined one when copied. –  Jun 12 '14 at 18:39
  • Did you try witn XeLaTeX? I get a mess... (And it would be better if it did copy the figures as lined but the issue with the ligatures is even worse.) – cfr Jun 12 '14 at 23:26