Debian Codegraph @

texmf-dist/tex/latex/tonevalue/tonevalue.sty

raw
1 \NeedsTeXFormat{LaTeX2e}
2 \ProvidesPackage{tonevalue}
3 [2021/07/25 v1.0 LaTeX Package (Tone value: visualising tone value patterns)]
4
5 \RequirePackage{etoolbox}
6 \RequirePackage{listofitems}
7 \RequirePackage{xstring}
8 \RequirePackage{xkeyval}
9 \RequirePackage{xcolor}
10 \RequirePackage{tikz}
11 \usetikzlibrary{positioning,decorations.markings,arrows}
12 \RequirePackage{contour}
13
14 % package options
15 % font command
16 \DeclareOptionX{fontcmd}[\sffamily]{\def\toneVisualisationFontCmd{#1}}
17 % colors
18 \DeclareOptionX{defaultcolors}{
19 \definecolor{1}{HTML}{7E2639}
20 \definecolor{2}{HTML}{FF98AF}
21 \definecolor{3}{HTML}{AD724A}
22 \definecolor{4}{HTML}{DE6A1C}
23 \definecolor{5}{HTML}{426579}
24 \definecolor{6}{HTML}{86B8F3}
25 \definecolor{7}{HTML}{769164}
26 \definecolor{8}{HTML}{ACC551}
27 }
28 % contour around numbers
29 \DeclareOptionX{draft}{\contournumber{50}}
30 \DeclareOptionX{contourlength}[0.075em]{\contourlength{#1}}
31 \DeclareOptionX{contournumber}[1000]{\contournumber{#1}}
32 \ExecuteOptionsX{
33 contourlength=0.075em,
34 contournumber=1000,
35 fontcmd=\sffamily,
36 }
37 \ProcessOptionsX*\relax
38 \ProcessOptionsX\relax
39
40 \def\xjoinbycomma<#1#2>{%
41 \ifx\relax#1
42 \else
43 #1,\xjoinbycomma<#2>%
44 \fi
45 }
46 \def\sendiauToListStr#1{\xjoinbycomma<#1\relax>}
47
48 % environment for unt's visualisation approach
49 \define@key{untVisualisation}{minmax}{\def\untVisualisation@minmax{#1}}
50 \define@key{untVisualisation}{scale}{\def\untVisualisation@scale{#1}}
51 \define@key{untVisualisation}{showlabels}{\def\untVisualisation@showlabels{#1}}
52 \newenvironment{untVisualisation}[1][]{
53 \setkeys{untVisualisation}{minmax={1,5}, scale=1, showlabels=false}
54 \setkeys{untVisualisation}{#1}
55 \toneVisualisationFontCmd
56 % mxn minmax
57 \pgfmathparse{{\untVisualisation@minmax}[0]}
58 \edef\xstart{\pgfmathresult}
59 \pgfmathparse{{\untVisualisation@minmax}[1]}
60 \edef\xend{\pgfmathresult}
61 \pgfmathparse{{\untVisualisation@minmax}[0]}
62 \edef\ystart{\pgfmathresult}
63 \pgfmathparse{{\untVisualisation@minmax}[1]}
64 \edef\yend{\pgfmathresult}
65 \tikzpicture[scale=\untVisualisation@scale]
66 \begin{scope}[rotate=45, scale=1.4142, line width=0.1em, gray]
67 \foreach \x in {\xstart,...,\xend}
68 \draw (\x,\ystart) -- (\x,\yend);
69 \foreach \y in {\ystart,...,\yend}
70 \draw (\xstart,\y) -- (\xend,\y);
71 \end{scope}
72 \begin{scope}[gray]
73 \expandafter\ifstrequal\expandafter{\untVisualisation@showlabels}{true}{
74 \node at (0,\ystart*2-0.5) {\large\bfseries\xstart};
75 \node at (-\xend+0.6767+\xstart-1,\yend+0.6767+\ystart-1) {\large\bfseries\xend};
76 \node at (\xend-0.6767-\xstart+1,\yend+0.6767+\ystart-1) {\large\bfseries\xend};
77 \node (xAxisArrowTip) at (-\xend+0.6767+\xstart-1+\xend/2-\xstart/2,\yend+0.6767+\ystart-1-\yend/2+\ystart/2) {};
78 \node[below left=1.25em of xAxisArrowTip] (xAxisArrowTail) {};
79 \draw[line width=0.125em, -angle 60] (xAxisArrowTail) -- (xAxisArrowTip);
80 \node (yAxisArrowTail) at (\xend-0.6767-\xstart+1-\xend/2+\xstart/2,\yend+0.6767+\ystart-1-\yend/2+\ystart/2) {};
81 \node[below right=1.25em of yAxisArrowTail] (yAxisArrowTip) {};
82 \draw[line width=0.125em, -angle 60] (yAxisArrowTail) -- (yAxisArrowTip);
83 }{}
84 \end{scope}
85 }{
86 \endtikzpicture
87 }
88
89 % draw a point
90 \newcommand{\drawuntpoint}[9][]{
91 % override tikz options, background color, coordinates, tone name, tone value in numbers, label position
92 \node[draw, shape=circle, scale=#9*0.75, inner sep=0.1em, fill, #2, text=white, #1, xshift=#7, yshift=#8]
93 ({#5}{#4})
94 at ({#3}[0],{#3}[1])
95 {#4};
96 \node[#2, #6 = 0pt of {#5}{#4}] {\contour{white}{#5}};
97 }
98
99 \newcounter{sumOfPitchHeights}
100 % keys of options
101 \define@key{untpoint}{label}{\def\untpoint@label{#1}}
102 \define@key{untpoint}{tikzoptions}{\def\untpoint@tikzoptions{#1}}
103 \define@key{untpoint}{bgcolor}{\def\untpoint@bgcolor{#1}}
104 \define@key{untpoint}{xshift}{\def\untpoint@xshift{#1}}
105 \define@key{untpoint}{yshift}{\def\untpoint@yshift{#1}}
106 \define@key{untpoint}{scale}{\def\untpoint@scale{#1}}
107 \define@key{untpoint}{stem}{\def\untpoint@stem{#1}}
108 % drawing interface
109 \newcommand{\untpoint}[3][]{
110 % options, tone value in numbers, tone name
111 \setkeys{untpoint}{label=above, tikzoptions={}, bgcolor=black, xshift=0pt, yshift=0pt, scale=1, stem=false}
112 \setkeys{untpoint}{#1}
113
114 \StrGobbleRight{\sendiauToListStr{#2}}{2}[\sendiaulistStr] % readlist cannot parse trailing comma
115 \readlist\sendiaulist{\sendiaulistStr}
116 \edef\len{\listlen\sendiaulist[]}
117
118 \ifnum0\len=1
119 \drawuntpoint[{\untpoint@tikzoptions}]{\untpoint@bgcolor}{0,{#2}[0]*2}{#3}{#2}
120 {\untpoint@label}{\untpoint@xshift}{\untpoint@yshift}{\untpoint@scale}
121 \else
122 \setcounter{sumOfPitchHeights}{0}
123 \pgfmathparse{\len-2}
124 % calculate the sum of pitch heights
125 \foreach \pitchHeightIndex in {0,...,{\pgfmathresult}} {
126 \pgfmathparse{{#2}[\pitchHeightIndex]}
127 \addtocounter{sumOfPitchHeights}{\pgfmathresult}
128 \pgfmathparse{{#2}[\pitchHeightIndex+1]}
129 \addtocounter{sumOfPitchHeights}{\pgfmathresult}
130 }
131 % draw the point
132 \drawuntpoint[\untpoint@tikzoptions]
133 {\untpoint@bgcolor}
134 {{-({#2}[0])+{#2}[\len-1]},{\thesumOfPitchHeights/(\len-1)}}
135 {#3}{#2}
136 {\untpoint@label}{\untpoint@xshift}{\untpoint@yshift}{\untpoint@scale}
137 % draw the stem
138 \expandafter\ifstrequal\expandafter{\untpoint@stem}{true}{
139 \draw[\untpoint@bgcolor, line width=0.1em] ({-({#2}[0])+{#2}[\len-1]},{#2}[0]+{#2}[\len-1]) -- ({#2}{#3});
140 }{}
141 \fi
142 }
143
144 % link points
145 \define@key{linkuntpoints}{color}{\def\linkuntpoints@color{#1}}
146 \define@key{linkuntpoints}{bend}{\def\linkuntpoints@bend{#1}}
147 \newcommand{\linkuntpoints}[3][]{
148 \setkeys{linkuntpoints}{color=black, bend={}}
149 \setkeys{linkuntpoints}{#1}
150
151 \begin{scope}[
152 decoration={
153 markings,
154 mark=at position 0.5 with {\arrow[scale=0.875]{angle 60}}}
155 ]
156 \draw[postaction={decorate}, line width=0.15em, \linkuntpoints@color] (#2) to [\linkuntpoints@bend] (#3);
157 \end{scope}
158 }
159
160 \endinput