25

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?

1
  • 1
    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
    Commented May 15, 2013 at 10:02

10 Answers 10

18

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.

3
  • 1
    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
    Commented Feb 14, 2013 at 13:43
  • 1
    @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 ;-) Commented Feb 14, 2013 at 13:51
  • 3
    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. Commented Nov 23, 2014 at 22:25
14

[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.

enter image description here

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:

enter image description here

...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.

enter image description here

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 :)

related: How do I enter an arbitrary Unicode code point into my document? and Entering Unicode characters in LaTeX

7

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
2
  • 1
    \showfonts gives an error for me (undefined command), and \showfont prints only one page for minion pro. Commented Feb 14, 2013 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. Commented Feb 14, 2013 at 19:05
6

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}
1
  • 4
    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. Commented Feb 14, 2014 at 5:47
3

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: enter image description here

1

This program works fine to print the list of font's glyphes that are Unicode characters. However it misses all the glyphes that are variants of Unicode characters (the ones we generaly access thru RawFeatures) and that dont belong to Unicode. In the case of EBGaramond-Italic (from TeXLive), glyphmax has the value 3055 however only 1990 glyphes are listed. The 1065 missing ones are those non-Unicode glyphes. You can see them, using fontforge, at code points > 0x110000 (decimal 1 114 112), id est out of Unicode-full blocks. In the file ebgaramond-italic.lua, they have code points >983040. (Lua shits these glyphes apparently).

This program checks if (glyphs[i].unicode >0 ) -- that is the regular case of Unicode chars but does do nothing else when Unicode=-1, the code for non-Unicode glyphes. I dont know the OT fonts data structure in lua, however it should be possible to handle this case as well.

1
  • What do you mean by "this program"?
    – Teepeemm
    Commented Feb 10, 2023 at 14:57
1

The glyph number in \symbol{glyph number} is the Unicode codepoint.

You can find it for example with FontForge.

Open the font (e.g., the .ttf file) with FontForge.

Right click on the glyph you are interested in, and select "Glyph Info...":

enter image description here

The "Unicode Value" field will give you the Unicode value in hexadecimal:

enter image description here

Now you can use it with symbol: \symbol{"E95E}.

The " before the number indicate that the number is expressed in hexadecimal base.

2
  • There is no need for converting into decimals, \symbol understands hexadecimals perfectly \symbol{64}=\symbol{"40}.
    – campa
    Commented Aug 13, 2023 at 10:56
  • @campa You are right. Fixed. Commented Aug 13, 2023 at 14:05
1

The unicodefonttable package will show every glyph provided by the font and their unicode slots. Scrolling through the table generated by \displayfonttable{Minion Pro}, we see

unicode-table

So the moon glyphs are in slots U+E0B9 and U+E0BA, which can be accessed via \symbol{"E0B9} and \symbol{"E0BA}.

Full example:

\documentclass{article}

\usepackage{unicodefonttable}
\setmainfont{Minion Pro}

\begin{document}

\symbol{"E0B9} \symbol{"E0BA}

\displayfonttable{Minion Pro}

\end{document}
0

For reference, interestingly, the two moons (waxing and waning crescents?) are in different positions in the italic faces, where swashed glyphs push them further into the PUA:

comparison

Italic:

italic moons

MWE

\documentclass{article}
%\documentclass[varwidth,border=5pt]{standalone}
\newcommand\mypathname{C:/Users/verylongpathname/}
\newcommand\myfilename{\detokenize{MinionPro-It}}
\newcommand\myext{.otf}
\newcommand\myfont{\mypathname\myfilename\myext}

\usepackage{xcolor}
\usepackage{fontspec}
\setmainfont{Noto Serif}
\newfontfamily\forn{\myfilename}[
  Path=\mypathname,
  Extension=\myext,
  UprightFont=*,
%  ItalicFont=*-Italic,
%  BoldFont=*-Bold,
%  BoldItalicFont=*-BoldItalic,
%  SlantedFont=*-RegularSlanted,
%  BoldSlantedFont=*-BoldSlanted,
]
\newcommand\fstartrange{97}
\newcommand\fendrange{122}


\usepackage{luacode}
\usepackage{multicol}
\setlength{\columnsep}{0.3cm} \setlength{\columnseprule}{1pt}

\begin{document}

\myfilename\ 


%print inline sample
\begin{luacode}
      mystartrange = \fstartrange 
      myendrange   = \fendrange 
      myfont         = '\myfont'
\end{luacode}

\begin{luacode}
local f = fontloader.open(myfont)
local glyphs = {}
for i = 0, f.glyphmax - 1 do
   local g = f.glyphs[i]
   if g then
       table.insert(glyphs, {name = g.name, unicode = g.unicode})
   end
end
table.sort(glyphs, function (a,b) return (a.unicode < b.unicode) end)
--   tex.sprint('Sample\\\\')
tex.sprint(f.glyphmax .. ' glyphs\\\\')
for i = 1, #glyphs do
   if (glyphs[i].unicode > 0) then
      if (glyphs[i].unicode >= mystartrange ) then
      if (glyphs[i].unicode <= myendrange ) then
                tex.sprint("{\\forn\\Uchar" .. glyphs[i].unicode .. "}\\ ")
           end
           end
   end
end
fontloader.close(f)
\end{luacode}


%print table
\begin{multicols}{4}\noindent
\begin{luacode*}
local f = fontloader.open(myfont)
local glyphs = {}
for i = 0, f.glyphmax - 1 do
   local g = f.glyphs[i]
   if g then
       table.insert(glyphs, {name = g.name, unicode = g.unicode})
   end
end
table.sort(glyphs, function (a,b) return (a.unicode < b.unicode) end)
for i = 1, #glyphs do
   if (glyphs[i].unicode > 0) then
   tex.sprint(glyphs[i].unicode .. ": ")
   tex.sprint("{\\huge\\color{blue}\\forn\\char" .. glyphs[i].unicode .. "}");
   tex.print("\\ {\\scriptsize=")
   tex.print(-2, glyphs[i].name)
   tex.sprint('}\\\\')
   end
end
fontloader.close(f)
\end{luacode*}
\end{multicols}

\end{document}
0

You can open MinionPro-Regular.otf by fontforge and you see all characters. Of course, it is somewhat impractical to scroll the table with huge amount of undeclared slots. I am using Alt-Ctrl-] in such cases, it skips the block of undeclared slots. The moon character can be found and fontforge reports its code as 57530 (bold) or 57529 (normal). So, you can use

\char57530\ or \char57529

in your source code.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .