# How to replace a letter?

When I use font package FiraSans

I enter "g", get

But actually I want to get

I don't quite understand that FiraSans font has two g forms, but they do exist in "*.otf"

I checked the description and ".sty" file of the package, only found the command to control the numeric style.

If you can not affect the Italian font, then it is better.

• Do you use XeLaTeX or LuaLaTeX with the .otf fonts or pdfLaTeX with Type 1 fonts? – moewe Aug 25 '18 at 16:13
• If you switch to FiraGO (bboxtype.com), the successor to Fira Sans 4.3, ss05 controls ‘g’ and only ‘g’, whereas in Fira Sans ss04 controls both ‘g’ and ‘a’. – Thérèse Aug 25 '18 at 16:54
• @Thérèse Are the stylistic sets and alternatives of the font families documented anywhere, or do we just have to look it up in a program like FontForge? – Davislor Aug 25 '18 at 17:59
• @Davislor Some designers and foundries provide documentation, and others don’t. FiraGo comes with several PDF files, and those called “Technical_Report*.pdf” dcoument the features. – Thérèse Aug 25 '18 at 18:03
• @Thérèse Ah! I did look through that document, but I didn't see it until I searched. According to pages 37–38, Stylistic Set 5 ought to work in Fira Sans as well. – Davislor Aug 25 '18 at 18:10

