# How to typeset a letter or grapheme specimen with alternates?

I want to print a font specimen for certain letters, each of which should cover a complete A4 page.

The Open Type font contains many letters with several glyphs, which are accessible as character variants (cc..), in stylistic sets (ss..), as contextual and positional alternates (calt; init, medi, fina), local or historic forms (locl; hist) or otherwise; some are available through different methods, of course. Some letters are also part of ligatures (liga, dlig, clig, hlig). Most of them can be seen with Access All Alternates (aalt) in GUIs.

I’d like to typeset them all at the same font size, which would be considerably larger than \Huge, say 5 cm (140 pt or so). Preferably, they would be put on a background that showed light lines at baseline, x-height, cap-height or ascender-height and descender-height, all determined automatically if possible.

The thing is, I have no idea if LuaTeX or Tikz/PGF or a combination thereof is the best tool for the job. The specimens might become part of a .tex document later on, but I could live with independent pages for now. So any pointers in the right direction are appreciated.

• How do I draw and, most importantly, correctly position the horizontal lines – automatically? (Background colors to show the “bands” would be okay, too.)
• Is there a better way to access glyphs (without Unicode position) by name than shown in the code below?

## Rough concept

Using Linux Libertine as an example without employing OT features yet.

% !TEX TS-program = LuaLaTeX
\documentclass{scrartcl}

\usepackage{fontspec,xcolor,libertine,graphicx}
\setmainfont[Color=brown]{Linux Libertine O}

% access glyph by name with LuaTeX
\begin{luacode}
documentdata       = documentdata or { }
local stringformat = string.format
local texsprint    = tex.sprint
documentdata.fontchar = function (chr)
local chr = slot_of_name(font.current(), chr, false)
if chr and type(chr) == "number" then
texsprint
(stringformat ([[\char"%X]], chr))
end
end
\end{luacode}

\newcommand\linecolor{gray}
\newcommand\lineheight{1mm}
\newcommand\linelength{\textwidth}

% \horizontalline{<color>}{<thickness>}{<width>}{<position>}
\newcommand\horizontalline[4]{\relax} %  <== how to?
% \textline{<color>}{<thickness>}{<position>}
\newcommand\textline[1]{\horizontalline{\linecolor}{\lineheight}{\linelength}{#1}}

\newcommand\ascenderline{\textline{k-height}} % stem
\newcommand\capitalline{\textline{H-height}} % majuscule size
\newcommand\midline{\textline{A-line}} % crossbar
\newcommand\meanline{\textline{x-height}} % minuscule size
\newcommand\baseline{\textline{0}} % alphabetic base
\newcommand\descenderline{\textline{-p-height}} % depth

\newcommand\visiblelines{%
\ascenderline\capitalline\midline\meanline\baseline\descenderline}

\newcommand\letterspecimen[1]{\visiblelines%
{\framebox[1.1\width]{\fontsize{40mm}{50mm}\selectfont #1\strut}}}

\def\fontchar#1{\directlua{documentdata.fontchar "#1"}}
\def\yround{\fontchar{y.alt}}
\def\heng{\fontchar{h.alt}}

\begin{document}

\letterspecimen{A a ɑ}

\letterspecimen{G g ɡ \fontchar{uni0262} \fontchar{g.sc}}

\letterspecimen{H h \heng}

\letterspecimen{Y y \yround}

\end{document}

• Maybe consider setting them in a regular font on a sufficiently-large page. Then, crop it and include it as a correctly-scaled image. – Werner Jul 14 '14 at 19:42
• @Werner, that’s the solution I’m afraid of, because it sounds like a lot of work that should be possible to be automated. – Crissov Jul 14 '14 at 20:02
• It may sound like a lot of work, but it's really flexible and not that much more than trying to make it work in your document, really. – Werner Jul 14 '14 at 20:08
• If you use standalone, you can crop automagically. (There are probably other packages which do this more simply, maybe?) – cfr Jul 15 '14 at 0:39

Here, I address the issue of underlaying ruled lines below the sample glyphs, using stacks. I put the text in a box first, to determine its width, which I need to set the rule length. I set the rule thickness (\rulewd) as .02ex in the current larger font. I then construct a stack of rules with the following characteristics, regardless of rule thickness.

1. the baseline rule sits atop the baseline

2. The rule at 1ex height has its upper extremity at 1ex

3. The rule at the height of X has its upper extremity at that height

4. the descender rule is based on the depth of y and sits with its lower extremity at that depth.

The MWE:

% !TEX TS-program = LuaLaTeX
\documentclass{scrartcl}

\usepackage{fontspec,xcolor,libertine,graphicx}
\setmainfont[Color=brown]{Linux Libertine O}

% access glyph by name with LuaTeX
\begin{luacode}
documentdata       = documentdata or { }
local stringformat = string.format
local texsprint    = tex.sprint
documentdata.fontchar = function (chr)
local chr = slot_of_name(font.current(), chr, false)
if chr and type(chr) == "number" then
texsprint
(stringformat ([[\char"%X]], chr))
end
end
\end{luacode}

\newcommand\linecolor{gray}
\newcommand\lineheight{1mm}
\newcommand\linelength{\textwidth}

% \horizontalline{<color>}{<thickness>}{<width>}{<position>}
\newcommand\horizontalline[4]{\relax} %  <== how to?
% \textline{<color>}{<thickness>}{<position>}
\newcommand\textline[1]{\horizontalline{\linecolor}{\lineheight}{\linelength}{#1}}

\newcommand\ascenderline{\textline{k-height}} % stem
\newcommand\capitalline{\textline{H-height}} % majuscule size
\newcommand\midline{\textline{A-line}} % crossbar
\newcommand\meanline{\textline{x-height}} % minuscule size
\newcommand\baseline{\textline{0}} % alphabetic base
\newcommand\descenderline{\textline{-p-height}} % depth

\newcommand\visiblelines{%
\ascenderline\capitalline\midline\meanline\baseline\descenderline}

\newlength\rulewd
\def\therule{\rule{\wd0}{\rulewd}}
{\framebox[1.1\width]{\fontsize{40mm}{50mm}\selectfont\color{black}%
\setbox0=\hbox{#1}%
\setbox2=\hbox{Xy}%
\stackengine{0pt}%
{\setlength\rulewd{.02ex}%
\stackon[\dimexpr-\dp2]{%
\stackon[\dimexpr\ht2-\rulewd]{%
\stackon[\dimexpr1ex-\rulewd]{\therule}{\therule}}{\therule}}{\therule}}
{#1\strut}{O}{l}{F}{F}{L}}}}

\def\fontchar#1{\directlua{documentdata.fontchar "#1"}}
\def\yround{\fontchar{y.alt}}
\def\heng{\fontchar{h.alt}}
\usepackage{stackengine}
\begin{document}

\letterspecimen{A a ɑ}

\letterspecimen{G g ɡ \fontchar{uni0262} \fontchar{g.sc}}

\letterspecimen{H h \heng}

\letterspecimen{Y y \yround{} X x}

\end{document}


Here I change \rulewd to .06ex and the rule color to gray!50:

I have confirmed that the method scales when different font sizes are invoked in the \letterspecimen macro.