From 84ff1351b3ee00a1859a4057fc82b1e822cd148d Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 11 Aug 2019 20:37:58 +0000 Subject: ddphonism (11aug19) git-svn-id: svn://tug.org/texlive/trunk@51864 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/tex/latex/ddphonism/ddphonism.sty | 206 +++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 Master/texmf-dist/tex/latex/ddphonism/ddphonism.sty (limited to 'Master/texmf-dist/tex/latex') diff --git a/Master/texmf-dist/tex/latex/ddphonism/ddphonism.sty b/Master/texmf-dist/tex/latex/ddphonism/ddphonism.sty new file mode 100644 index 00000000000..76f3e028ce8 --- /dev/null +++ b/Master/texmf-dist/tex/latex/ddphonism/ddphonism.sty @@ -0,0 +1,206 @@ +% ddphonism +% +% (c) Celia Rubio Madrigal +% +%% This program can be redistributed and/or modified under the terms +%% of the LaTeX Project Public License Distributed from CTAN archives +%% in directory macros/latex/base/lppl.txt. + +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{ddphonism} +[2019/08/10 v0.1 LaTeX package for twelve-tone matrices, clock diagrams et al.] + +\RequirePackage{ifthen} +\RequirePackage{xparse} +\RequirePackage{tikz} +\RequirePackage{xstring} +\RequirePackage{pgfkeys} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Matrices + +\usetikzlibrary{matrix} + +\ExplSyntaxOn +\DeclareExpandableDocumentCommand{\Evaluation}{m}{\int_eval:n {#1}} +\ExplSyntaxOff + +\newcounter{Dfirst} +\newcounter{Dsize} + +\newcommand{\DsizeHead}[1]{ + \setcounter{Dsize}{0} + \setcounter{Dfirst}{-1} + + \foreach \n in {#1}{ + \ifnum\theDfirst=-1 + \setcounter{Dfirst}{\n} + \fi + \stepcounter{Dsize} + } +} + +\newcommand{\Modulo}[1]{ + \ifnum#1>\Evaluation{\theDsize-1} + \Evaluation{#1-\theDsize} + \else\ifnum#1<0 + \Evaluation{#1+\theDsize} + \else #1 + \fi\fi +} + +\newcommand{\dmatrix}[1]{ + \DsizeHead{#1} + \begin{tikzpicture} + \foreach [count=\nj] \j in {#1} { + \foreach [count=\ni] \i in {#1} { + \draw node at (\ni-0.5,-\nj/2+0.25) { + \Modulo{\Evaluation{\i-\j+\theDfirst}} + }; + } + } + \end{tikzpicture} +} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Diagrams + +\usetikzlibrary{shapes,arrows,decorations.markings,shapes.misc} + +\tikzstyle ddiagramArrow=[decoration= + {markings,mark=at position 0.25 with + {\arrow[scale=1.25,>=triangle 45]{>}}}, + postaction={decorate}] + +\newcounter{anterior} +\newcounter{var} +\newcommand{\ddiagram}[3][-1]{ + \DsizeHead{#2} + \def\theDDfirst{\Evaluation{\Modulo{\theDfirst}}} + + \ifnum #1=-1 + \setcounter{var}{\theDDfirst} + \else + \setcounter{var}{#1} + \fi + + \begin{tikzpicture}[rotate=360*\thevar/\theDsize, + minimum height=0pt,inner sep=0pt,outer sep=0pt,scale=0.65] + \foreach \x in {0,...,\Evaluation{\theDsize-1}} { + \node at (90-360*\x/\theDsize:2) {\x}; + \node (\x) at (90-360*\x/\theDsize:1.6) {}; + }; + + \setcounter{anterior}{-1} + \foreach \xD in {#2}{ + \def\x{\Evaluation{\Modulo{\xD}}} + \ifnum \theanterior=\theDDfirst + \draw [style=ddiagramArrow] (\theanterior) -- (\x); + \else \ifnum \theanterior=-1 + \else + \draw (\theanterior) -- (\x); + \fi\fi + \setcounter{anterior}{\x} + }; + \draw (\theanterior) -- (\theDDfirst); + + \node at (0,0) [circle,fill=white] {#3}; + \end{tikzpicture} +} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Dihedral diagrams + +\tikzstyle ddihedralArrow=[decoration= + {markings,mark=at position 1 with {\arrow[scale=1.5,>=angle 60]{>}}}, + postaction={decorate}] + +\pgfkeys{ + /ddihedral/.is family, /ddihedral, + default/.style = {t = 0, c = 0, s = 0, v = 0}, + t/.estore in = \ddihedralT, + c/.estore in = \ddihedralC, + s/.estore in = \ddihedralS, + v/.estore in = \ddihedralV, +} + +\newcommand{\darrows}[1]{ + \DsizeHead{#1} + \draw foreach \x in {0,...,\Evaluation{\theDsize-1}} { + (90-360*\x/\theDsize:2.5) node[circle] (\x) {} + }; + \foreach \xD [count=\y] in {#1} { + \def\x{\Evaluation{\Modulo{\xD}}} + \draw [style=ddihedralArrow] (90-360*\Evaluation{\y-1}/\theDsize:1.25) -- (\x); + }; +} + +\newcommand\ddihedral[2][]{ + \pgfkeys{/ddihedral, default, #1} + + \tikzset{inner sep=0,minimum height=18pt} + + \DsizeHead{#2} + + \draw foreach \x in {0,...,\Evaluation{\theDsize-1}} { + (\Evaluation{(90+\ddihedralT*360/\theDsize)+(2*\ddihedralS-1)*\x*360/\theDsize}:2.5) + node[very thin,circle,draw] (\x) {\x} + }; + + \draw foreach \x in {0,...,\Evaluation{\theDsize-1}} { + (\Evaluation{(90-\ddihedralC*360/\theDsize)+(2*\ddihedralV-1)*\x*360/\theDsize}:1.25) + node[very thin,circle,draw] {\x} + }; + + \darrows{#2} + + \node at (0,0) [very thin,draw,circle, fill=white] {\ + \ifnum\ddihedralV=0 + \ifnum\ddihedralC=0 + \ifnum\ddihedralS=0 + \ifnum\ddihedralT=0 + P + \fi\fi\fi + \else V \fi + \ifnum\ddihedralC=0 + \else C$^{\ddihedralC}$ \fi + \ifnum\ddihedralS=0 + \else S \fi + \ifnum\ddihedralT=0 + \else T$^{\ddihedralT}$ \fi + \ }; +} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Rows + +\newcount\fooo +\long\def\addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}} +\newcounter{myDDcntr} + +\newcommand{\drow}[1]{ + \DsizeHead{#1} + \def\tabledata{} \fooo=\theDsize + \setcounter{myDDcntr}{0} + \loop + \addto\tabledata{\themyDDcntr\stepcounter{myDDcntr} &} + \advance \fooo -1 + \ifnum \fooo>1 + \repeat + \addto\tabledata{\themyDDcntr \\} + \ensuremath{ + \left(\begin{array}{*{\theDsize}c} + \tabledata + \StrSubstitute{#1}{,}{&}\\ + \end{array}\right) + } +} + +\endinput + + +%% End of file `ddphonism.sty'. \ No newline at end of file -- cgit v1.2.3