The following workaround enables you to change the letter g without also changing the letter a, in the upright font. First, download the updated version (4.301) of the font files (or at least the ones that are in TEXMF/fonts/opentype/public/fira into a subdirectory of your project directory, named fonts.

This version contains the substitution you want as Stylistic Set 5. You can tell fontspec to look in your project’s fonts directory for Fira Sans and to add this stylistic set on every upright font in the family that it will load in the future.

This will completely remove any ambiguity about which of the several versions of Fira Sans on your hard drive you want to load.

Then, load the firasans package and get all its interfaces. Or load it yourself by the method of your choice.

\documentclass[varwidth, preview]{standalone}
\usepackage{fontspec}

% Requires version 4.301 of the font files to be stored in a subdirectory
% named fonts
\defaultfontfeatures[FiraSans]{
UprightFeatures = { StylisticSet=5 },
BoldFeatures = { StylisticSet=5 },
Path = ./fonts/ }

\usepackage[sfdefault]{firasans}

\begin{document}
Ziggy eats eggs.
\end{document}


If the package maintainer updates the version of the fonts in the TeX Live distribution, this hack will no longer be necessary. As of TeX Live 2018, it is.

### Another Approach

The firasans package is what you were using before, and has a number of options and support for different font weights. Since some commenters requested a solution using only fontspec, here it is. This defines the de-facto standard LaTeX2e series names, as defined in the second edition of The LaTeX Companion and The LaTeX Font Installation Guide.

This version does not support all the weights of the font family, but it does support all the ones that correspond to LaTeX commands in common use, such as \textlf and \sbseries. For ordinary use, you might prefer to do what the package does and create a font family that selects relatively lighter or darker weights as its regular and bold.

It does define \firafamily for compatibility with firasans, but doesn’t declare all the variants that package does.

It is also more future-proof, should the firasans package ever change (for example, to load Fira Go).

\documentclass[varwidth, preview]{standalone}
\usepackage{fontspec}

% Requires version 4.301 of the font files to be stored in a subdirectory
% named fonts
\setsansfont{FiraSans}[
Ligatures = { Common, Discretionary, TeX },
Numbers = { Lining, OldStyle },
Scale = 1.0 ,
FontFace = {ul}{n}{ StylisticSet=5, Font = *-UltraLight},
FontFace = {ul}{it}{*-UltraLightItalic},
FontFace = {el}{n}{ StylisticSet=5, Font = *-ExtraLight},
FontFace = {el}{it}{*-ExtraLightItalic},
FontFace = {l}{n}{ StylisticSet=5, Font = *-Light},
FontFace = {l}{it}{*-LightItalic},
UprightFont = *-Regular ,
UprightFeatures = { StylisticSet=5 },
ItalicFont = *-Italic ,
FontFace = {mb}{n}{ StylisticSet=5, Font = *-Book},
FontFace = {mb}{it}{*-BookItalic},
FontFace = {sb}{n}{ StylisticSet=5, Font = *-Medium},
FontFace = {sb}{it}{*-MediumItalic},
FontFace = {db}{n}{ StylisticSet=5, Font = *-Semibold},
FontFace = {db}{it}{*-SemiboldItalic},
BoldFont = *-Bold ,
BoldFeatures = { StylisticSet=5 },
BoldItalicFont = *-BoldItalic ,
FontFace = {eb}{n}{ StylisticSet=5, Font = *-ExtraBold},
FontFace = {eb}{it}{*-ExtraBoldItalic},
FontFace = {ub}{n}{ StylisticSet=5, Font = *-Heavy},
FontFace = {ub}{it}{*-HeavyItalic},
Extension = .otf ,
Path = ./fonts/
]

\let\firafamily\sfdefault
\renewcommand*\familydefault{\firafamily}

\DeclareRobustCommand\ulseries{\fontseries{ul}\selectfont}
\DeclareTextFontCommand\textul{\ulseries}
\DeclareRobustCommand\elseries{\fontseries{el}\selectfont}
\DeclareTextFontCommand\textel{\elseries}
\DeclareRobustCommand\lfseries{\fontseries{l}\selectfont}
\DeclareTextFontCommand\textlf{\lfseries}
\DeclareRobustCommand\mbseries{\fontseries{mb}\selectfont}
\DeclareTextFontCommand\textmb{\mbseries}
\DeclareRobustCommand\sbseries{\fontseries{sb}\selectfont}
\DeclareTextFontCommand\textsb{\sbseries}
\DeclareRobustCommand\dbseries{\fontseries{db}\selectfont}
\DeclareTextFontCommand\textdb{\dbseries}
\DeclareRobustCommand\ebseries{\fontseries{eb}\selectfont}
\DeclareTextFontCommand\texteb{\ebseries}
\DeclareRobustCommand\ubseries{\fontseries{ub}\selectfont}
\DeclareTextFontCommand\textub{\ubseries}

\newcommand\eggs{Ziggy eats eggs.}

\begin{document}
\parbox{160pt}{
\textul{\eggs} \textel{\eggs} \textlf{\eggs} \textmd{\eggs} \textmb{\eggs}
\textsb{\eggs} \textdb{\eggs} \textbf{\eggs} \texteb{\eggs} \textub{\eggs}
\textit{\textul{\eggs} \textel{\eggs} \textlf{\eggs} \textmd{\eggs}
\textmb{\eggs} \textsb{\eggs} \textdb{\eggs} \textbf{\eggs} \texteb{\eggs}
\textub{\eggs}}}
\end{document}


• tex.stackexchange.com/q/434273 is relevant if you’re trying to work with newer versions than those in TeX Live. – Thérèse Aug 25 '18 at 18:37
• @Thérèse Thanks! In practice, I would either stick my own version of the fonts in a project directory and use fontspec’s Path = feature to override the (inconsistent) default search paths, or else change the filename, e.g. to FiraSans4.3-Regular.otf, – Davislor Aug 25 '18 at 23:42
• What is the purpose of the firasans package? – AndreKR Aug 26 '18 at 9:52
• @AndreKR I wondered that as well. If one is using fontspec, why not just go with \setmainfont{FiraSans}? Does the package get you anything extra? – Derek Aug 26 '18 at 16:37
• I added a second solution using only fontspec. (And also fixed a bug with bold text in the first MWE.) – Davislor Aug 26 '18 at 20:10

If you are using LuaLaTeX and the OTF version of the fonts you can try

\documentclass[a4paper]{article}
\usepackage{fontspec}
\directlua{
name = "galt",
type = "substitution",
data = {["g"] = 0x210A,}
}}
\setmainfont[RawFeature={+galt}]{FiraSans}

\begin{document}
gg

\emph{gg}
\end{document}


This is easy if you use fontspec and xelatex:

\documentclass{article}
\usepackage{fontspec}
\setmainfont[StylisticSet=4]{FiraSans-Medium.otf}

\begin{document}
Ziggy eats eggs.
\end{document}


Update:

Thérèse's note raises an excellent point: if you do it this way, you change the look of both "a" and "g". Just FYI.

• There is one question: this method has changed the letter a. Can we not change the letter a? – poorich Aug 25 '18 at 17:09
• As far as I'm aware, specifying StylisticSet is all-or-nothing – you can't pick and choose characters. But I'm not 100% sure I'm right about that. – Derek Aug 25 '18 at 17:11
• The solution of @moewe doesn’t affect the ‘a’ — this is one great advantage to luatex. – Thérèse Aug 25 '18 at 17:14