[Tex/LaTex] How to print Unicode characters in LaTeX by its code? (For example \U0001316E)

newunicodecharsymbolsunicodexetex

For example, the character [ \U0001316E ] in Unicode is 𓅮. How could I transform it into a LaTeX command.

I tried to use XeLaTeX compiler and directly copy the symbol into Overleaf, but is became �� in the editior.

I also tried to use \symbol{}, but it only can print a small number of Unicode characters.

What other methods I can try? How about to use newunicodechar?

Best Answer

The font 'Noto Sans Egyptian Hieroglyphs - Regular' has placed its 1,071 glyphs in slots 77824 thru 78894 or, equivalently, slots U13000 thru U1342E. (To typeset all glyphs in a table, one needs 66 rows with 16 glyphs and 1 row with 15 glyphs.)

Under either LuaLaTeX or XeLaTeX, one may use either \symbol or \char to typeset the glyphs by their "number":

  • To typeset the first glyph in the font file, one can write either \symbol{77824} or \symbol{"13000}; to typeset the final glyph, one can write either \symbol{78894} or \symbol{"1342E}. (The " character informs TeX that the number is written with hexadecimal-numeral notation.)

  • Alternatively, if you prefer to use \char instead of symbol, you'd write either \char77824 or \char"13000 for the first glyph and either \char78894 or \char"1342E for the final glyph contained in the font file. Observe that the argument of \char must not be enclosed in curly braces.

Let's generate a practical example. To typeset the glyph "𓅮", you could peruse the table shown below and discover that the glyph is located in a row with row index 78176 and column index 14. Because 78176+14=78190, you could write \symbol{78190} or \char78190 to generate the desired glyph. Naturally, you're free to write \symbol{"1316E} or \char"1316E if you prefer hexadecimal-numeral notation.

Table of characters part 1

Table of characters part 2

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{longtable,booktabs,geometry}
\usepackage{fontspec}
\newfontfamily{\Egypt}{NotoSansEgyptianHieroglyphs-Regular}

%% Set up a Lua function to typeset all 1071 glyphs
\usepackage{luacode}
\begin{luacode}
function allrows ()
   for i = 4864,4930 do
      tex.sprint ( i*16 )
      for j = 0,15 do tex.sprint ( '&\\Egypt\\char' .. i*16+j ) end
      tex.sprint ( '\\\\' ) -- row terminator
   end
end
\end{luacode}

\begin{document}
\noindent
First glyph: {\Egypt \symbol{"13000} \symbol{77824}}.
Final glyph: {\Egypt \symbol{"1342E} \symbol{78894}}.

%% Typeset all glyphs in a longtable: 16 data columns, 67 rows
\ttfamily
\setlength\tabcolsep{0pt}
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\renewcommand\arraystretch{1.25}

\begin{longtable}{@{\extracolsep{\fill}} l *{16}{c} }
   %% headers and footers:
    \directlua{for i=0,15 do tex.sprint("&"..i) end} \\
    \midrule
    \endhead
    
    \bottomrule
    \endfoot

   %% call the Lua function to generate the body of the table
   \directlua{allrows()}
\end{longtable}
\end{document}

Addendum: Overleaf permits the use of all Noto fonts -- including NotoSansEgyptianHieroglyphs-Regular -- under both XeLaTeX and LuaLaTeX. The following MWE (minimum working example)

\documentclass{article}
\usepackage{fontspec}
\newfontfamily{\Egypt}{NotoSansEgyptianHieroglyphs-Regular}
\begin{document}
First glyph: {\Egypt \symbol{77824} \char"13000} \quad
OP's glyph:  {\Egypt \symbol{78190} \char"1316E} \quad
Final glyph: {\Egypt \symbol{78894} \char"1342E} 
\end{document}

indeed runs fine on Overleaf, as the screenshot below confirms. (Just be sure to select XeLaTeX as the compiler from the "Menu" column and to load the fontspec package.)

Overleaf screenshot

Related Question