8

I opened Shobhika font in FontForge and it has certain glyphs which I am guessing aren't encoded in Unicode (if I understand this business correctly). E.g., have a look at the following slot.

1

What I guessed from this is that the slot I have selected is a non-Unicode position because I see U+????. Is there any way to load this shape by calling either 65664/0x10080/BhaRa.dv? Disclaimer: I don't know what all of them mean, I am just guessing they are different types of identifier for this shape. Which of these identifiers are understood by TeX (especially LuaTeX)? I found this solution, but it didn't work for the glyph I want.

6
  • You are right about your guess. It is not clear to me what macro package you use, but for ConTeXt, you can get them by using \resolvedglyphdirect. Works both for luatex and luametatex. Here is an example output from the BhaRa.dv.
    – mickep
    Commented Sep 11, 2023 at 12:22
  • @mickep I am using LaTeX :'(
    – Niranjan
    Commented Sep 11, 2023 at 12:46
  • Although what I want is exactly this. A command which will simply take an argument with one of these identifiers and print the glyph. Do you know a LaTeX-way to do this?
    – Niranjan
    Commented Sep 11, 2023 at 12:48
  • 1
    I used "n:BhaRa.dv", that takes the name. It seems there are alternatives in that command. So, good, now you know that it is possible in luatex at least. I am sure somebody else will help you with the latex way of doing it.
    – mickep
    Commented Sep 11, 2023 at 12:50
  • 1
    Yes, it seems not you have gotten the answer that you need. Good luck with the TeXing!
    – mickep
    Commented Sep 11, 2023 at 13:06

1 Answer 1

10

You can use slot_of_name from luaotfload:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Shobhika}
\begin{document}
The BhaRa.dv character is:
\directlua{tex.sprint("\\char" .. luaotfload.aux.slot_of_name(font.current(), [[BhaRa.dv]]))}
\end{document}

enter image description here


You can also enter the code directly with \char[code] if you know the slot number. I am not entirely sure how the codes correspond to the values that FontForge shows. You can however print the font table with numbers that \char understands with the following code, adapted from https://tex.stackexchange.com/a/666152/ (which is itself adapted from https://tex.stackexchange.com/a/98789/). The code is basically a for-loop around slot_of_name for each character.

\documentclass[a5paper]{article}
\usepackage{luacode}
\usepackage[margin=0.5cm]{geometry}
\usepackage{fontspec}
\usepackage{multicol}
\setlength{\columnsep}{0.3cm} \setlength{\columnseprule}{1pt}
\setmainfont{Shobhika Regular}

\newfontface\OD{Shobhika-Regular.otf}
\begin{document}
\begin{multicols}{4}\noindent
\begin{luacode*}
local f = fontloader.open('/usr/share/texlive/texmf-dist/fonts/opentype/public/shobhika/Shobhika-Regular.otf')
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("{\\OD\\char" .. glyphs[i].unicode .. "}");
   else
      local charcode = luaotfload.aux.slot_of_name(font.current(), glyphs[i].name)
      tex.sprint("{\\tiny " .. tostring(charcode) .. ":}")
      if (charcode ~= false) then
         tex.sprint("{\\OD\\char" .. charcode .. "}")
      end
   end
   tex.sprint("\\ {\\small(" .. string.gsub(glyphs[i].name, "_", "\\_") .. ")}\\\\")
end
fontloader.close(f)
\end{luacode*}
\end{multicols}
\end{document}

Small part of the output:

enter image description here

Now for example ShaVa.dv can be printed with \char984278 etc.

14
  • Thanks a lot! It works for me, but I want to discuss a few things. First of all, there is an absolute path in your code because of which it wasn't compiling on my machine. It would be great to not have it and ask the user to have Shobhika-Regular.otf in the working directory.
    – Niranjan
    Commented Sep 11, 2023 at 14:08
  • 1
    Oh, apparently using Renderer=Harfbuzz was creating a problem. I have no idea why, but removing it works perfectly fine! Thanks a lot.
    – Niranjan
    Commented Sep 11, 2023 at 14:37
  • 1
    Be aware that these indices are not stable. After an update of the font, LuaLaTeX, luaotfload or some settings they will often refer to different glyphs. Commented Sep 11, 2023 at 17:24
  • 1
    @Niranjan Thanks. But for reasons that I don't understand, I cannot use the methods in that answer to use the private use area glyphs in math mode. They seem to work outside math mode. Commented Sep 12, 2023 at 6:44
  • 1
    @ApoorvPotnis, Ask a separate question, showing what you tried. (For example, math mode uses its own fonts; what did your code do?)
    – Cicada
    Commented Sep 12, 2023 at 7:45

You must log in to answer this question.

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