[Tex/LaTex] Displaying the 64 hexagrams of the Yi Jing (using Unicode range 4DC0 up 4DFF)

cjkunicodexetex

I'm writing a book and I need to include the range of Unicode characters 4DC04DFF up to display the hexagrams of the Chinese book Yi Jing http://en.wikipedia.org/wiki/I_Ching

I've used the various packages and I've also read all the questions about how to use Unicode here in the Community. I am a beginner in LaTeX.

My environment: MikTeX with TeXnicCenter with option XeLaTeX, Windows 8.
I saved my document in UTF-8.

Just a comment (it is solved): I can display all Chinese characters using the CJK package?

Here we have an example. But how to display each hexagram in LaTeX?

http://en.wikipedia.org/wiki/I_Ching_hexagram_01

Please, I ask for a complete example that works for my environment described. Do not write things like "do this" or "use it."

I hope understanding and help.

Below is an example of the packages that I am using

\documentclass[a4paper,12pt,twoside,openright]{book}
\usepackage[T1]{fontenc}
\usepackage[brazil,portuguese]{babel}
\usepackage{lmodern}    % Type1-font for non-english texts and characters
\usepackage{graphicx}   % For loading graphic files
\usepackage{amssymb, amsmath, pxfonts}  % permite simbolos matemáticos
\usepackage{ae}
\usepackage{aecompl}
\usepackage{fontspec}
%----------------------------------------------
% Unicode environment
%----------------------------------------------
\usepackage{autofe}
\usepackage{ucs}
\usepackage{newunicodechar}
\usepackage[utf8x]{inputenc}
\usepackage[unicode=true]{hyperref}
\hypersetup{unicode=true}
\usepackage{cmap}
\usepackage{CJKutf8}
\DeclareUnicodeCharacter{4DC0}{\hex1}
\newunicodechar{4DC2}{\hex2}
\catcode"4DC0=\qian
%----------------------------------------------
\begin{document}

$hex1$    $hex2$
\qian
\unichar{4DC0}
\char"4DC0
Hexagram \hex1

\end{document}

Best Answer

The ucs and inputenc package must not be used with XeLaTeX as well as fontenc, in general, but the last one may have its uses; never load ae and aecompl: they are obsolete.

CJKutf8 package is a mixture of CJK package and inputenc package with utf8 option. it is also not used in XeLaTeX.

You don't need any CJK package in order to print some glyphs: just find a font that has them. On my system, I found DejaVu Sans. So I defined a macro that takes as argument the glyph's number (from 0 to 63, it would be easy to start at 1, if you so desire).

For some reason, apparently due to how xeCJK decides what's Chinese and what's not, one has to declare the font twice: for hexagrams it has to be declared with \newCJKfontfamily and for trigrams with \newfontfamily (or \newfontface that's more efficient for a font that's not required to change shape according to the context).

\documentclass{article}
\usepackage{fontspec}
\usepackage{xeCJK}

\setmainfont{Times New Roman}
\setCJKmainfont{LiSong Pro} % or another font supporting Chinese

\newCJKfontfamily{\dejavusanszh}{DejaVu Sans} % this font has the required glyphs
\newfontface{\dejavusans}{DejaVu Sans} % this font has the required glyphs

\newcommand{\iching}[1]{{\dejavusanszh\char\numexpr"4DC0+#1}}
\newcommand{\trigram}[1]{{\dejavusans\char\numexpr"2630+#1}}

\begin{document}

Yì Jīng 易經 - Hex: \iching{8} \trigram{7}

\trigram{0} \trigram{1} \trigram{2} \trigram{3}
\trigram{4} \trigram{5} \trigram{6} \trigram{7}


\iching{0}
\iching{1}
\iching{2}
\iching{3}
\iching{4}
\iching{5}
\iching{6}
\iching{7}

\iching{8}
\iching{9}
\iching{10}
\iching{11}
\iching{12}
\iching{13}
\iching{14}
\iching{15}

\iching{16}
\iching{17}
\iching{18}
\iching{19}
\iching{20}
\iching{21}
\iching{22}
\iching{23}

\iching{24}
\iching{25}
\iching{26}
\iching{27}
\iching{28}
\iching{29}
\iching{20}
\iching{31}

\iching{32}
\iching{33}
\iching{34}
\iching{35}
\iching{36}
\iching{37}
\iching{38}
\iching{39}

\iching{40}
\iching{41}
\iching{42}
\iching{43}
\iching{44}
\iching{45}
\iching{46}
\iching{47}

\iching{48}
\iching{49}
\iching{50}
\iching{51}
\iching{52}
\iching{53}
\iching{54}
\iching{55}

\iching{56}
\iching{57}
\iching{58}
\iching{59}
\iching{60}
\iching{61}
\iching{62}
\iching{63}

\end{document}

enter image description here

An alternative method is to declare Yijing Hexagrams Symbols as non-CJK characters in xeCJK:

\documentclass{article}

\usepackage{xeCJK}
\xeCJKsetcharclass{"4DC0}{"4DFF}{0} % set Yijing Hexagrams Symbols as non-CJK characters

\setmainfont{Times New Roman}
\setCJKmainfont{LiSong Pro} % or another font supporting Chinese

\newfontface{\dejavusans}{DejaVu Sans} % this font has the required glyphs

\newcommand{\iching}[1]{{\dejavusans\char\numexpr"4DC0+#1}}
\newcommand{\trigram}[1]{{\dejavusans\char\numexpr"2630+#1}}

\begin{document}

Yì Jīng 易經 - Hex: \iching{8} \trigram{7}
......

\end{document}