How to replace a letter?

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

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

\begin{document}
gg

\emph{gg}
\end{document}

four g's in FiraSans


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}

enter image description here

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.


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}

Fira Sans Stylistic Set 5

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}

% Load other fonts here.

\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}

Does Ziggy eat eggs?

Tags:

Fonts