| 1 |
%% This is file 'tikz-bagua.sty' |
| 2 |
%% |
| 3 |
%% Developed by WANG Xu |
| 4 |
%% Copyright (C) 2021 by WANG Xu <[email protected]> |
| 5 |
%% |
| 6 |
%% It may be distributed and/or modified under the conditions of |
| 7 |
%% the LaTeX Project Public License (LPPL). |
| 8 |
%% |
| 9 |
\NeedsTeXFormat{LaTeX2e} |
| 10 |
\ProvidesPackage{tikz-bagua}[2022/08/04 v1.01 draw Bagua in Yijing via tikz package] |
| 11 |
|
| 12 |
\RequirePackage{tikz} |
| 13 |
\RequirePackage{xstring} |
| 14 |
\RequirePackage{bitset} |
| 15 |
\RequirePackage{xparse} |
| 16 |
\RequirePackage{xintexpr} |
| 17 |
|
| 18 |
%%\taiji[<scale>] |
| 19 |
\NewDocumentCommand\taiji{sO{1}}{% taiji yinyang |
| 20 |
\IfDecimal{#2}{% % check whether #2 is decimal number |
| 21 |
\IfBooleanTF#1% %check whether a star is exist |
| 22 |
{% begin of a star seen |
| 23 |
\begin{tikzpicture}[baseline=1.9074,scale=0.17646*#2] |
| 24 |
\fill plot [domain=0:180,smooth] ({\x*1/180*cos(\x-90)},{\x*1/180*sin(\x-90)+1}) -- (0,2) arc (90:-90:1) plot [domain=0:180,smooth] ({\x*1/180*cos(\x+90)},{\x*1/180*sin(\x+90)+1}); |
| 25 |
\draw (0,1) circle (1); |
| 26 |
|
| 27 |
\fill (0.25,0.25/pi+1) circle ({0.25/exp(1)}); |
| 28 |
\fill [fill=white] (-0.25,-0.25/pi+1) circle ({0.25/exp(1)}); |
| 29 |
\end{tikzpicture} |
| 30 |
}% end of a star seen |
| 31 |
{% |
| 32 |
\begin{tikzpicture}[baseline=1.9074,scale=0.17646*#2] |
| 33 |
\fill plot [domain=0:180,smooth] ({\x*1/180*cos(\x-90)},{\x*1/180*sin(\x-90)+1}) -- (0,2) arc (90:-90:1) plot [domain=0:180,smooth] ({\x*1/180*cos(\x+90)},{\x*1/180*sin(\x+90)+1}); |
| 34 |
\draw (0,1) circle (1); |
| 35 |
\end{tikzpicture} |
| 36 |
}% |
| 37 |
}{\@latex@error{Error! Please check whether \#1 is decimal number.}{}}% |
| 38 |
} |
| 39 |
|
| 40 |
%%\xtaiji[<scale>] |
| 41 |
\NewDocumentCommand\xtaiji{sO{1}}{% taiji yinyang |
| 42 |
\IfDecimal{#2}{% % check whether #2 is decimal number |
| 43 |
\IfBooleanTF#1% %check whether a star is exist |
| 44 |
{% begin of a star seen |
| 45 |
\begin{tikzpicture}[baseline=1.9074,scale=0.17646*#2] |
| 46 |
\fill (0,0) arc (270:90:0.5) arc (-90:90:0.5) arc (90:-90:1); |
| 47 |
\draw (0,1) circle (1); |
| 48 |
|
| 49 |
\fill [fill=white] (0,0.5) circle ({0.25/exp(1)}); |
| 50 |
\fill (0,1.5) circle ({0.25/exp(1)}); |
| 51 |
\end{tikzpicture} |
| 52 |
}% end of a star seen |
| 53 |
{% |
| 54 |
\begin{tikzpicture}[baseline=1.9074,scale=0.17646*#2] |
| 55 |
\fill (0,0) arc (270:90:0.5) arc (-90:90:0.5) arc (90:-90:1); |
| 56 |
\draw (0,1) circle (1); |
| 57 |
\end{tikzpicture} |
| 58 |
}% |
| 59 |
}{\@latex@error{Error! Please check whether \#1 is decimal number.}{}}% |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
%%\drawliangyi[<yshift>]{<0 or 1>} |
| 64 |
\newcommand\drawliangyi[2][0]{% |
| 65 |
\ifnum #2=0 \draw [line width=0.0816em] (0,#1) -- (1em/3,#1) (2em/3,#1) -- (1em,#1)%;% |
| 66 |
\else% |
| 67 |
\ifnum #2=1 \draw [line width=0.0816em] (0,#1) -- (1em,#1)%;% |
| 68 |
\else \node {Error!}% |
| 69 |
\fi% |
| 70 |
\fi% |
| 71 |
} |
| 72 |
|
| 73 |
%%\liangyi{<0 or 1>}[<scale>] |
| 74 |
\NewDocumentCommand\liangyi{mO{1}}{% |
| 75 |
\IfInteger{#1}{% |
| 76 |
\xintifboolexpr{#1 == 0 || #1 == 1}{% |
| 77 |
\begin{tikzpicture}[baseline=-0.3em,scale=#2]% |
| 78 |
\drawliangyi{#1};% |
| 79 |
\end{tikzpicture}}{\@latex@error{Error! Please check whether \#1 is 0 or 1.}{}}% |
| 80 |
}{\@latex@error{Error! Please check whether \#1 is integer.}{}}% |
| 81 |
} |
| 82 |
|
| 83 |
%%\sixiang{<binary>}[<scale>] |
| 84 |
%%\sixiang*{<decimal>}[<scale>] |
| 85 |
\NewDocumentCommand\sixiang{smO{1}}{% \sixiang{11}=\sixiang*{3} |
| 86 |
\IfInteger{#2}{% begin of if #2 is an integer |
| 87 |
\IfBooleanTF#1% |
| 88 |
{\xintifboolexpr{#2 >= 0 && #2 < 4}% begin of If a star is seen |
| 89 |
{\bitsetSetDec{sixiangdec}{#2}% |
| 90 |
\begin{tikzpicture}[baseline=-0.5em,scale=#3]%[baseline=-0.225em] |
| 91 |
\foreach \j in {1,0} |
| 92 |
{ |
| 93 |
\drawliangyi[-\j*0.408em]{\bitsetGet{sixiangdec}{\j}}; |
| 94 |
} |
| 95 |
\end{tikzpicture}}{\@latex@error{Error! Please check whether 0<=\#1<4.}{}}% |
| 96 |
}% end of If a star is seen |
| 97 |
{\StrLen{#2}[\lengthforbinary]%begin of binary |
| 98 |
\xintifboolexpr{\lengthforbinary=1 || \lengthforbinary=2}{% |
| 99 |
\bitsetSetBin{sixiangbin}{#2}% |
| 100 |
\begin{tikzpicture}[baseline=-0.5em,scale=#3]%[baseline=-0.225em] |
| 101 |
\foreach \j in {1,0} |
| 102 |
{ |
| 103 |
\drawliangyi[-\j*0.408em]{\bitsetGet{sixiangbin}{\j}}; |
| 104 |
} |
| 105 |
\end{tikzpicture}% |
| 106 |
}{\@latex@error{Error! Please check whether 0<=\#1<=11.}{}}%end of binary |
| 107 |
}% If no star is seen |
| 108 |
}% end of if #2 is an integer |
| 109 |
{\@latex@error{Error! Please check whether \#1 is integer.}{}}% else #2 is not an integer |
| 110 |
} |
| 111 |
|
| 112 |
%%\bagua{<binary>}[<scale>] |
| 113 |
%%\bagua*{<decimal>}[<scale>] |
| 114 |
\NewDocumentCommand\bagua{smO{1}}{% \bagua{101}=\bagua*{5} |
| 115 |
\IfInteger{#2}{% begin of if #2 is an integer |
| 116 |
\IfBooleanTF#1% |
| 117 |
{%% begin of If a star is seen |
| 118 |
\bitsetSetDec{baguadec}{#2}% |
| 119 |
\xintifboolexpr {#2 >= 0 && #2 <8} |
| 120 |
{% |
| 121 |
\begin{tikzpicture}[baseline=-0.714em,scale=#3] |
| 122 |
\foreach \j in {2,1,0} |
| 123 |
{ |
| 124 |
\drawliangyi[-\j*0.408em]{\bitsetGet{baguadec}{\j}}; |
| 125 |
} |
| 126 |
\end{tikzpicture}% |
| 127 |
}% |
| 128 |
{\@latex@error{Error! Please check whether 0<=\#1<8.}{}}% |
| 129 |
}%% end of If a star is seen |
| 130 |
{%% begin of If no star is seen |
| 131 |
\bitsetSetBin{baguabin}{#2}% |
| 132 |
\StrLen{#2}[\lengthforbinary]% |
| 133 |
\xintifboolexpr{\lengthforbinary > 0 && \lengthforbinary <4}% |
| 134 |
{% |
| 135 |
\begin{tikzpicture}[baseline=-0.714em,scale=#3] |
| 136 |
\foreach \j in {2,1,0} |
| 137 |
{ |
| 138 |
\drawliangyi[-\j*0.408em]{\bitsetGet{baguabin}{\j}}; |
| 139 |
} |
| 140 |
\end{tikzpicture}% |
| 141 |
}% |
| 142 |
{\@latex@error{Error! Please check whether 0<=\#1<1000.}{}}% |
| 143 |
}%% end of If no star is seen |
| 144 |
}% end of if #2 is an integer |
| 145 |
{\@latex@error{Error! Please check whether \#1 is integer.}{}}% else #2 is not an integer |
| 146 |
} |
| 147 |
|
| 148 |
%%\Bagua[<2 default, 8>]{<binary, octal>}[<scale>] |
| 149 |
%%\Bagua*{<decimal>}[<scale>] |
| 150 |
\NewDocumentCommand\Bagua{sO{2}mO{1}}{% \bagua{101110}=\bagua[8]{56}=\bagua*{46} |
| 151 |
\IfInteger{#3}{% begin of if #3 is an integer |
| 152 |
\IfBooleanTF#1% |
| 153 |
{%% begin of If a star is seen |
| 154 |
\bitsetSetDec{baguadec}{#3}% |
| 155 |
\xintifboolexpr {#3 >= 1 && #3 < 64}% |
| 156 |
{% |
| 157 |
\begin{tikzpicture}[baseline=-0.714em,scale=#4] |
| 158 |
\foreach \j in {5,4,...,0} |
| 159 |
{ |
| 160 |
\drawliangyi[-\j*0.1632em]{\bitsetGet{baguadec}{\j}}; |
| 161 |
} |
| 162 |
\end{tikzpicture}% |
| 163 |
}{\@latex@error{Error! Please check whether 0<=\#2<64.}{}}% |
| 164 |
}%% end of If a star is seen |
| 165 |
{%% begin of If no star is seen |
| 166 |
\ifnum#2=2% |
| 167 |
\bitsetSetBin{baguabin}{#3}% |
| 168 |
\StrLen{#3}[\lengthforbinary]% |
| 169 |
\xintifboolexpr{\lengthforbinary >= 1 && \lengthforbinary < 7}% |
| 170 |
{% |
| 171 |
\begin{tikzpicture}[baseline=-0.714em,scale=#4] |
| 172 |
\foreach \j in {5,4,...,0} |
| 173 |
{ |
| 174 |
\drawliangyi[-\j*0.1632em]{\bitsetGet{baguabin}{\j}}; |
| 175 |
} |
| 176 |
\end{tikzpicture}% |
| 177 |
}{\@latex@error{Error! Please check whether 0<=\#2<1000000.}{}}% |
| 178 |
\else% |
| 179 |
\ifnum#2=8% |
| 180 |
\bitsetSetOct{baguaoct}{#3}% |
| 181 |
\StrLen{#3}[\lengthforoct]% |
| 182 |
\xintifboolexpr{\lengthforoct == 1 || \lengthforoct == 2}% |
| 183 |
{% |
| 184 |
\begin{tikzpicture}[baseline=-0.714em,scale=#4] |
| 185 |
\foreach \j in {5,4,...,0} |
| 186 |
{ |
| 187 |
\drawliangyi[-\j*0.1632em]{\bitsetGet{baguaoct}{\j}}; |
| 188 |
}% |
| 189 |
\end{tikzpicture}% |
| 190 |
}{\@latex@error{Error! Please check whether 0<=\#2<100.}{}}% |
| 191 |
\else{\@latex@error{Error! Please check whether \#1 is default (2) or 8.}{}}\fi% |
| 192 |
\fi% |
| 193 |
}%% end of If no star is seen |
| 194 |
}% end of if #3 is an integer |
| 195 |
{\@latex@error{Error! Please check whether \#2 is integer.}{}}% else #3 is not an integer |
| 196 |
} |
| 197 |
|
| 198 |
\endinput |
| 199 |
%% |
| 200 |
%% End of file 'tikz-bagua.sty' |