5

I have encountered something I fail to understand. I have read that I should use fontspec and not fontenc when I use XeLaTeX, but this causes some problems for me when I use the cochineal font package.

When I use the following code:

\documentclass[a4paper, english]{article}

\usepackage{polyglossia}
\setmainlanguage{english}
\usepackage{fontspec}
\usepackage[p,osf]{cochineal} 

\title{Some title}

\begin{document}
    \maketitle
    some text
\end{document}

I get the message in the log that Font shape TU/Cochineal-OsF/m/n undefined(Font) using TU/lmr/m/n instead and the font for the title defaults ot Latin Modern. But when I instead use:

\documentclass[a4paper, english]{article}

\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[p,osf]{cochineal} 

\title{Some title}

\begin{document}
    \maketitle
    some text
\end{document}

I don't get that message and the title is in the Cochineal font. Am I setting something wrong when I use fontspec? Is there some drawback with using fontenc together with XeLaTex? I would really like to get Cochineal also in the title.

I'm using MikTex on a Windows 10 machine.

All the best, Richard

10
  • 1
    this font is not suited for xelatex/lualatex. Sep 1, 2018 at 18:48
  • Thank you, it looks ok even though I use xelatex, is there some problem with using xelatex and cochineal? Is there some similar font that is a better option (if I have to stick to xelatex)? Sep 1, 2018 at 18:51
  • Type Grüße in your example with fontenc and you will see the problem. T1/fontenc is not for xelatex. It will break with quite a number of chars. Use pdflatex if you want to use your font. Sep 1, 2018 at 19:04
  • 1
    if you use T1 encoding then 8bit encoded fonts will appear to load but all hyphenation will be wrong as the hyphenation tables loaded for xelatex assume Unicode. Sep 1, 2018 at 19:22
  • 1
    but the fonts are available as OpenType so you can use them directly with xetex and fontspec ctan.org/tex-archive/fonts/cochineal/opentype Sep 1, 2018 at 19:30

2 Answers 2

3

The cochineal package is only for pdflatex. If you have installed the OpenType version of Cochineal as a system font you can emulate the package as follows

\documentclass[a4paper]{article}

\usepackage{fontspec}
\usepackage{polyglossia}

\setmainfont{Cochineal}[
  Numbers={Proportional,OldStyle},
]
\setmainlanguage{english}

\DeclareRobustCommand{\lfstyle}{\addfontfeatures{Numbers=Lining}}
\DeclareTextFontCommand{\textlf}{\lfstyle}
\DeclareRobustCommand{\tlfstyle}{\addfontfeatures{Numbers={Tabular,Lining}}}
\DeclareTextFontCommand{\texttlf}{\tlfstyle}

\title{Some title}

\begin{document}

\maketitle

some text 1234567890\par
some text {\lfstyle 1234567890} \textlf{1234567890}\par
some text {\tlfstyle 1234567890} \texttlf{1234567890}\par

\end{document}

enter image description here

If, for some reasons, you only rely on the TeX Live distribution, the font setup is slightly different.

\documentclass[a4paper]{article}

\usepackage{fontspec}
\usepackage{polyglossia}

\setmainfont{Cochineal}[
  Extension=.otf,
  UprightFont=*-Roman,
  ItalicFont=*-Italic,
  BoldFont=*-Bold,
  BoldItalicFont=*-BoldItalic,
  Numbers={Proportional,OldStyle},
]
\setmainlanguage{english}

\DeclareRobustCommand{\lfstyle}{\addfontfeatures{Numbers=Lining}}
\DeclareTextFontCommand{\textlf}{\lfstyle}
\DeclareRobustCommand{\tlfstyle}{\addfontfeatures{Numbers={Tabular,Lining}}}
\DeclareTextFontCommand{\texttlf}{\tlfstyle}

\title{Some title}

\begin{document}

\maketitle

some text 1234567890\par
some text {\lfstyle 1234567890} \textlf{1234567890}\par
some text {\tlfstyle 1234567890} \texttlf{1234567890}\par

\end{document}
2

With xetex you want to use the default TU (Unicode) encoding and access the OpenType versions of the font directly via fontspec

enter image description here

The pdffonts utility confirms that the font used in the pdf is:

name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
FXMMJJ+Cochineal-Roman-Identity-H    CID Type 0C       Identity-H       yes yes yes      5  0

This from a source of

\documentclass[a4paper, english]{article}

\usepackage[english]{babel}
\usepackage{fontspec}
\setmainfont{Cochineal}

\title{Some title}

\begin{document}
    \maketitle
    some text
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .