MaTeX to the Rescue
As of version 11.3, Mathematica's handling of font variations is still buggy. To address the need for displaying text objects in any font correctly and using them to compose graphic objects that can be converted to PDF without losing their formatting, I turn to MaTeX. It might seem overkill, but it allows you to bypass the font bug completely.
To be able to use any font installed in your system, you would need to use the XeLaTeX mode (with the path set as appropriate for your system):
Needs["MaTeX`"]
ConfigureMaTeX["pdfLaTeX" -> "/Library/TeX/texbin/xelatex"]
with fontspec
+ unicode-math
in the base preamble:
SetOptions[
{MaTeX},
"BasePreamble" -> {"\\usepackage{fontspec,unicode-math}"}
]
or mathspec
(which also loads fontspec
so you don't have to declare it):
SetOptions[
{MaTeX},
"BasePreamble" -> {"\\usepackage{mathspec}"}
]
Choosing between them is beyond the scope of this answer. (See for example here as a starting point.) In brief, if you'd like to use a non-math font in the math mode, go for mathspec
.
With either one of them chosen as the base preamble, we could construct a function that formats a string in any font of any size as follows, provided you know the name (not the PostScript name) of the font of the desired variation:
text[txt_, font_, size_] := MaTeX[
"\\text{" <> txt <> "}",
"Preamble" -> {"\\setmainfont{" <> font <> "}"},
Magnification -> size / 10
];
For example:
text["Hamburgefonstiv 2018", "InputMonoCondensed MediumIta", 40]

You can obtain Input Mono to try this yourself from here.
The approach allows me to for example produce a PDF figure below, typeset in two variations of ITC Conduit. Without it, exporting the plot (directly with "Save Graphic As", or through this, or through Jens's gsExport) only results in the text pieces falling back to Helvetica and frustration.

Bonus: Font Test
Let me share the following code to illustrate the font bug.
fonttest[family_, weight_, slant_, postscriptname_] := Module[
{sizes, text, head, list, n, g, s, p, private, c},
text = "Hamburgefonstiv 2018";
sizes = Range[20, 30, 10];
private = PrivateFontOptions -> {"FontPostScriptName" -> postscriptname};
c = Apply[RGBColor] /@ ({{27, 163, 142}, {252, 161, 36}, {220, 74, 74}, {30, 33, 40}} / 255);
list[x__] := (
Print["As Notebook Texts:"];
Table[
Print @ Style[text, FontSize -> size, x],
{size, sizes}
];
Print["As Graphics Objects:"];
Table[
Print @ Graphics[Text @ Style[text, FontSize -> size, x], ImageSize -> {size StringLength[text], 1.5 Max[sizes]}],
{size, sizes}
];
);
head[t1_, t2_, t3_] := Print @ g[
{{
s["Family: " <> n[t1]],
s["Weight/Slant: " <> n[t2]],
s["PS Name: " <> n[t3]]
}},
{None, None, {{1, 1} -> c[[1]], {1, 2} -> c[[2]], {1, 3} -> c[[3]]}}
];
g[cont_, bg_] := Grid[cont, Background -> bg, Frame -> All, FrameStyle -> White, Spacings -> {2, 1}];
s[txt_] := Style[txt, Larger, White, Bold];
n[state_] := Switch[state, -1, "Auto", 0, "-", 1, "Specified"];
p[txt_] := Print @ g[{{s @ txt}}, c[[4]]];
p["Compare the samples below with a correct specimen of " <> postscriptname];
head[-1, 0, 1];
list[FontFamily -> Automatic, private];
head[-1, 1, 1];
list[FontFamily -> Automatic, FontSlant -> slant, FontWeight -> weight, private];
head[1, 1, 0];
list[FontFamily -> family, FontSlant -> slant, FontWeight -> weight];
head[1, 0, 1];
list[FontFamily -> family, private];
head[1, 1, 1];
list[FontFamily -> family, FontSlant -> slant, FontWeight -> weight, private];
p["Export a Graphics Object to PDF to see if what works on screen still works in print"];
]
The arguments of fonttest
are:
- The base name of the font to test
- The value that would be for
FontWeight
were you to attempt to use the font
- The value that would be for
FontSlant
were you to attempt to use the font
- The PostScript name of the font
For example:
fonttest["Input Mono", "Thin", Italic, "InputMono-ThinItalic"]
The function helps you examine whether styling a string with the following methods works, in a Cell environment and Graphic environment:
1 (Minimal Specification)
Style[...,
FontFamily -> Automatic,
PrivateFontOptions -> {"FontPostScriptName" -> ...}
]
2
Style[...,
FontFamily -> Automatic,
FontWeight -> ..., FontSlant -> ...,
PrivateFontOptions -> {"FontPostScriptName" -> ...}
]
3 (Normal Specification)
Style[...,
FontFamily -> ...,
FontWeight -> ..., FontSlant -> ...
]
4
Style[...,
FontFamily -> ...,
PrivateFontOptions -> {"FontPostScriptName" -> ...}
]
5 (Maximal Specification)
Style[...,
FontFamily -> ...,
FontWeight -> ..., FontSlant -> ...,
PrivateFontOptions -> {"FontPostScriptName" -> ...}
]
All sample sets should look identical, or at least the discrepancies between them should be consistent across multiple fonts. Neither seems to be the case. Here's my result, on Mathematica 11.3 on macOS High Sierra, with Input Mono Thin Italic.
fonttest["Input Mono", "Thin", Italic, "InputMono-ThinItalic"]

So many things are not right, not to mention when the pieces are exported to PDF.
FontWeight -> "Bold"
still seems to work. Somehow Mathematica is re-orgainizing the dfont contents, and losing information. ButFontSlant
still works. Combinations like"Bold Italic"
are neither pure weight nor pure slant information, and maybe that's why they get ignored... $\endgroup$Style["Hello",20,Bold]
and if I select the output, it is correctly highlighted in the font panel ... $\endgroup$