[Tex/LaTex] Unicode with PdfLaTeX

pdftexunicode

I would like to get Alchemy symbols working in PdfLaTeX. I do not have access to XeTeX or LuaTex as I am using Tex Writer on the iPad. Here are two minimal examples.

The first one works.

    \documentclass{article}
    \usepackage[T1]{fontenc}
    \usepackage{textcomp}
    \usepackage[utf8x]{inputenc}

    \begin{document}
    \unichar{"00E4}
    \unichar{"20AC}
    \end{document}

This one does not compile:

    \documentclass{article}
    \usepackage[T1]{fontenc}
    \usepackage{textcomp}
    \usepackage[utf8x]{inputenc}

    \begin{document}
    \unichar{"00E4}
    \unichar{"1F701}
    \end{document}

Here is the error message:

l.9 \unichar{"1F701}

? 
! Emergency stop.
 ...                                              

l.9 \unichar{"1F701}

Unicode character 128769 = U+1F701:
ALCHEMICAL SYMBOL FOR AIR
Character is not defined in uni-*.def files.
Enter I! to define the glyph.

Here is how much of TeX's memory you used:
 1717 strings out of 493024
 24829 string characters out of 6124273
 70825 words of memory out of 5000000
 5308 multiletter control sequences out of 15000+600000
 4403 words of font info for 15 fonts, out of 8000000 for 9000
 1141 hyphenation exceptions out of 8191
 23i,0n,17p,304b,478s stack positions out of 5000i,500n,10000p,200000b,80000s
!  ==> Fatal error occurred, no output PDF file produced!

Best Answer

TeX is a typesetter: its job is to pick up glyphs (shapes) from a font, and decide where to place them on a page. So information about those shapes needs to be available to TeX.

For interpreting your input, by default TeX treats each byte individually. With \usepackage[utf8x]{inputenc} you can let TeX know that it should interpret sequences of bytes as Unicode characters, as specified by the UTF-8 encoding. For example, when you type โ‚ฌ into the file, it will understand you mean the Unicode character U+20AC (EURO SIGN), as the file will contain the bytes corresponding to the UTF-8 encoding of that character. This is equivalent to manually entering \unichar{"20AC}.

But understanding that you intended a particular Unicode character isn't enough: so what? TeX still needs to know what to do with it.

For example:

  • รค U+00E4 LATIN SMALL LETTER A WITH DIAERESIS is defined in texmf-dist/tex/latex/ucs/data/uni-0.def as \"a (which TeX knows how to do)
  • โ‚ฌ U+20AC EURO SIGN is defined in texmf-dist/tex/latex/ucs/data/uni-32.def as \ifx\euro\undefined\texteuro\else\euro\fi which in turn is made somehow via glyphs available in TeX

The character you want, U+1F701 ALCHEMICAL SYMBOL FOR AIR ๐Ÿœ has no such definition. This explains the error message you're seeing.


To solve this, you need to give TeX some instructions for how to produce the shape for that symbol, when given that character:

  1. The easiest would be to use XeTeX/LuaTeX and use a Unicode font (like Noto Sans Symbols) that contains a glyph for that character. (Then the instruction is to just pick that glyph and use it.)
  2. You could find a TeX-compatible font that contains the character, and define U+1F701 to use that glyph from that font. (E.g. there are some astrological symbols in packages wasysym, marvosym, starfont and horoscop, which have some overlap with alchemical symbols.)
  3. You could find images for the glyphs, and the instruction would be to include the corresponding images as graphics. (This would give you maximum freedom in the shape of the symbols.)
  4. You could draw the images from "inside TeX", with something like Metapost or TikZ.

The last one is a solution that seems to have been used by the author of an earlier question about alchemical symbols and by the author of an alchemy-latex repo on Github.

For the latter, see this PDF of all its symbols, and borrowing its definition from alchemy.sty, we can do:

\documentclass{article}
\usepackage[utf8x]{inputenc}
% \usepackage[T1]{fontenc}
\usepackage{tikz}

% From https://github.com/michaelplews/alchemy-latex/blob/9adf10c/alchemy.sty#L30,L42
\newcommand{\air}[1]{%
\begin{tikzpicture}[#1]%
    \draw (0, 0)
    -- ++ (-60:1.5ex)
    -- ++ (180:1.5ex)
    -- ++ (60:1.5ex)
    -- cycle;
    \draw (0, 0)
       ++ (270:0.5ex)
       ++ (0:0.75ex)
    -- ++ (180:1.5ex);
\end{tikzpicture}%
}

% \DeclareUnicodeCharacter{1F701}{\air{}}
\DeclareUnicodeCharacter{128769}{\air{}}

\begin{document}

\air{}

\unichar{"1F701}

๐Ÿœ

\end{document}

giving

air air air

Related Question