I've just found

How do I enter an arbitrary Unicode code point into my document?

but I want to do the same with pdfTeX, not LuaTeX. Is this possible?


I assume, the Unicode character is given as four hexadecimal digits (or eight hexadecimal digits for a surrogate pair). Then macro \uni performs the following steps:

  • First the hex string is extended to eight hexadecimal digits for a full hexadecimal representation of a Unicode character in encoding UTF-32BE.
  • \pdfunescapehex converts the hexadecimal digits to the four bytes in encoding UTF-32BE.
  • Package stringenc converts from UTF-32BE to UTF-8.
  • \scantokens is used to convert the string of inactive characters (category code 12/other) to active characters, needed for encoding utf8 of package inputenc.
  • Since the definition is fragile, the macro is made robust by \DeclareRobustCommand.
  • Additionally, support for hyperref is added, so that the defined macro \uni can be used in bookmarks.

Full example:


        \ifnum"#1<"100000 0\fi
        \ifnum"#1<"10000 0\fi
        \ifnum"#1<"1000 0\fi
        \ifnum"#1<"100 0\fi
        \ifnum"#1<"10 0\fi
    \endlinechar=-1 %

% hyperref support

\section{Musical note \uni{266A} in title}
Symbols: \uni{266A}, \uni{B1}, \uni{20AC}, \uni{DF}.


  • For what it's worth, I just enter the Unicode character directly into my document. There's no general reason to keep everything in ASCII, although you may have specific requirements otherwise.
    – Derek
    Sep 16 '16 at 3:01

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.