# Displaying the 64 hexagrams of the Yi Jing (using Unicode range 4DC0 up 4DFF)

I'm writing a book and I need to include the range of Unicode characters 4DC0 - 4DFF 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{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}

• Welcome to TeX.SX! The ucs and inputenc packages must not be used with XeLaTeX (and also ae and aecompl, which should never be used). I'm very dubious also towards CJKutf8. – egreg Sep 9 '13 at 16:51

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}


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}

• Your solution works. But Chinese characters do not appear (and have always worked). If I put as "comments" lines: \setCJKmainfont{DFKai-SB} \ setCJKmonofont MingLiU {} The opposite occurs: the Hexagram and do not appear to be returning Chinese characteres exbidos normally. That is, one or the other (or hexagrams Chinese characters). I made several attempts at combinations. And I found that conflict happens past 2 lines above. I try to put the code but the maximum size is exceeded \begin{document} Yì Jīng 易經 - Hexagrams: \iching{8} and \iching{60} \end{document} – JWainer Sep 9 '13 at 21:29
• @JWainer HTML doesn't work in comments. You asked about those glyphs. Please, explain better in your question what are hexagrams. – egreg Sep 9 '13 at 21:33
• \documentclass{book} % Unicode \usepackage{fontspec} \newfontface{\dejavusans}{DejaVu Sans} % this font has the required glyphs \newcommand{\iching}[1]{{\dejavusans\char\numexpr"4DC0+#1}} % CJK \usepackage{xeCJK} \usepackage{CJK} \usepackage{pinyin} \XeTeXlinebreaklocale "zh" \XeTeXlinebreakskip = 0pt plus 1pt \setmainfont[Mapping=tex-text]{Times New Roman} % rm \setsansfont[Mapping=tex-text]{Arial} % sf \setmonofont{Courier New} % tt \setCJKmainfont{DFKai-SB} \setCJKmonofont{MingLiU} \begin{document} Yì Jīng 易經 - Hex: \iching{8} \end{document} – JWainer Sep 9 '13 at 21:36
• @JWainer Use \newCJKfontfamily instead of \newfontface (move the line after \usepackage{xeCJK}. I don't think you should load CJK and pinyin that aren't thought for XeLaTeX. – egreg Sep 9 '13 at 22:04

You are loading a lot of package which either don't work or will clash with xelatex. To get the glyphs you can use a code like this, but you will have to find a suitable font first.

\documentclass{book}
\usepackage[brazil]{babel}
\usepackage{fontspec}

\begin{document}
{\fontspec{UnicodeBMPFallback.ttf} % replace by a real font with the glyphs
^^^^4dc0
\char"4DC0}

\end{document}

• As another solution, its works. But Chinese characters do not appear (and have always worked). If I put as "comments" lines: \ setCJKmainfont-SB} {DFKai \ setCJKmonofont MingLiU {} The opposite occurs: the Hexagram and do not appear to be returning Chinese characteres exbidos normally. That is, one or the other (or hexagrams Chinese characters). Please, how can I do also appear ideograms and hexagrams? \begin{document} Yì Jīng 易經 {\fontspec{DejaVu Sans} ^^^^4dc0 \char"4DC0} \end{document} – JWainer Sep 9 '13 at 22:05
• @JWainer: No the font I used is a fall back font for unicode. It doesn't contain the actual glyphs but shows only the numbers. I don't know which fonts have the glyphs you are looking for. – Ulrike Fischer Sep 10 '13 at 8:21