1

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!

6
  • 1
    pdflatex will understand the UTF-8 あ but you need to define that to make that character. You can not use a Unicode font, you must use some custom fonts each containg at most 256 characters, There are packages that set this up (with a very limited range of font options) but it is much easier (and vastly more font options available) if you use xelatex or lualatex that can use opentype unicode fonts or platex that is specifically set up for Japanese. Commented Sep 13, 2021 at 8:47
  • As I said 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. Do we have something like this?
    – Master.AKA
    Commented Sep 13, 2021 at 8:51
  • the hard part is getting the symbol to print using pdftex, if you have that set up specifying it by number or by the character is easy enough Commented Sep 13, 2021 at 8:55
  • I see. How do you manage to bring up the set up? If I understood correctly, to get access to all the 143,859 characters, I have to use some package, right? Can you name some of them? Huge thanks again.
    – Master.AKA
    Commented Sep 13, 2021 at 8:58
  • 2
    You'd have to load almost 600 fonts to get access to 143,859 as each font can have at most 256 characters. That isn't going to happen. Commented Sep 13, 2021 at 9:27

1 Answer 1

2

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.

3
  • Thank you for your detailed answer. Still I can't realize why pdfLatex doesn't just print the character?
    – Master.AKA
    Commented Sep 13, 2021 at 9:19
  • 1
    every font in pdftex has 256 characters numbered 0 to 255. It can not typeset using Unicode fonts. So to print CJK using pdflatex you need hundreds of fonts with custom encodings each having a 256 character range and a complicated set of macros working out for each input character which position in which font is needed. This has been done for one or two fonts by the CJK package but it is fragile and is exactly why tex now has extensions luatex and xetex that natively understand unicode, but you are specifically asking to use classic tex which was designed before Unicode existed. @Master.AKA Commented Sep 13, 2021 at 9:25
  • Now I see. Is it safe to move on from pdfLatex to LuaTex from now on? Will I loose any functionality?
    – Master.AKA
    Commented Sep 13, 2021 at 9:27

You must log in to answer this question.

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