# fontspec setmainfont working

Here is a minimal problem example

\ProvidesClass{cvMinimal}[2012/04/30 CV class]
\NeedsTeXFormat{LaTeX2e}

%%%%%%%%%%
% Colors %
%%%%%%%%%%

\RequirePackage{xcolor}
\definecolor{green}{HTML}{C2E15F}
\definecolor{gray}{HTML}{4D4D4D}

%%%%%%%%%
% Fonts %
%%%%%%%%%

\RequirePackage{fontspec}
\defaultfontfeatures{Mapping=tex-text}
\setmainfont[Mapping=tex-text, Color=gray]{Helvetica Neue Light}

%%%%%%%%%%
%%%%%%%%%%

\RequirePackage{tikz}
\usetikzlibrary{positioning}

\begin{tikzpicture}[remember picture, overlay]
\node[](name){\fontsize{24pt}{72pt}\selectfont\color{green}{My Name}};  %
\end{tikzpicture}
}


produces a gray "My name" wheras I would expect to produce a green one. Commenting the line setmainfont solves the problem.

Can someone explain me what do I do wrong ? And how to get what I want without commenting the setmainfontline which is important in the rest of my document?

I know it is possible since it is achieved in the cv here.

• What about {\addfontfeature{green}My Name}? – jon Jun 2 '13 at 20:07
• Some related discussion: How do I globally set the text color in XeLaTeX. When you specify the colour in the font definition you lose the ability to set it with normal means. – Alan Munn Jun 2 '13 at 20:12

As I suggested in my comment, the 'manual' way would be to call \addfontfeature where you want it. Another solution would be to use the SizeFeatures option for fontspec. Both are illustrated below. (I used Adobe's Source Sans Pro since I don't have Helvetica.)

\documentclass{article}

\usepackage{xcolor}
\definecolor{green}{HTML}{C2E15F}
\definecolor{gray}{HTML}{4D4D4D}

%%%%%%%%%
% Fonts %
%%%%%%%%%

\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text}
\setmainfont[ Mapping=tex-text,
SizeFeatures={
{Size={-24}, Color=gray},
{Size={24-}, Color=green}}
]{Source Sans Pro}

%%%%%%%%%%
%%%%%%%%%%

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{tikzpicture}[remember picture, overlay]
% \node[](name){%                       <-- manual solution
%   \fontsize{24pt}{72pt}\selectfont%
%
\node[](name2){%                       <-- uses SizeFeatures
\fontsize{24pt}{72pt}\selectfont {My Name2}};
\end{tikzpicture}
}

\begin{document}

my name;

\fontsize{24pt}{72pt}\selectfont my name;

\end{document}


In my opinion it's better to define separate font families: one for the main text font, another one for the special items. Here's an example.

\documentclass{article}
\usepackage{xcolor}
\definecolor{cvgreen}{HTML}{C2E15F} % give distinctive names to colors
\definecolor{cvgray}{HTML}{4D4D4D}

\usepackage{fontspec}
\setmainfont[Ligatures=TeX,Color=cvgray]{Helvetica Neue Light}
\newfontfamily{\greenHelv}[Ligatures=TeX,Color=cvgreen]{Helvetica Neue Light}

\usepackage{tikz}
\usetikzlibrary{positioning}