3

I would like to print unicode character like this one using it's unicode code. I know there is \char command that allows me to print symbols (e.g. \char48 prints 0). But \char1F40D is evaluated to (\char1)F40D.

How can I print symbol by their unicode number?

\documentclass[12pt]{article}
\begin{document}
\begin{itemize}
    \item Snake: \some_command{U+1F40D}
\end{itemize}
\end{document}
kosciej16
  • 133
  • 1
    Please explain what you mean by didn't work. Additionally there aren't any fonts that covers all of unicode in one go so you might also need to load a specific font to access a rarely used symbol – daleif Dec 25 '22 at 13:14
  • Use https://tex.stackexchange.com/questions/377613/solve-unicode-char-is-not-set-up-for-use-with-latex-without-special-handling-o/377729#377729 and https://tex.stackexchange.com/questions/235421/why-are-some-unicode-characters-missing-when-using-xetex-and-ubuntu-mono and adapt that to specify the exact font that contain the character. – user202729 Dec 25 '22 at 13:15
  • @daleif as far as I understood after reading different topics I should start with having a proper font but... I have no idea how to find font having snake in the question. I see nothing there indicating where it could be, searching web didn't help either. – kosciej16 Dec 25 '22 at 14:36
  • ok, I think I found it, will fight with that further https://www.fileformat.info/info/unicode/char/1f40d/fontsupport.htm – kosciej16 Dec 25 '22 at 14:40
  • It works for copy-pasted symbol but still cannot make it works by using unicode number. – kosciej16 Dec 25 '22 at 15:04

2 Answers2

3

First off, you need either XeLaTeX or LuaLaTeX. Moreover, Unicode points are denoted with hexadecimal notation, so if you want to pass it to TeX, you need to prefix the number with ".

However, \char is not really the best command:

\symbol{"1F40D}

is much better.

% compile with LuaLaTeX

\documentclass{article} \usepackage{fontspec}

\setfontface{\emojis}{Symbola}% or whatever font in your system \setfontface{\coloredemojis}{Apple Color Emoji}[Renderer=HarfBuzz]

\begin{document}

{\emojis\symbol{"1F40D}}

{\coloredemojis\symbol{"1F40D}}

\end{document}

enter image description here

egreg
  • 1,121,712
  • Thank you for full example! One thing - could you elaborate a bit on why symbol is better than char? – kosciej16 Dec 25 '22 at 17:13
  • 1
    @kosciej16 The main reason is that with \char"1F40D X the space would disappear, which doesn't happen with \symbol{"1F40D} X. Using TeX primitives directly is not for the casual user, which is the reason why LaTeX provides wrappers for several of them. – egreg Dec 25 '22 at 17:15
0

I needed to use extra " so \char"1F40D correctly printed my snake.

There is another syntax for that - ^^48 for 256 characters and ^^^^2302 for 65536 characters.

kosciej16
  • 133
  • I would appreciate if someone could explain is it just special syntax or part of some concept in latex I don't understand. – kosciej16 Dec 25 '22 at 15:09
  • Not a complete answer but here a couple of useful links: https://tex.stackexchange.com/q/62725/82917, https://tex.stackexchange.com/a/404650/82917 – campa Dec 25 '22 at 16:55