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.

Niranjan
  • 3,435
  • 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 Sep 11 '23 at 12:22
  • @mickep I am using LaTeX :'( – Niranjan Sep 11 '23 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 Sep 11 '23 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 Sep 11 '23 at 12:50
  • @mickep I meant LuaLaTeX, not the plain one. If this is possible in LuaTeX, then it should also work with LuaLaTeX, right? – Niranjan Sep 11 '23 at 12:57
  • 1
    Yes, it seems not you have gotten the answer that you need. Good luck with the TeXing! – mickep Sep 11 '23 at 13:06

1 Answers1

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.

Marijn
  • 37,699
  • 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 Sep 11 '23 at 14:08
  • The other question is, if I don't have \setmainfont command with Shobhika, the output doesn't show the non-standard glyphs. They only show up when I set Shobhika as the main font. What might be the reason? – Niranjan Sep 11 '23 at 14:09
  • @Niranjan without the absolute path it did not work on my machine, so I left it in. Of course some changes may be needed for different users, as is often the case when working with filenames or other operating system-related operations. This is not "production code", I hope it can serve as a starting point for you and others to achieve the results they want. – Marijn Sep 11 '23 at 14:12
  • @Marjin, sure! That's alright. – Niranjan Sep 11 '23 at 14:13
  • For the main font: this is most likely related to slot_of_name taking font.current() as an argument, which is a register number that is connected in some way to \setmainfont. I didn't look into it further but there is probably a way to get the number index of secondary fonts to use as the argument to slot_of_name. – Marijn Sep 11 '23 at 14:15
  • @Marjin Okay, maybe a fontspec-problem, will ask a separate question for that. I have a last question to you regarding this. I tried your code with another font I am currently testing (can't share it as I don't have the rights). I followed the exact same steps like looking into the glyph name with FontForge and using it in the code you have given, but weirdly I get bad character code error with that font. I tried forming the character table with the other code and issued \char[code] command. It works, but I get a tofu. What might be wrong with it? – Niranjan Sep 11 '23 at 14:25
  • 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 Sep 11 '23 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. – Marcel Krüger Sep 11 '23 at 17:24
  • Can this method be used to access glyphs in private use areas of some math fonts, such as stix two math? – Apoorv Potnis Sep 11 '23 at 17:39
  • @MarcelKrüger I made a easy-to-use macro with \def\myglyph#1{\directlua{tex.sprint("\\char" .. luaotfload.aux.slot_of_name(font.current(),[[#1]]))}}}. It should be safe, right? As it would compute the index number on-the-fly. Of course I am guessing the font-developer shouldn't change the internal name that they have set once. – Niranjan Sep 12 '23 at 04:34
  • @ApoorvPotnis does this answer your question? – Niranjan Sep 12 '23 at 04:35
  • 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. – Apoorv Potnis Sep 12 '23 at 06: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 Sep 12 '23 at 07:45
  • @Cicada David Carlisle has said that he shall write an answer later, regarding this. I just thought this method might work perhaps https://tex.stackexchange.com/questions/693724/how-to-use-sans-serif-italic-greek-letter-in-math-mode/693745?noredirect=1#comment1721770_693745 – Apoorv Potnis Sep 12 '23 at 13:46