# Last step in moving to XeTeX: Font shape problems

I am trying to move to the XeTeX distribution. My current problem is the following:

If I leave these packages I have no problems with the Helvetica.

\usepackage[portuges,english]{babel}
\usepackage[T1]{fontenc}
\usepackage[scaled]{helvet}
\renewcommand*\familydefault{\sfdefault}


However, if I define the XeTeX packages and font like:

\usepackage{mathspec}
\defaultfontfeatures{Mapping=tex-text}
\setmainfont{Helvetica}

\usepackage{polyglossia}
\setmainlanguage[variant=uk]{english}
\setotherlanguage{portuges}

\usepackage{xunicode}
\usepackage{unicode-math}


Then I get warnings about missing font shapes, namely:

LaTeX Font Warning: Font shape EU1/phv/b/n' undefined
LaTeX Font Warning: Font shape EU1/Helvetica(0)/m/sc' undefined


I have also tried:

\usepackage{mathspec}
\defaultfontfeatures{Mapping=tex-text}
\usepackage[scaled]{helvet}
\renewcommand*\familydefault{\sfdefault}


But then the font shapes got even worse.

Has someone faced this problem?

EDIT:

Now I have the following packages:

\usepackage{mathspec}
\defaultfontfeatures{Mapping=tex-text}
\setmainfont[
Extension=.otf,
UprightFont= *-regular,
BoldFont=*-bold,
ItalicFont=*-italic,
BoldItalicFont=*-bolditalic,
]{texgyreheros}

\usepackage{polyglossia}
\setmainlanguage[variant=uk]{english}
\setotherlanguage{portuges}

\usepackage{xunicode}
\usepackage{unicode-math}


And the template I started with has the following command:

\newcommand{\helv}{ %
\fontfamily{phv}\fontseries{b}\fontsize{9}{11}\selectfont}


I honestly don't know what it is doing to the font, but I do know it's the last resistant:).

Warning is:

LaTeX Font Warning: Font shape EU1/phv/b/n' undefined


If I remove the \fontfamily command I get

LaTeX Font Warning: Font shape EU1/texgyreheros(0)/b/n' undefined


This command is being applied in the Header and Footer of the document.

I don't know what the \fontfamily does, but I assume \fontseries defines the font to be Bold. Is there a redefinition of the command required to match XeTeX?

-
is your Helvetica family complete, e.g. do you have bold, italics, small caps, and bold italics versions of the helvetica font? /m/sc is the small caps variant. If you don't have small caps of Helvetica, then you won't be able to load /m/sc. –  Mica Feb 3 '11 at 21:44
I don't have them, can they be found in the internet? (I am talking legit scenarios) –  Tiago Veloso Feb 3 '11 at 21:47
As far as I know there is no small caps variant of Helvetica. The helvet package uses faked small caps and Linotype doesn't sell any small caps variant. –  Caramdir Feb 3 '11 at 21:59
I assume there is no workaround then? –  Tiago Veloso Feb 3 '11 at 22:23

The TeX Gyre fonts typically come with small caps. TeX Gyre Heros looks very similar to Helvetica (technically, it is based on URW Nimbus Sans L; so it has the same font metrics as Helvetica, but the characters might look slightly different­­­­). The fonts are probably already installed with your TeX distribution. To use them form there in XeLaTeX, you have to call them the following way:

\documentclass{article}
\usepackage{fontspec}

\setmainfont[
Extension=.otf,
UprightFont= *-regular,
BoldFont=*-bold,
ItalicFont=*-italic,
BoldItalicFont=*-bolditalic,
]{texgyreheros}

\begin{document}
CGRart \textsc{CGRart}
\end{document}


-
I am going to try this later today. –  Tiago Veloso Feb 4 '11 at 8:45
This works wonders. However I have one last detail to iron out all warnings. I have added it to my question above. –  Tiago Veloso Feb 4 '11 at 12:20
@tiago instead of writing \fontshape{b} just write \bfseries. –  Will Robertson Feb 4 '11 at 14:02
Another wonder :)thanks Will –  Tiago Veloso Feb 4 '11 at 14:26

As Caramdir mentions in his comment, Helvetica doesn't come with small caps, and it doesn't seem that many free fonts (and even many professional fonts) come with real small caps. Will Robertson recommended the following workaround on the XeTeX mailing list a couple of years ago.

In the past I've thought about this in fontspec, but it really becomes impossible if you want the fake small caps to behaviour like \textsc -- that is, to have uppercase come out as real uppercase but lowercase to come out as scaled uppercase.

So rather than using fontspec, it's probably easier to use the relsize package, like this:

\documentclass{article}
\usepackage{fontspec,relsize}
\begin{document}
\fontspec{Georgia}
THIS IS UPPERCASE and lowercase
{\smaller THIS IS FAKE SMALL CAPS}
\end{document}


You can always define a macro to make this more "semantic", as well:

