Using individual glyphs from a OpenType Font in LuaLaTeX
I am currently preparing a tutorial on the Texas Instruments BAII Plus Professional Calculator in LaTeX. TI provides the font for the different keystrokes as TTF and PFB/PFM which makes it way easier to typeset the symbols.
The first step was to convert the font to OTF format. I tried TTF 2 OTF first without luck as the resulting OTF did not have any symbols in it. Using PFB 2 OTF worked better, the generated OTF had supposedly all the keys in it.
In the next step I wanted to generate an LaTeX overview of all symbols. Using the information from https://tex.stackexchange.com/questions/103704/how-to-properly-install-and-use-a-new-font-with-lualatex and https://tex.stackexchange.com/questions/25249/how-do-i-use-a-particular-font-for-a-small-section-of-text-in-my-document/37251 I came up with the following (don’t forget to install the OTF before!):
\documentclass[11pt]{article} \usepackage[left=1cm,right=1cm,landscape,a4paper]{geometry} \usepackage{fontspec} \newfontfamily\tifont{BA2Plus Symbols} \usepackage{luacode} \usepackage{longtable,array,xcolor,listings} \begin{luacode*} function print_glyphs(maxCols,maxChars) local id = font.current() -- geht Font ID local fnt = font.getfont(id) local col = 1 local maxU4 = 15*(16^3+16^2+16+1) a = {} for k, v in pairs(fnt.characters) do a [#a + 1] = k end table.sort(a) for i, k in ipairs(a) do if i >= maxChars then break end if col == 1 then if k > maxU4 then tex.sprint(string.format("U+%06x", k)) else tex.sprint(string.format("U+%04x", k)) end tex.sprint("&") end if (i) then tex.sprint(string.format([[\char%i]], k)) else tex.sprint("~") end if col == maxCols then -- Line finished? tex.sprint([[\\\cline{2-]] .. maxCols+1 .. "} ") -- Yes col = 1 -- newline else tex.sprint("&") -- no, Print & col = col + 1 -- next column end end end \end{luacode*} \begin{document} {\tifont \begin{longtable}{>{\color{black!50}\ttfamily\footnotesize}r| *{10}{>{\color{black}}p{5em}|}} \cline{2-11} \endhead \directlua{print_glyphs(10,65463)} \\ \cline{2-11} \end{longtable}} \end{document} |
The next step then was to create a logic of how to address the different symbols. Of course TSX was helpful again (https://tex.stackexchange.com/questions/38402/how-to-pick-a-specific-symbol-from-a-specific-font):
\documentclass[twocolumn]{article} \usepackage{fontspec} \usepackage[top=4cm,left=2cm,right=2cm,bottom=2cm]{geometry} \newfontfamily\tifont{BA2Plus Symbols} \newcommand\tif[1]{{\tifont\symbol{#1}}} \usepackage{fonttable} \begin{document} \twocolumn 33 > \tif{33} 34 > \tif{34} ... 124 > \tif{124} 125 > \tif{125} \end{document} |
The next step is to come up with a convenient way of addressing the glyphs, e.g. by creating aliases for each glyph.