Skip Navigation

Simple font selection for opentype fonts

ConTeXt has a nice font selection system. LaTeX ported the ConTeXt code in luaotfload.sty and they have fontspec, OpTeX has a font selection system with font files and all. In plain, there's only the primitive font switches. There are some packages on ctan for plain to extend functionality, but I'm not sure how they work.

The good news is, you can use luaotfload.sty directly in plain! Just \input luaotfload.sty. The bad news if you're into minimalism is that it depends on LaTeX so you'll need that installed. An alternative is to use luafonts.tex from the csplain package: \input luafonts.tex, it uses the luaotfload code too.

Once you've done that, you can use all the nice things in luaotfload.

In this example I'll use an updated version of Tuftes Bembo-clone, ETbb. You can put the files anywhere where luaotfload will find them, ~/.fonts or your projects directory for example.

There are many ways to implement font selection. I rarely use many fonts in a project, so I usually just do something simple like this:

\font\tenrm "ETbb-Regular" at 10pt
\font\tenit "ETbb-Italic" at 10pt
\font\tenbf "ETbb-Bold" at 10pt
\font\tenbi "ETbb-BoldItalic" at 10pt
\font\tensc "ETbb-Regular":+smcp;letterspace=10; at 10pt
\font\tencaps "ETbb-Regular":+upper;letterspace=10; at 10pt

The opentype features come after the name, with a + or - to turn them on or off. To make it a little more semantic I add a size macro, and why not set \baselineskip at the same time. You could also set struts here.

\def\normalsize{% 10pt
	\baselineskip=12pt
	\def\rm{\tenrm}%
	\def\it{\tenit}%
	\def\bf{\tenbf}%
	\def\bi{\tenbi}%
	\def\sc{\tensc}%
	\def\caps{\tencaps}%
}

Now I can type \normalsize\rm and the default will be 10pt roman. \it will switch to italic, \sc to small caps, etc. I have two special switches for small caps and big caps because I always want them letterspaced and maybe some opentype features too.

With the same structure, it's (repetitive) but easy to add a \footnotesize say, 8pt, and a \largesize at 12pt.

In regular writing the macros could work something like this:

\normalsize\rm % default for document

\centerline{\largesize\caps Title}

\vskip\baselineskip

Lorem ipsum {\it dolor} sit amet, consectetur {\bf adipiscing} elit. Integer non {\bi accumsan} sem. Vestibulum ante {\sc ipsum} primis in faucibus orci luctus et ultrices posuere cubilia curae; Morbi blandit in nisl sed dapibus. Praesent porttitor id mauris sit amet tincidunt.
 
\vskip\baselineskip 
 
{\footnotesize\rm
Lorem ipsum {\it dolor} sit amet, consectetur {\bf adipiscing} elit. Integer non {\bi accumsan} sem. Vestibulum ante {\sc ipsum} primis in faucibus orci luctus et ultrices posuere cubilia curae; Morbi blandit in nisl sed dapibus. Praesent porttitor id mauris sit amet tincidunt.\par
}

which gives:

This is a very primitive and simple way, and would probably become tedious if you're using lots of different fonts, then it would be better to use/make a more advanced system. There's a programming paradigm called "Worse is better", and I'm not sure if this is an example of that. Maybe it's just "Worse is worse". But, it's easy to understand all the moving parts, which can be a good thing.

The full code:

%\input luaotfload.sty
\input luafonts.tex

\hsize=65mm
\frenchspacing
\tolerance=1000

\font\eightrm "ETbb-Regular" at 8pt
\font\eightit "ETbb-Italic" at 8pt
\font\eightbf "ETbb-Bold" at 8pt
\font\eightbi "ETbb-BoldItalic" at 8pt
\font\eightsc "ETbb-Regular":+smcp;letterspace=10; at 8pt
\font\eightcaps "ETbb-Regular":+upper;letterspace=10; at 8pt

\font\tenrm "ETbb-Regular" at 10pt
\font\tenit "ETbb-Italic" at 10pt
\font\tenbf "ETbb-Bold" at 10pt
\font\tenbi "ETbb-BoldItalic" at 10pt
\font\tensc "ETbb-Regular":+smcp;letterspace=10; at 10pt
\font\tencaps "ETbb-Regular":+upper;letterspace=10; at 10pt

\font\twelverm "ETbb-Regular" at 12pt
\font\twelveit "ETbb-Italic" at 12pt
\font\twelvebf "ETbb-Bold" at 12pt
\font\twelvebi "ETbb-BoldItalic" at 12pt
\font\twelvesc "ETbb-Regular":+smcp;letterspace=10; at 12pt
\font\twelvecaps "ETbb-Regular":+upper;letterspace=10; at 12pt

\def\footnotesize{% 8pt
	\baselineskip=10pt
	\def\rm{\eightrm}%
	\def\it{\eightit}%
	\def\bf{\eightbf}%
	\def\bi{\eightbi}%
	\def\sc{\eightsc}%
	\def\caps{\eightcaps}%	
}

\def\normalsize{% 10pt
	\baselineskip=12pt
	\def\rm{\tenrm}%
	\def\it{\tenit}%
	\def\bf{\tenbf}%
	\def\bi{\tenbi}%
	\def\sc{\tensc}%
	\def\caps{\tencaps}%
}

\def\largesize{% 12pt
	\baselineskip=14pt
	\def\rm{\twelverm}%
	\def\it{\twelveit}%
	\def\bf{\twelvebf}%
	\def\bi{\twelvebi}%
	\def\sc{\twelvesc}%
	\def\caps{\twelvecaps}%
}

{\footnotesize\rm footnotesize rm}\par
{\footnotesize\it footnotesize it}\par
{\footnotesize\bf footnotesize bf}\par
{\footnotesize\bi footnotesize bi}\par
{\footnotesize\sc footnotesize sc}\par
{\footnotesize\caps footnotesize caps}\par

\vskip\baselineskip

{\normalsize\rm normalsize rm}\par
{\normalsize\it normalsize it}\par
{\normalsize\bf normalsize bf}\par
{\normalsize\bi normalsize bi}\par
{\normalsize\sc normalsize sc}\par
{\normalsize\caps normalsize caps}\par

\vskip\baselineskip

{\largesize\rm largesize rm}\par
{\largesize\it largesize it}\par
{\largesize\bf largesize bf}\par
{\largesize\bi largesize bi}\par
{\largesize\sc largesize sc}\par
{\largesize\caps largesize caps}\par

\vskip\baselineskip 
\hrule
\vskip\baselineskip

\normalsize\rm

\centerline{\largesize\caps Title}

\vskip\baselineskip

Lorem ipsum {\it dolor} sit amet, consectetur {\bf adipiscing} elit. Integer non {\bi accumsan} sem. Vestibulum ante {\sc ipsum} primis in faucibus orci luctus et ultrices posuere cubilia curae; Morbi blandit in nisl sed dapibus. Praesent porttitor id mauris sit amet tincidunt.
 
\vskip\baselineskip 
 
{\footnotesize\rm
Lorem ipsum {\it dolor} sit amet, consectetur {\bf adipiscing} elit. Integer non {\bi accumsan} sem. Vestibulum ante {\sc ipsum} primis in faucibus orci luctus et ultrices posuere cubilia curae; Morbi blandit in nisl sed dapibus. Praesent porttitor id mauris sit amet tincidunt.\par
}

\bye
0
0 comments