3

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?

13
  • As supplement, I tested and it seems all characters in form of [ \U00xxxxxx ] can be printed and all characters in form of [ \U01xxxxxx ],[ \U02xxxxxx ],[ \U03xxxxxx ] can not. Feb 29, 2020 at 4:42
  • 1
    Welcome to TeX.SE. Have you tried using LuaLaTeX instead of XeLaTeX? (The luaotfload utility has a way of mapping characters with a unicode number above UTF8's range back into the acceptable range.) Out of curiosity: Which font has a glyph for 𓅮?
    – Mico
    Feb 29, 2020 at 5:31
  • Thanks. I have tried but it works exactly the same. Feb 29, 2020 at 5:37
  • 1
    @Mico Noto Sans Egyptian Hieroglyphs, and some others. 𓅪𓅫𓅬𓅭𓅮𓅯𓅰𓅱
    – Cicada
    Feb 29, 2020 at 5:47
  • 1
    @ZizhengYang Overleaf has the complete set of Noto fonts "as included in Ubuntu 18.04": overleaf.com/learn/latex/Questions/What_OTF/… So tryfont "Noto Sans Egyptian Hieroglyphs" with fontspec package. Otherwise, you have to upload it via the menu, apparently.
    – Cicada
    Feb 29, 2020 at 6:09

2 Answers 2

6

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

5

Just use the character, specifying a font that contains it, and compile with xelatex or lualatex:

\documentclass{article}
\usepackage{fontspec}
\newfontfamily{\hifont}{NotoSansEgyptianHieroglyphs-Regular}
\begin{document}
I, {\hifont 𓅮}, am a bird.
\end{document}

output


That's all you need, if you're using a good editor and compiling locally. Now on Overleaf specifically, there seems to be a bug in its text editor component for “astral” characters (Unicode characters outside the Basic Multilingual Plane, namely those with codepoints greater than FFFF in hexadecimal = 65535 in decimal). So as you say, if you paste “𓅮” into the web version, it turns into “��”.

(Overleaf used to have a way to upload your own files and compile them; if that works for you, you could use that. Otherwise...) A workaround is to use hex notation with 6 ^s and 6 hexadecimal digits:

\documentclass{article}
\usepackage{fontspec}
\newfontfamily{\hifont}{NotoSansEgyptianHieroglyphs-Regular}
\begin{document}
I, {\hifont ^^^^^^01316e}, am a bird.
\end{document}

This covers the common case where you just want to typeset a Unicode character for which you have a font that covers it. Many variations and extension are possible:

  • If you don't want to manually specify a font each time you use the character, you can:

    1. use package ucharclasses (I couldn't get it to work in this instance but I didn't try very hard—anyway it works only with XeTeX, not LuaTeX),

    2. use package newunicodechar:

      \documentclass{article}
      \usepackage{fontspec}
      \newfontfamily{\hifont}{NotoSansEgyptianHieroglyphs-Regular}
      \usepackage{newunicodechar}
      \newunicodechar{𓅮}{\hifont 𓅮}
      \begin{document}
      I, 𓅮, am a bird.
      \end{document}
      
    3. (if using Overleaf or some other editor with such bugs) do it manually (caveat: see last point below):

      \documentclass{article}
      \usepackage{fontspec}
      \newfontfamily{\hifont}{NotoSansEgyptianHieroglyphs-Regular}
      \catcode"1316E=\active
      \def ^^^^^^01316e{{\hifont \char"1316E}}
      \begin{document}
      I, ^^^^^^01316e, am a bird.
      \end{document}
      
  • If you don't have a font that covers your desired character, or if you're using pdfTeX instead of XeTeX/LuaTeX, you can use workarounds:

    1. Try to find a package that has defined that shape somehow (try The Comprehensive LATEX Symbol List),

    2. Include an image as graphics

    3. Draw it using TikZ etc.

  • Finally, you can typeset the character by the position of its glyph among the font's slots. Typically (for a well-behaved Unicode font) this will be the same as the Unicode codepoint, so you just use either \char (or its LaTeX wrapper \symbol where \symbol{#1} means \char #1\relax): you can use either hexadecimal (like the 1316E mentioned in the question) prefixed with a double quote, or the decimal equivalent (78190). All four are equivalent:

    \documentclass{article}
    \usepackage{fontspec}
    \newfontfamily{\hifont}{NotoSansEgyptianHieroglyphs-Regular}
    \begin{document}
    I, {\hifont \symbol{"1316E} \symbol{78190} \char "1316E \char 78190}, am a bird.
    \end{document}
    

    with \char or \symbol

    (There's also \Uchar like \char.)

  • If this doesn't work and shows an incorrect character, try another font! Else you may really have to look “inside” the font to see where it puts what glyphs to use \char or \symbol; for this see Mico's answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.