4

I was having problems trying to combine a "traditional" font package (berasans) with fontspec (using TeX Gyre Pagella). Just using both correctly changed the text font to TeX Gyre Pagella, but text set with \sffamily used Latin Modern (Sans or Roman, depending on the order in which the packages were loaded) instead of Bera Sans.

Looking for a solution, I found this answer suggesting (albeit in a different context) that the font encoding had to be manually set. This left me with the following minimal example:

\documentclass{scrartcl}

\usepackage{fontspec}
\setmainfont{TeX Gyre Pagella}
\usepackage{berasans}
\let\sffamilyold\sffamily
\def\sffamily{\fontencoding{T1}\sffamilyold}

\begin{document}
TeX Gyre Pagella

\sffamily Bera Sans
\end{document}

which works, but I'm feeling slighly uneasy redefining \sffamily like that. Is there an easier/better solution for such a combination of Type 1 fonts and fontspec? Or even better, is there a good sans-serif OTF/TTF font to use with TeX Gyre Pagella?

  • 1
    According to tug.dk/FontCatalogue/berasans, “Bera Sans is a version of Bitstream Vera Sans slightly enhanced for use with TeX.” And the DejaVu family is based on Vera. DejaVu Sans should meet your needs. – Thérèse Sep 12 '15 at 2:06
  • 1
    I don't see the method you are using suggested in the answer/comments to the question you linked to. And I am not sure that defining it with \def is a great idea. The original is defined as a robust command. You are certainly losing some of the protections built into that command because you've declared an encoding switch before those checks are completed. – cfr Sep 12 '15 at 2:14
  • @cfr Well, the problem in the linked question was with the font encoding and apparently solved by using \titleformat{\section} {\fontencoding{EU2}\Large\sffamily\bfseries} {\thesection} {1em} {}. Sure, the idea to put the \fontencoding inside a redefinition of \sffamily is my own, that's why I'm asking about that ;-) – Socob Sep 12 '15 at 3:13
  • 2
    Don't change the encoding in \sffamily it will not go back when you change family back with \rmfamily also hyphenation of words within the changed encoding area is likely to be wrong. – David Carlisle Sep 12 '15 at 10:00
  • 2
    While you can use a type1 and T1-encoded font with xelatex I wouldn't recommend it. You will get problems with non-ascii-chars, and copy and paste could break. It is much better to look for a sensible open type version of the font you want to use. – Ulrike Fischer Sep 12 '15 at 10:20
4

I suggest you use the opentype version, developed by Arkandis Digital Foundry under the name of Verana Sans, or even a font inspired by Bitstream Vera, Switzera. Here is a demo:

\documentclass{scrartcl}

\usepackage{fontspec}
\setmainfont{TeX Gyre Pagella}
\usepackage{berasans}
\let\sffamilyold\sffamily
\def\sffamily{\fontencoding{T1}\sffamilyold}
%\setsansfont{Verana Sans}
%\setsansfont{Switzera ADF}

\begin{document}
TeX Gyre Pagella

\sffamily Bera Sans

\fontspec{Verana Sans}Verana Sans. Baffling, isn’t it?

\fontspec{Switzera ADF}
Switzera ADF

\end{document} 

enter image description here

  • Thanks for the pointer to ADF! You have a small typo in there ("Arkandis Digital Founfry"), but I can't suggest an edit with only one character changed... – Socob Sep 12 '15 at 13:09
  • Oh yes! One of my many typos… :o) It's corrected. – Bernard Sep 12 '15 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.