Just a quick question, I want parts of my document to be on this particular font which resembles a code, like this with mclust
and FactoMineR
:
How can I do this?
codefonts
Just a quick question, I want parts of my document to be on this particular font which resembles a code, like this with mclust
and FactoMineR
:
How can I do this?
I don't know whether I understand you question right. Here is my interpretation ;-)
\documentclass[11pt]{article}
\begin{document}
\makeatletter
orig: \f@size
\verb+\small+ \small \f@size
\verb+\normalsize+ \normalsize \f@size
\verb+\large+ \large \f@size
\verb+\Huge+ \Huge \f@size
\makeatother
\end{document}
This is actually the hardest part. When you load a regular font package like helvet
(which sets the default sans serif font to a Helvetica clone) it issues commands to set up the font using an internal name, which is hidden to regular users. These names traditionally use a system of three or four letter lower case names for each font family. Usually these names are documented in documentation associated with the font.
Here is a list of the most common fonts, and their codes:
Family Font Name pag Avant Garde fvs Bitstream Vera Sans pbk Bookman bch Charter ccr Computer Concrete cmr Computer Modern pcr Courier mdugm Garamond phv Helvetica fi4 Inconsolata lmr Latin Modern lmss Latin Modern Sans lmtt Latin Modern Typewriter LinuxBiolinumT-OsF Linux Biolinum (formerly 'fxb' in older package versions) LinuxLibertineT-OsF Linux Libertine (formerly 'fxl' in older package versions) pnc New Century Schoolbook ppl Palatino qag TeX Gyre Adventor qbk TeX Gyre Bonum qzc TeX Gyre Chorus qcr TeX Gyre Cursor qhv TeX Gyre Heros qpl TeX Gyre Pagella qcs TeX Gyre Schola qtm TeX Gyre Termes ptm Times uncl Uncial put Utopia pzc Zapf Chancery
For some greek fonts the codes are:
Artemisia artemisia
Baskerville gfsbaskerville
Bodoni bodoni
Complutum complutum
Didot udidot
Neohellenic neohellenic
Porson porson
Solomos solomos
Greek Times txr
Kerkis mak
LX llcmss
Default lmr
If you don't find any documentation for the font, as a last resort (or a first resort once you know what you're doing) you can open the .sty
file that actually loads the font and see for yourself what the internal font family name is (or you could search inside it with grep
). Here are two examples:
From helvet.sty
: at the end of the package is the line:
\renewcommand{\sfdefault}{phv}
This sets the default sans font (\sfdefault
) to the phv
family, so phv
is the internal name of the font.
From PTSansCaption.sty
, you will find the following line:
\renewcommand{\sfdefault}{PTSansCaption-TLF}
Here, the internal name is closer to its file name: PTSansCaption-TLF
.
Both of these examples have shown the code for changing the default sans serif font. If the font package changes the roman or mono font you would look for the following commands respectively
\renewcommand{\rmdefault}{...}
\renewcommand{\ttdefault}{...}
To select a font, you use the following commands:
\fontfamily{<familyname>}\selectfont
It's often useful to wrap this in a macro:
\newcommand*{\myfont}{\fontfamily{<familyname>}\selectfont}
You can always restrict the scope of font changing commands by enclosing the text in braces:
{\fontfamily{<familyname>}\selectfont ...}
or if using a command
{\myfont ...}
or, to make the scope of the command more visible in your file if you don't have a brace-matching editor
\begingroup
\myfont ...
\endgroup
If this is something you will be doing a lot, it would make more sense to turn it into a proper environment:
\newenvironment{myfont}{\fontfamily{<familyname>}\selectfont}{\par}
Then you use it like any other environment:
\begin{myfont}
Some text in the new font.
\end{myfont}
You can also define a command corresponding to the standard font changing commands such as \textrm
or \textsf
, but using your particular font:
\DeclareTextFontCommand{\textmyfont}{\myfont}
Use this like the standard commands:
Text in the default font. \textmyfont{Text in the new font.} Again text in the default font.
An advantage of this command over the simpler version described above is automatic italic correction, cf. Why use \DeclareTextFontCommand vs. just \newcommand?.
(except ccr Compute Concrete).
Best Answer
Simply type: