2

In LuaTeX, we can use \CID and \UTF in luatexja-otf to insert characters via their CIDs:

\documentclass{ctexart}
\usepackage{luatexja-otf}
\setCJKmainfont{KozMinPr6N-Regular.otf}

\begin{document}
森\UTF{9DD7}外と内田百\UTF{9592}とが\UTF{9AD9}島屋に行く。

\CID{7652}飾区の\CID{13706}野家,\CID{1481}城市,葛西駅,高崎と\CID{8705}\UTF{FA11}
\end{document}

They are inherited from upTeX. So how to use CID-key to insert some character in XeTeX?

For Kozuka Mincho Pr6N, the glyph order is the same as CID order (Adobe Japan1-6). But other fonts may not use the same order, so \XeTeXglyph etc cannot be (at least, directly) used here.

2

A proof of concept using the cidmap files in TeX Live.

\documentclass{article}
\usepackage{xparse,xeCJK}

\setCJKmainfont{Hiragino Mincho ProN}

\ExplSyntaxOn

\NewDocumentCommand{\readCIDfile}{m}
 {
  \readcid_file:n { #1 }
 }

\NewDocumentCommand{\CID}{m}
 {
  \use:c { CID#1 }
 }
\NewDocumentCommand{\UTF}{m}
 {
  \symbol { \int_from_hex:n { #1 } }
 }

\ior_new:N \g_readcid_file_stream

\cs_new_protected:Nn \readcid_file:n
 {
  \ior_open:Nn \g_readcid_file_stream { #1 }
  \ior_str_map_inline:Nn \g_readcid_file_stream
   {
    \__readcid_line:n { ##1 }
   }
 }


\cs_new_protected:Nn \__readcid_line:n
 {
  \__readcid_line_aux:w #1 \q_stop
 }

\cs_new_protected:Npn \__readcid_line_aux:w #1 ~ #2 \q_stop
 {
  \str_if_eq:nnF { #1 } { #2 }
   {
    \str_case_e:nnF { \str_range:nnn { #2 } { 1 } { 3 } }
     {
      {/un}{ \__readcid_def_uni:nn { #1 } { #2 } }
      {/Ja}{ \__readcid_def_japan:nn { #1 } { #2 } }
      {./n}{ }
     }
     { \__readcid_def:nn { #1 } { #2 } }
   }
 }

\cs_new_protected:Nn \__readcid_def:nn
 {
  \str_if_in:nnTF { #1 } { . }
   {
    \__readcid_def:w #1 - { #2 }
   }
   {
    \__readcid_def_do:nn { #1 } { #2 }
   }
 }
\cs_new_protected:Npn \__readcid_def:w #1..#2 - #3
 {
  \int_step_inline:nnn { #1 } { #2 }
   {
    \__readcid_def_do:nn { ##1 } { #3 }
   }
 }
\cs_new_protected:Nn \__readcid_def_do:nn
 {
  \cs_new:cpx {CID#1} { \UTF { #2 } }
 }

\cs_new_protected:Nn \__readcid_def_uni:nn
 {
  \str_if_in:nnTF { #1 } { . }
   {
    \__readcid_def_uni_multi:w #1 - { #2 }
   }
   {
    \__readcid_def_uni_do:nn { #1 } { #2 }
   }
 }
\cs_new_protected:Npn \__readcid_def_uni_multi:w #1..#2 - #3
 {
  \int_step_inline:nnn { #1 } { #2 }
   {
    \__readcid_def_uni_do:nn { ##1 } { #3 }
   }
 }
\cs_new_protected:Nn \__readcid_def_uni_do:nn
 {
  \cs_new:cpx {CID#1} { \UTF { \str_range:nnn { #2 } { 5 } { 8 } } }
 }

\cs_new_protected:Nn \__readcid_def_japan:nn
 {
  \str_if_in:nnTF { #1 } { . }
   {
    \__readcid_def_japan_multi:w #1 - { #2 }
   }
   {
    \__readcid_def_japan_do:nn { #1 } { #2 }
   }
 }
\cs_new_protected:Npn \__readcid_def_japan_multi:w #1..#2 - #3
 {
  \int_step_inline:nnn { #1 } { #2 }
   {
    \__readcid_def_japan_do:nn { ##1 } { #3 }
   }
 }
\cs_new_protected:Nn \__readcid_def_japan_do:nn
 {
  \cs_new:cpx {CID#1} { \CID { \__readcid_japan_strip:w #2 \q_stop } }
 }
\cs_new:Npn \__readcid_japan_strip:w #1.#2.#3 \q_stop { #2 }

\ExplSyntaxOff


\readCIDfile{/usr/local/texlive/2019/texmf-dist/fonts/cid/fontforge/Adobe-Japan1-6.cidmap}

\begin{document}

森\UTF{9DD7}外と内田百\UTF{9592}とが\UTF{9AD9}島屋に行く。

森鷗外と内田百閒とが髙島屋に行く。

\CID{7652}飾区の\CID{13706}野家,\CID{1481}城市,葛西駅,高崎と\CID{8705}\UTF{FA11}

\CID{7652}飾区の𠮷野家,葛城市,葛西駅,高崎と髙﨑

\end{document}

There is no CID 7652, as far as I can see in Adobe-Japan1-6.

enter image description here

Some explanations: the first in the .cidmap line contains the number of entries and we don't need it. The other lines have the form

<CID> <translation>

or

<CID>..<CID> <translation>

for multiple entries pointing to the same UTF character.

Many of the translations are just a Unicode code point in hexadecimal, others have the form

/uni<pqrs>.<other specs>

or

/Japan1.<CID>.<other specs>

so these macros strip /uni and the part from the period on. In the Unicode or /uni cases, I define \CID<CID> to do \UTF{<code>}. Otherwise \CID<CID> does \CID{<CID>}.

The macro \CID{<number>} expands to \CID<number> (define via the analog of \csname...\endcsname).

A full specification of the .cidmap files might improve the translation.

|improve this answer|||||
  • The point is that several CIDs may map to a single Unicode code point. Here, cid1481 and cid7652 both map to U+845B 葛, but they are different glyphs (look different). That's why I need to use CID rather than UTF. – stone-zeng Apr 1 '19 at 8:29
  • @stone-zeng I said it is a proof of concept. – egreg Apr 1 '19 at 10:43

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.