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}
5
  • 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
    Commented Dec 25, 2022 at 13:14
  • Use tex.stackexchange.com/questions/377613/… and tex.stackexchange.com/questions/235421/… and adapt that to specify the exact font that contain the character.
    – user202729
    Commented Dec 25, 2022 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
    Commented Dec 25, 2022 at 14:36
  • ok, I think I found it, will fight with that further fileformat.info/info/unicode/char/1f40d/fontsupport.htm
    – kosciej16
    Commented Dec 25, 2022 at 14:40
  • It works for copy-pasted symbol but still cannot make it works by using unicode number.
    – kosciej16
    Commented Dec 25, 2022 at 15:04

2 Answers 2

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

2
  • Thank you for full example! One thing - could you elaborate a bit on why symbol is better than char?
    – kosciej16
    Commented Dec 25, 2022 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
    Commented Dec 25, 2022 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.

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .