![打印 unicode 字形及其代码点](https://linux22.com/image/319180/%E6%89%93%E5%8D%B0%20unicode%20%E5%AD%97%E5%BD%A2%E5%8F%8A%E5%85%B6%E4%BB%A3%E7%A0%81%E7%82%B9.png)
是否可以定义一个宏,并调用它charwithcodepoint
,以便
\charwithcodepoint{A}
排放相当于
\texttt{A} (U+0041)
其他代码点也类似。如果不行,我可以做相反的事情吗codepointwithchar
?
\codepointwithchar{U+0041}
发出相当于
\texttt{A} (U+0041)
我想这样做是为了记录解析器。是否有支持此功能的软件包?
引擎pdftex
和输入文件是UTF-8。
答案1
新版本采用单个 UTF-8 字符或单个 ASCII 字母命令序列,例如\#
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{1D400}{\textbf{\textrm{A}}}% for demo only
% code mostly from the 2015/10/01 latex release inputenc)
\makeatletter
\def\charwithcodepointb#1{%
\texttt{#1}
(%
U+%
\expandafter\UTFviii@hexnumber\expandafter{%
\the\numexpr\expandafter\decode@UTFviii\detokenize{#1}\relax})%
}
\gdef\decode@UTFviii#1\relax{%
\expandafter\UTFviii@cleanup
\the\numexpr\dec@de@UTFviii#1\relax)))))\@empty}
\gdef\UTFviii@cleanup#1)#2\@empty{#1}
\def\d@c@de@UTFviii#1{%
\dec@de@UTFviii{#1}}
\gdef\dec@de@UTFviii#1{%
\ifx\relax#1%
\else
\ifnum`#1>"EF
((((`#1-"F0)%
\else
\ifnum`#1>"DF
(((`#1-"E0)%
\else
\ifnum`#1>"BF
((`#1-"C0)%
\else
\ifnum`#1>"7F
)*64+(`#1-"80)%
\else
+`#1 %
\fi
\fi
\fi
\fi
\expandafter\dec@de@UTFviii
\fi}
\gdef\UTFviii@hexnumber#1{%
\ifnum#1<"10 0\fi
\ifnum#1<"100 0\fi
\ifnum#1<"1000 0\fi
\UTFviii@hexnumb@r{#1}}
\gdef\UTFviii@hexnumb@r#1{%
\ifnum#1>15 %
\expandafter\UTFviii@hexnumb@r\expandafter{\the\numexpr(#1-8)/16\relax}%
\fi
\UTFviii@hexdigit{\numexpr#1\ifnum#1>0-((#1-8)/16)*16\fi\relax}%
}
\gdef\UTFviii@hexdigit#1{\ifcase\numexpr#1\relax
0\or1\or2\or3\or4\or5\or6\or7\or8\or9\or
A\or B\or C\or D\or E\or F\fi}
\def\charwithcodepoint#1{%
\ifcat\relax\noexpand#1%
\expandafter\expandafter\expandafter\charwithcodepointb\expandafter\@gobble\string#1
\else
\charwithcodepointb{#1}%
\fi}
\makeatother
\begin{document}
\charwithcodepoint{A}
\charwithcodepoint{Á}
\charwithcodepoint{