summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/ddphonism
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2019-09-01 21:36:04 +0000
committerKarl Berry <karl@freefriends.org>2019-09-01 21:36:04 +0000
commit899ff83bf3e9cd5dd91bb1da6c52596d7534255e (patch)
tree1a54e8dadbf71f262f7febb7b65226378419902e /Master/texmf-dist/tex/latex/ddphonism
parent743d65ddc6fa01add37aa1136fba86d3adddb577 (diff)
ddphonism (1sep19)
git-svn-id: svn://tug.org/texlive/trunk@52009 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/ddphonism')
-rw-r--r--Master/texmf-dist/tex/latex/ddphonism/ddphonism.sty456
1 files changed, 321 insertions, 135 deletions
diff --git a/Master/texmf-dist/tex/latex/ddphonism/ddphonism.sty b/Master/texmf-dist/tex/latex/ddphonism/ddphonism.sty
index 76f3e028ce8..4ae54d3e63d 100644
--- a/Master/texmf-dist/tex/latex/ddphonism/ddphonism.sty
+++ b/Master/texmf-dist/tex/latex/ddphonism/ddphonism.sty
@@ -5,12 +5,12 @@
%% 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.]
+[2019/09/01 v0.2 Dodecaphonic diagrams: twelve-tone matrices, clock diagrams, etc.]
-\RequirePackage{ifthen}
+\RequirePackage{etoolbox}
\RequirePackage{xparse}
\RequirePackage{tikz}
\RequirePackage{xstring}
@@ -26,41 +26,131 @@
\DeclareExpandableDocumentCommand{\Evaluation}{m}{\int_eval:n {#1}}
\ExplSyntaxOff
-\newcounter{Dfirst}
\newcounter{Dsize}
+\newcommand{\DsizeMake}[1]{%
+ \setcounter{Dsize}{0}%
+ \foreach \n in {#1}{%
+ \stepcounter{Dsize}%
+ }%
+}
-\newcommand{\DsizeHead}[1]{
- \setcounter{Dsize}{0}
- \setcounter{Dfirst}{-1}
-
- \foreach \n in {#1}{
- \ifnum\theDfirst=-1
- \setcounter{Dfirst}{\n}
- \fi
- \stepcounter{Dsize}
+% Only with numbers.
+\newcounter{Dfirst}
+\newcommand{\DheadMake}[1]{%
+ \setcounter{Dfirst}{-1}%
+ \foreach \n in {#1}{%
+ \ifnum\theDfirst=-1%
+ \setcounter{Dfirst}{\n}%
+ \fi%
+ }%
+}
+
+% Only when DsizeMake is already done.
+\newcounter{Dmod}
+\newcommand{\Modulo}[1]{%
+ \setcounter{Dmod}{#1}%
+ \loop%
+ \ifnum\theDmod>\Evaluation{\theDsize-1}%
+ \setcounter{Dmod}{\Evaluation{\theDmod-\theDsize}}%
+ \repeat%
+ \ifnum\theDmod<0%
+ \setcounter{Dmod}{\Evaluation{\theDmod+\theDsize}}%
+ \repeat%
+ \theDmod%
+}
+
+\newif\ifdmatrixLines
+\newif\ifdmatrixOutside
+\newif\ifdmatrixInside
+\newif\ifdmatrixV
+\newif\ifdmatrixH
+\newif\ifdmatrixTikz
+\pgfkeys{
+ /dmatrix/.is family
+ , /dmatrix
+ , default/.style =
+ { lines = false
+ , outside lines = false
+ , inside lines = false
+ , sep = 1
+ , vsep = 1
+ , hsep = 1
+ , no tikz = false
}
+ , no tikz/.is if=dmatrixTikz
+ , lines/.is if=dmatrixLines
+ , outside lines/.is if=dmatrixOutside
+ , inside lines/.is if=dmatrixInside
+ , vlines/.is if=dmatrixV
+ , hlines/.is if=dmatrixH
+ , sep/.estore in=\dmatrixSep
+ , vsep/.estore in=\dmatrixVsep
+ , hsep/.estore in=\dmatrixHsep
}
-\newcommand{\Modulo}[1]{
- \ifnum#1>\Evaluation{\theDsize-1}
- \Evaluation{#1-\theDsize}
- \else\ifnum#1<0
- \Evaluation{#1+\theDsize}
- \else #1
- \fi\fi
+\newcommand{\DLOH}{%
+ \draw (0.05*\dmatrixSep*\dmatrixHsep,0) --%
+ (\theDsize*\dmatrixSep*\dmatrixHsep+0.05*\dmatrixSep*\dmatrixHsep,0);%
+ \draw (0.05*\dmatrixSep*\dmatrixHsep,-\theDsize*0.5*\dmatrixSep*\dmatrixVsep) -- %
+ (\theDsize*\dmatrixSep*\dmatrixHsep+0.05*\dmatrixSep*\dmatrixHsep,-\theDsize*0.5*\dmatrixSep*\dmatrixVsep);%
}
-\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}
+\newcommand{\DLOV}{%
+ \draw (0.05*\dmatrixSep*\dmatrixHsep,0) -- %
+ (0.05*\dmatrixSep*\dmatrixHsep,-\theDsize*0.5*\dmatrixSep*\dmatrixVsep);%
+ \draw (\theDsize*\dmatrixSep*\dmatrixHsep+0.05*\dmatrixSep*\dmatrixHsep,0) -- %
+ (\theDsize*\dmatrixSep*\dmatrixHsep+0.05*\dmatrixSep*\dmatrixHsep,-\theDsize*0.5*\dmatrixSep*\dmatrixVsep);
+}
+
+\newcommand{\DLIH}{%
+ \draw (0.05*\dmatrixSep*\dmatrixHsep,-\xD*0.5*\dmatrixSep*\dmatrixVsep) -- %
+ (\theDsize*\dmatrixSep*\dmatrixHsep+0.05*\dmatrixSep*\dmatrixHsep,-\xD*0.5*\dmatrixSep*\dmatrixVsep);%
+}
+
+\newcommand{\DLIV}{%
+ \draw (\xD*\dmatrixSep*\dmatrixHsep+0.05*\dmatrixSep*\dmatrixHsep,0) -- %
+ (\xD*\dmatrixSep*\dmatrixHsep+0.05*\dmatrixSep*\dmatrixHsep,-\theDsize*0.5*\dmatrixSep*\dmatrixVsep);%
+}
+
+\newcommand{\dmatrix}[2][]{%
+ \DsizeMake{#2}%
+ \DheadMake{#2}%
+ %
+ \pgfkeys{/dmatrix, default, #1}%
+ %
+ \ifdmatrixTikz\else%
+ \begin{tikzpicture}%
+ \fi%
+ \foreach [count=\nj] \j in {#2} {%
+ \foreach [count=\ni] \i in {#2} {%
+ \draw node at
+ ( \ni*\dmatrixSep*\dmatrixHsep-0.5*\dmatrixSep*\dmatrixHsep
+ , -\nj*\dmatrixSep*\dmatrixVsep/2+0.25*\dmatrixSep*\dmatrixVsep) {%
+ \Modulo{\Evaluation{\i-\j+\theDfirst}}%
+ };%
+ }%
+ }%
+ \foreach \xD in {1,...,\Evaluation{\theDsize-1}} {%
+ \ifdmatrixLines
+ \DLOH\DLOV\DLIH\DLIV
+ \fi
+ \ifdmatrixOutside
+ \DLOH\DLOV
+ \fi
+ \ifdmatrixInside
+ \DLIH\DLIV
+ \fi
+ \ifdmatrixH
+ \DLOH\DLIH
+ \fi
+ \ifdmatrixV
+ \DLOV\DLIV
+ \fi
+ }%
+ %
+ \ifdmatrixTikz\else%
+ \end{tikzpicture}%
+ \fi%
}
@@ -69,45 +159,82 @@
\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
+\tikzstyle{ddiagram}=[minimum height=0pt,inner sep=0pt,outer sep=0pt,scale=0.65]
+
+\newif\ifddiagramTikz
+\newif\ifddiagramNoNum
+\newif\ifddiagramNoArr
+\pgfkeys{
+ /ddiagram/.is family
+ , /ddiagram
+ , default/.style =
+ { name =\empty%
+ , up =\empty%
+ , no tikz = false
+ , no numbers = false
+ , no arrow = false
+ , xshift = 0
+ , yshift = 0
+ , arrow shift = 2.5
+ }
+ , no tikz/.is if=ddiagramTikz
+ , no numbers/.is if=ddiagramNoNum
+ , no arrow/.is if=ddiagramNoArr
+ , name/.estore in=\ddiagramName
+ , up/.estore in=\ddiagramUp
+ , xshift/.estore in=\ddiagramX
+ , yshift/.estore in=\ddiagramY
+ , arrow shift/.estore in=\ddiagramArrS
+}
+
+\newcounter{Dprev}
+\newcommand{\Dvar}{}
+\newcommand{\ddiagram}[2][]{%
+ \DsizeMake{#2}%
+ \DheadMake{#2}%
+ %
+ \pgfkeys{/ddiagram, default, #1}%
+ %
+ \ifdefequal{\ddiagramUp}{\empty}%
+ {\renewcommand{\Dvar}{\theDfirst}}% if empty
+ {\renewcommand{\Dvar}{\ddiagramUp}}% if not empty
+ %
+ \ifddiagramTikz\else%
+ \begin{tikzpicture}[ddiagram,rotate=360*\Dvar/\theDsize]%
+ \fi%
+ \foreach \x in {0,...,\Evaluation{\theDsize-1}} {%
+ \ifddiagramNoNum\else
+ \node [xshift=\ddiagramX,yshift=\ddiagramY] at (90-360*\x/\theDsize:2) {\x};%
+ \fi
+ \node [xshift=\ddiagramX,yshift=\ddiagramY] (\x) at (90-360*\x/\theDsize:1.6) {};%
+ };%
+ %
+ \setcounter{Dprev}{-1}%
+ \foreach \x in {#2}{%
+ \ifnum \theDprev=\theDfirst%
+ \ifddiagramNoArr
+ \draw [xshift=\ddiagramX,yshift=\ddiagramY] (\theDprev) -- (\x);%
\else
- \draw (\theanterior) -- (\x);
- \fi\fi
- \setcounter{anterior}{\x}
- };
- \draw (\theanterior) -- (\theDDfirst);
-
- \node at (0,0) [circle,fill=white] {#3};
- \end{tikzpicture}
+ \draw [xshift=\ddiagramX,yshift=\ddiagramY,
+ decoration=
+ {markings,mark=at position 0.099*\ddiagramArrS with
+ {\arrow[scale=1.25,>=triangle 45]{>}}},
+ postaction={decorate}
+ ] (\theDprev) -- (\x);%
+ \fi
+ \else \ifnum \theDprev=-1 \else%
+ \draw [xshift=\ddiagramX,yshift=\ddiagramY] (\theDprev) -- (\x);%
+ \fi\fi%
+ \setcounter{Dprev}{\x}%
+ };%
+ \draw [xshift=\ddiagramX,yshift=\ddiagramY] (\theDprev) -- (\theDfirst);%
+ %
+ \ifdefequal{\ddiagramName}{\empty}%
+ {}% if empty
+ {\node [xshift=\ddiagramX,yshift=\ddiagramY] at (0,0) [circle,fill=white] {\ddiagramName};}% if not empty
+ \ifddiagramTikz\else%
+ \end{tikzpicture}%
+ \fi%
}
@@ -115,89 +242,148 @@
% Dihedral diagrams
\tikzstyle ddihedralArrow=[decoration=
- {markings,mark=at position 1 with {\arrow[scale=1.5,>=angle 60]{>}}},
- postaction={decorate}]
+{markings,mark=at position 1 with {\arrow[scale=1.5,>=angle 60]{>}}},
+postaction={decorate}]
+\tikzstyle{ddihedral}=[inner sep=0,minimum height=18pt]
+
+\newif\ifddihedralTikz
+\newif\ifddihedralItalics
\pgfkeys{
/ddihedral/.is family, /ddihedral,
- default/.style = {t = 0, c = 0, s = 0, v = 0},
+ default/.style =
+ { t = 0, c = 0, s = 0, v = 0
+ , no tikz=false
+ , new t = T, new c = C, new s = S, new v = V
+ , no italics = false
+ },
+ no tikz/.is if=ddihedralTikz,
t/.estore in = \ddihedralT,
c/.estore in = \ddihedralC,
s/.estore in = \ddihedralS,
v/.estore in = \ddihedralV,
+ no italics/.is if=ddihedralItalics,
+ new t/.estore in = \ddihedralNewT,
+ new c/.estore in = \ddihedralNewC,
+ new s/.estore in = \ddihedralNewS,
+ new v/.estore in = \ddihedralNewV,
+}
+
+\newif\ifdarrowsTikz
+\pgfkeys{
+ /darrows/.is family, /darrows,
+ default/.style = {no tikz=false},
+ no tikz/.is if=darrowsTikz,
+}
+\newcommand{\darrows}[2][]{%
+ \DsizeMake{#2}%
+ %
+ \pgfkeys{/darrows, default, #1}%
+ %
+ \ifdarrowsTikz\else%
+ \begin{tikzpicture}%
+ \fi%
+ \draw foreach \x in {0,...,\Evaluation{\theDsize-1}} {%
+ (90-360*\x/\theDsize:2.5) node[circle] (\x) {}%
+ };%
+ \foreach \x [count=\y] in {#2} {%
+ \draw [style=ddihedralArrow] (90-360*\Evaluation{\y-1}/\theDsize:1.25) -- (\x);%
+ };%
+ \ifdarrowsTikz\else%
+ \end{tikzpicture}%
+ \fi%
}
-\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
- \ };
+\newcommand\ddihedral[2][]{%
+ \DsizeMake{#2}%
+ %
+ \pgfkeys{/ddihedral, default, #1}%
+ %
+ \ifddihedralTikz\else%
+ \begin{tikzpicture}[ddihedral]%
+ \fi%
+ \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[no tikz]{#2}%
+ %
+ \node at (0,0) [very thin,draw,circle, fill=white] {%
+ {\ifddihedralItalics\else\it\fi%
+ \ifodd\ddihedralV%
+ \ddihedralNewV\else%
+ \ifnum\ddihedralC=0%
+ \ifodd\ddihedralS\else%
+ \ifnum\ddihedralT=0%
+ \ddihedralNewT$^0$%
+ \fi\fi\fi\fi%
+ \ifnum\ddihedralC=0%
+ \else \ddihedralNewC$^{\ddihedralC}$\fi%
+ \ifodd\ddihedralS%
+ \ddihedralNewS\fi%
+ \ifnum\ddihedralT=0%
+ \else \ddihedralNewT$^{\ddihedralT}$\fi}%
+ };%
+ \ifddihedralTikz\else%
+ \end{tikzpicture}%
+ \fi%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Rows
-\newcount\fooo
+\pgfkeys{
+ /drow/.is family, /drow,
+ default/.style = {sep=\arraycolsep},
+ sep/.estore in = \drowSep,
+}
+
\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)
- }
+\newlength{\Dvarr}
+
+\newcommand{\drow}[2][]{%
+ \DsizeMake{#2}%
+ %
+ \pgfkeys{/drow, default, #1}%
+ \setlength{\Dvarr}{\arraycolsep}
+ \setlength{\arraycolsep}{\drowSep}
+ %
+ \ifnum\theDsize=0%
+ \ensuremath{\left(\right)}%
+ \else\ifnum\theDsize=1%
+ \ensuremath{%
+ \left(\begin{array}{*{\theDsize}c}%
+ 0\\%
+ #2\\%
+ \end{array}\right)%
+ }%
+ \else%
+ \def\TableDDdata{}%
+ \setcounter{myDDcntr}{0}%
+ \loop%
+ \addto\TableDDdata{\themyDDcntr\stepcounter{myDDcntr} &}%
+ \stepcounter{myDDcntr}%
+ \ifnum\themyDDcntr<\Evaluation{\theDsize-1}%
+ \repeat%
+ \addto\TableDDdata{\themyDDcntr \\}%
+ \setcounter{myDDcntr}{0}%
+ %
+ \ensuremath{%
+ \left(\begin{array}{*{\theDsize}c}%
+ \TableDDdata%
+ \StrSubstitute{#2}{,}{&}\\%
+ \end{array}\right)%
+ }%
+ \fi\fi%
+ \setlength{\arraycolsep}{\Dvarr}
}
\endinput