Unicode in pdfLatex says it only supports up to 255 code points when I’m trying to use a Japanese letter

characterspdftexsymbolsunicode

I hope you are doing well. This is a very quick question.

I want to insert some characters from the Unicode table in a formula but unfortunately I can't find a way. I would appreciate your help. For now the character I want to have is the Hiragana character あ. I insist to do this by giving the Unicode code point and not by copy pasting the character so that pdfLatex understands it. I also prefer if I can be able to do this on pfLatex.

Update:

Just to emphasize, I don't want to type something like

let $あ : \mathbb{R} \rightarrow \mathbb{R}$ be a real function.

What I'd like to do is to use some command like this:

 Let $\symbol{U+3042}: \mathbb{R} \rightarrow \mathbb{R}$ be a real function.

I want to feed it the code and get the character and I'd like for this to work out on pdfLatex. Do we have such a thing?

Update 2: As @DavidCarlisle mentioned using pdfLaTeX wasn't just the efficient idea to use single Unicode characters. I changed my compiler to XeLatex and now commands like

\char"3042

and

$\text{\char"3042}:\mathb{R}\rightarrow\mathbb{R}$

work just fine for tying any unicode characters that I like!

Best Answer

If you use lualatex or xelatex this is easy to set up using any Opentype font that covers Japanese

enter image description here

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Microsoft YaHei}
\begin{document}
U+3042 HIRAGANA LETTER A is [あ] [\symbol{"3042}] [^^^^3042]
\end{document}

With pdflatex it is more complicated. This shows how to make \unisymbol{"3042} and あ make the same output (a boxed ? here) so to complete the job you need to change the \fbox{?} to something, perhaps \includegraphics if this is just a one-off symbol, or use a package such as \usepackage{CJK} to set up Japanese in pdftex.

enter image description here


\documentclass{article}
\DeclareUnicodeCharacter{3042}{\fbox{?}}

\makeatletter
\let\@@parse@XML@charref\parse@XML@charref
\let\@@parse@UTFviii@a\parse@UTFviii@a
\let\@@parse@UTFviii@b\parse@UTFviii@b
\newcommand\unisymbol[1]{\count@#1\relax\parse@XML@charref\UTFviii@tmp}
\makeatother

\begin{document}
\makeatletter
\let\parse@XML@charref\@@parse@XML@charref
\let\parse@UTFviii@a\@@parse@UTFviii@a
\let\parse@UTFviii@b\@@parse@UTFviii@b
\makeatother


U+3042 HIRAGANA LETTER A is [あ] [\unisymbol{"3042}]

\end{document}

Or you could use (u)ptex which is a tex variant specifically modified for typesetting Japanese.

Related Question