5

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?

  • 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. – Zizheng Yang Feb 29 '20 at 04: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 '20 at 05:31
  • Thanks. I have tried but it works exactly the same. – Zizheng Yang Feb 29 '20 at 05:37
  • As for , it is a pictograph from Unicode. – Zizheng Yang Feb 29 '20 at 05:38
  • 1
    @Mico Noto Sans Egyptian Hieroglyphs, and some others. – Cicada Feb 29 '20 at 05:47
  • @ZizhengYang You must use a font containing the glyph. – Cicada Feb 29 '20 at 05:48
  • Thank you very much, but can you be more specific, I mean, what should I do on overleaf? – Zizheng Yang Feb 29 '20 at 05:53
  • @ZizhengYang Sorry, I don't use Overleaf; are there instructions for loading a font onto there? Or does Overleaf only have its own fonts? Some instructions: https://www.overleaf.com/learn/latex/Questions/I_have_a_custom_font_I%27d_like_to_load_to_my_document._How_can_I_do_this%3F – Cicada Feb 29 '20 at 06:04
  • 1
    @ZizhengYang Overleaf has the complete set of Noto fonts "as included in Ubuntu 18.04": https://www.overleaf.com/learn/latex/Questions/What_OTF/TTF_fonts_are_supported_via_fontspec%3F So tryfont "Noto Sans Egyptian Hieroglyphs" with fontspec package. Otherwise, you have to upload it via the menu, apparently. – Cicada Feb 29 '20 at 06:09
  • I imagine that this question must have been asked at least a hundred times on this site, yet I can't find good/canonical duplicates. Here are a couple that I know because I answered: 1, 2, 3. – ShreevatsaR Feb 29 '20 at 07:02
  • @ShreevatsaR - Maybe my answer can serve, from now on, as the canonical answer for questions related to the typesetting of glyphs with "high" Unicode numbers. :-) – Mico Mar 01 '20 at 14:08
  • This looks like a bug in Overleaf, because locally you don't need all those acrobatics and can just use directly (with the font specified). – ShreevatsaR Mar 01 '20 at 14:34
  • @Mico IMO in the typical one one doesn't even need to work with the character's codepoint, and extracting the font's table should only be an action of last resort (if you're using one nonstandard font, imagine the work needed if you'd like to switch to another font…). Posted an alternative answer de-emphasizing that approach :) – ShreevatsaR Mar 01 '20 at 17:16

2 Answers2

7

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

user202729
  • 7,143
Mico
  • 506,678
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.

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149