# How can I access a specific glyph in LuaLaTeX/Fontspec?

The OTF version of Minion Pro contains several Dingbats glyphs I would like to access. Some of them are not unicode, so I can not just copy the specific unicode character I want to access into my text editor.
In specific, I am looking for the bold looking Moon on page 3 of this document: http://www.adobe.com/type/browser/pdfs/1719.pdf

After searching, I could not figure out how to include a specific character from a font to my document. I found out that I can use the command \symbol{glyph number}, but don't see how I should obtain that number.

Thus I ask my question more generally: how can I use a specific glyph from a font using LuaLaTeX?

-
one might add that your question is in fact a LuaTeX and XeTeX question. I'm somewhat inhibited to edit/retag it, though, as two of the answers are Lua-only. –  Nils L May 15 '13 at 10:02
Thanks for the comment Nils, I added it. –  Ingo May 16 '13 at 13:02

In my version of Minion Pro I get the two moons with

\documentclass{article}

\usepackage{fontspec}%
\setmainfont{Minion Pro}
\begin{document}
blub \symbol{57529} \symbol{57530}

\end{document}


I found the numbers this way:

1. I opened temp-minionpro-regular.lua (the path is mentioned in the log-file)

2. There I got to the part starting with unicodes={ (somewhere around line 590.000) and then skimmed the glyph names until I hit upon ["orn.001"]=57525, which sounded like the names for the ornaments.

-
I guess that, being the glyphs in the PUA, there's really no "universal" way to access them, if not specified in some table distributed with the font. –  egreg Feb 14 '13 at 13:43
@egreg: Well it is certainly possible to get lualatex to loop through the glyph list and make a table. But sometimes the brute force method is simply faster ;-) –  Ulrike Fischer Feb 14 '13 at 13:51
Another way to find the symbol number on Mac OS X is to find the glyph number in Font Book and then search for ["index"]=N (for the number you want), and take the index of the entry as the symbol number. –  Elliott Slaughter Nov 23 '14 at 22:25

[the following applies to both XeLaTeX and LuaLaTeX]

In addition to what Urike said -- another, maybe more practical way of finding a specific glyph is using a tool like Windows's Character Map (or the equivalent in your operating system). If you wanted Minion's bold crescent moon, you'd look for it in the ›private use area‹ first, which is quite a common place for special stuff.

Now you can either use the unicode number with \symbol, or you can copy that glyph straight to the TeX document in your (unicode-aware) editor:

...which may or may not display it correctly (this is WinEdt 7 using Courier New). But if the glyph is present in your font, the output should be fine nevertheless.

PS:

I can not just copy the specific unicode character I want to access

I'd say that, using this method, there'll be no unicode character that you can't copy :)

-

You can display the some of the glyphs in a font using Context document (assuming the font is called whatever.otf):

\definefontsynonym[Dummy][file:whatever.otf][features=default]
\starttext
\showfont[Dummy]
\stoptext


This displays the offset numbers that you can use in Latex with \symbol, for the first 256 glyphs in the font.

## Postcript

The following code iterates over all the characters in a given OTF file. For some reason unclear to me, this generally seems to include a lot of character entities not associated with glyphs.

 %%Define font name and font path here
\def\fontname{Jerusalem}
\def\filename{/usr/X11/lib/X11/fonts/OTF/SyrCOMJerusalem.otf}

\startluacode

charset={}

function fonttablechars (f)
local cs, r = f.characters, {}
for c in pairs(cs) do
r[1+#r]=c
end
table.sort(r)
return r
end

function setcharset ()
charset = fonttablechars(font.fonts[font.current()])
return charset
end

function printcharset ()
local step=9
context "\\bTABLE[split=yes] "
for i=1,#charset,step do
context "\\bTR "
for j=0,step-1 do
local v, cstr = i+j, tostring(charset[i+j])
if not charset[v] then break end
context ('\\bTD \\ppno{%s} \\eTD   \\bTD \\glyph{%s} \\eTD ', cstr, cstr)
end
context "\\eTR "
end
context "\\eTABLE "
end

\stopluacode

\definefontsynonym[\fontname][file:\filename][features=default]
\def\glyph#1{\getglyph{\fontname}{#1}}
\def\ppno#1{#1\relax}

\starttext

\section{Print font \fontname\ from \filename}

\setupbodyfont [\fontname]
\directlua0{setcharset()}

\setupbodyfont [mainface]
\directlua0{printcharset()}

\stoptext

-
\showfonts gives an error for me (undefined command), and \showfont prints only one page for minion pro. –  Ulrike Fischer Feb 14 '13 at 15:13
@Ulrike: Right about the typo, and \showfont only shows the first 256 glyphs, so only part of Unicode fonts. I plan to add an addendum with Lua code to show the rest. –  Charles Stewart Feb 14 '13 at 19:05

# Xetex

Even though the question is about LuaLatex, here another XeTeX solution

Based on this post: Generating a table of glyphs with XeTeX and some other research.

It prints you all glyphs and you can access them with \XeTeXglyph

\documentclass[landscape]{article}
\usepackage{geometry}
\usepackage{xltxtra}
\usepackage{fontspec}
\usepackage{xunicode}
\setmainfont{Minion Pro}
\usepackage{multicol}
\setlength{\columnseprule}{0.4pt}
\usepackage{multido}
\setlength{\parindent}{0pt}
\begin{document}

\XeTeXglyph508\XeTeXglyph1262

\begin{multicols}{10}
\multido{\i=0+1}{\XeTeXcountglyphs\font}{
\makebox[3em][l]{\i}%
\XeTeXglyph\i\endgraf
}
\end{multicols}

\end{document}

-
It's worth noting that XeTeXgylph will allow you to access any glyph in the font even if it's not tied to a unicode code point. So it's definitely useful on occasion but also somewhat finicky in practise because the glyph indices will (often/usually) be font-specific. –  Will Robertson Feb 14 '14 at 5:47

I just want to add some words to Nils L's answer: I personally use NexusFont on windows 7, which can display the whole table of characters by categories (Latin1 Supplement, Cyrillic, Basic Greek, &c.) and offers a zoom on individual characters. That makes it easier to find what you want. Below is a screenshot of NexusFont in action:

-