\newcommand\fakesc[1]{{\smaller #1}}

Original message here.

-
Even though I've upvoted you for quoting me — :) — for this very specific question regarding Helvetica I think Caramdir's answer hits the nail on the head. For arbitrary fonts, however, your answer here is the best you can do. –  Will Robertson Feb 4 '11 at 3:33
@Will: I think your vote didn't register. –  Caramdir Feb 4 '11 at 3:49
@Will I gave up looking through all the fonts on my system and stopped at 'S'. If I'd been more persistent I would have come up with Caramdir's solution. I was trying to find a substitute font and failed through exhaustion. –  Alan Munn Feb 4 '11 at 4:06
If one is looking for replacements/extensions of popular fonts, TeX Gyre is a good place to start. I would have posted that solution earlier today, but I was under the impression that Heros doesn't have small caps. –  Caramdir Feb 4 '11 at 4:34
@Caramdir vote fixed, not sure about how that happened. –  Will Robertson Feb 4 '11 at 14:01

Just wanted to post my results with this - it seems the biggest problem is font encoding; apparently neither \sffamily nor \sfdefault handle it - so while one can set "phv" as the helvetica font in diverse ways, that font seemingly only exists in T1 encoding. One sign of this is if I compile the below example with pdflatex (previously removing all fontspec-related stuff) - and I get upon loading of helvet.sty:

(/path/to/texlive/2011/texmf-dist/tex/latex/psnfss/ot1phv.fd
File: ot1phv.fd 2001/06/04 scalable font definitions for OT1/phv.


The problem is then, that fontspec will switch to a different encoding - EU1 if you build with xelatex, and EU2 if with lualatex (or at least that is how I've seen it so far). And so, \sffamily may tell fontspec to look for phv, but if the encoding is set to EU2, then fontspec looks for EU2/phv which doesn't exist (instead of T1/phv which does).

The solution seems to be to issue a command like this explicitly:

\fontencoding{T1}\fontfamily{phv}\selectfont


... and as the below MWE shows, I haven't found a way how to redefine \sffamily or \sfdefault to also switch to T1 encoding (like with explicit \fontencoding{T1}). Another way could - conceivably - be, to use something like:

\DeclareFontShape{EU2}{phv}{m}{n}{<->ssub * phv/bx/n}{} % nope


... in the spirit of font "mapping" as in this post (where xelatex is used to generate a fake-bold smallcaps family; and the missing bold smallcaps from the original font is mapped to the fake-bold one); unfortunately, it seems \DeclareFontShape can only map between fonts of the same encoding - I cannot see a way to specify something line T1 on the right-hand side.

The output of the MWE is this (click for full res):

... and this is what pdffonts sees there:

\$ pdffonts test.pdf
name                                 type              emb sub uni object ID
------------------------------------ ----------------- --- --- --- ---------
UGSGGF+Junicode                      CID TrueType      yes yes yes      8  0
GEDPKS+LMRoman10-Regular             CID Type 0C       yes yes yes      9  0
ZRGIMP+NimbusSanL-Bold               Type 1            yes yes no      10  0
[none]                               Type 3            yes no  no      11  0
EURSKX+Junicode-Bold                 CID TrueType      yes yes yes     12  0


... and this is the code:

\documentclass[10pt]{article}

\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\setmainfont[Scale=1.0]{Junicode}

\usepackage[left=10pt,right=10pt]{geometry}
\usepackage{tikz}

\usepackage{helvet}

% for debugging fonts: http://tex.stackexchange.com/a/14382/2595
\makeatletter
\newcommand{\showfont}{Encoding: \f@encoding{},
Family: \f@family{},
Series: \f@series{},
Shape: \f@shape{},
Size: \f@size{},
\edef\tmpfn{\font@name}
font@name: \meaning\font@name \\
}
\makeatother

\begin{document}

Testing 1 \showfont

\sffamily\selectfont

Testing 2 \showfont

% texlive/2011/texmf-dist/tex/latex/psnfss/helvet.sty
\renewcommand{\sfdefault}{phv}\sfdefault\selectfont

Testing 3 \showfont

\fontencoding{T1}\fontfamily{phv}\bfseries\selectfont

Testing 4 \showfont % macro:->\T1/phv/bx/n/12

\rmfamily\selectfont

Testing 5 \showfont

\fontencoding{EU2}\selectfont

Testing 6 \showfont

\sffamily\selectfont

Testing 7 \showfont

\fontencoding{T1}\selectfont

Testing 8 \showfont

\fontencoding{EU2}\rmfamily\selectfont

Testing 9 \showfont

%     \DeclareFontShape{EU2}{phv}{m}{n}{<->ssub * phv/bx/n}{} % nope
%     \renewcommand{\sfdefault}{\T1/phv/bx/n/12} % nope
\sffamily\selectfont

Testing 10 \showfont

\typeout{ .. \expandafter\meaning\csname sffamily \endcsname -- \meaning\sffamily} %  .. \long macro:->\not@math@alphabet \sffamily \mathsf \fontfamily \sfdefault \selectfont -- macro:->\protect \sffamily
\typeout{ .. \expandafter\meaning\csname sfdefault \endcsname -- \meaning\sfdefault} % \relax-- \long macro:->phv
\typeout{ .. \expandafter\meaning\csname fontfamily \endcsname -- \meaning\fontfamily} % \long macro:#1->\edef \f@family {#1}-- macro:->\protect \fontfamily
\typeout{ .. \expandafter\meaning\csname selectfont \endcsname -- \meaning\selectfont} %

\end{document}


Well, hope this helps someone,
Cheers!

-