summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/digiconfigs/digiconfigs.sty
blob: cd014e5036c278a8d7d6d670c289c6514fa98e26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
%%
%% This package be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2003/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% The Current Maintainer of this work is Lars Madsen (daleif@imf.au.dk).
%%

% HISTORY
% 20060620 (daleif) package released
% 20060620 (daleif) a few \expandafter's could be saved, thanks MH for
%                   that comment
% 20060620 (daleif) removed dependency of calc package

\ProvidesPackage{digiconfigs}[2006/06/20 v0.5 by Lars 'daleif' Madsen]
\RequirePackage{amsmath}

\def\SCS@circ{o}
\def\SCS@bullet{.}
\def\SCS@blank{b}
\def\SCS@cdot{c}
\def\SCS@stop{X}
\newcommand\setCircleChar[1]{\def\SCS@circ{#1}}
\newcommand\setBulletChar[1]{\def\SCS@bullet{#1}}
\newcommand\setBlankChar[1]{\def\SCS@blank{#1}}
\newcommand\setCdotChar[1]{\def\SCS@cdot{#1}}


\def\SCS@circ@symbol{\circ}
\def\SCS@bullet@symbol{\bullet}
\def\SCS@cdot@symbol{\cdot}
\newcommand\setCircleSymbol[1]{\def\SCS@circ@symbol{#1}}
\newcommand\setBulletSymbol[1]{\def\SCS@bullet@symbol{#1}}
\newcommand\setCdotSymbol[1]{\def\SCS@cdot@symbol{#1}}


%\def\SCS@matrix@env{bmatrix}
%\newcommand\setMatrixEnv[1]{\def\SCS@matrix@env{#1}}

\def\SCS@matrix@start{\begin{pmatrix}}
\def\SCS@matrix@end{\end{pmatrix}}
\newcommand\setMatrixStart[1]{\def\SCS@matrix@start{#1}}
\newcommand\setMatrixEnd[1]{\def\SCS@matrix@end{#1}}



\newif\ifSCS@notdone
\newtoks\SCS@input
\newtoks\SCS@output
\newcounter{SCS@numtokens}
\newcounter{SCS@cols}
\newcounter{SCS@rows}

\def\SCS@token@Pop#1(into:)#2{%
  \edef\act{\noexpand\SCS@token@SplitOff\the#1%
    (head:)\noexpand#2(tail:)\noexpand#1}%
  \act}
\def\SCS@token@SplitOff#1#2(head:)#3(tail:)#4{\def#3{#1}#4={#2}}

\def\SCS@xsplit#1x#2\delim{\def\SCS@maxrows{#1}\def\SCS@maxcols{#2}}
\def\SCS@parseX#1x#2\END{
  \ifx\\#2\\% => ingen x
    \def\SCS@maxrows{#1}\def\SCS@maxcols{#1}
  \else
    \def\SCS@maxrows{#1} \SCS@parseXc #2 \fi}
\def\SCS@parseXc#1x{\def\SCS@maxcols{#1}}
\def\SCS@ParseArg#1{\SCS@parseX #1x\END}


\newcommand\SCS@config[1]{% #1 er en tokenlist
  \ifnum\value{SCS@numtokens}<\SCS@maxtokens%
    \SCS@token@Pop#1(into:)\first% tag første token af, husk at ' ' ignoreres
    \ifx\first\SCS@circ%
      % hvis \first = \Mo (o) tilføjes \circ
      \stepcounter{SCS@numtokens}%
      \stepcounter{SCS@cols}%
      \expandafter\addto@hook\expandafter\SCS@output\expandafter{\SCS@circ@symbol}%
    \else%
      \ifx\first\SCS@bullet%
        % hvis \first = \Mb (.) tilføjes \bullet
        \stepcounter{SCS@numtokens}%
        \stepcounter{SCS@cols}%
        \expandafter\addto@hook\expandafter\SCS@output\expandafter{\SCS@bullet@symbol}%
      \else%
        \ifx\first\SCS@cdot%
          \stepcounter{SCS@numtokens}%
          \stepcounter{SCS@cols}%
          \expandafter\addto@hook\expandafter\SCS@output\expandafter{\SCS@cdot@symbol}%
        \else%
          \ifx\first\SCS@blank%
            % hvis \first = \Mbl (b for blank) skal der ikke indsættes
            % noget kun evt &-tegn 
            \stepcounter{SCS@numtokens}%
            \stepcounter{SCS@cols}%
            \relax%
          \else %
            % resten ignoreres
            \SCS@notdonefalse%
          \fi%
        \fi%
      \fi%
    \fi%
    \ifSCS@notdone%
      \ifnum\value{SCS@cols}<\SCS@maxcols%
        % tilføj en & mellem punkterne i en række
        \addto@hook\SCS@output{&}%
      \else%
        % cols=\maxcols => ny linie
        \setcounter{SCS@cols}{0}%
        \ifnum\value{SCS@rows}<\SCS@maxrows%
          \addto@hook\SCS@output{\\}%
        \fi%
      \stepcounter{SCS@rows}%
      \fi%
    \fi%
    \SCS@notdonetrue%
    \ifx\first\SCS@stop%
      \PackageWarning{stereoconfigs}{%
        String too short, expected \SCS@maxtokens\space
        chars but only found \theSCS@numtokens^^J
      }{}%
      \relax%
    \else%
      \SCS@config{#1}%
    \fi%
   \fi%
}

\def\SCS@default@size{4}
\newcommand\setDefaultMatrixSize[1]{\def\SCS@default@size{4}}

\newcommand\dconfig[2][\SCS@default@size]{%
  \begingroup%
  \SCS@ParseArg{#1}%
%  \setcounter{SCS@rows}{\SCS@maxrows * \SCS@maxcols}%
  \setcounter{SCS@rows}{\SCS@maxrows}
  \multiply \c@SCS@rows by \SCS@maxcols
  \edef\SCS@maxtokens{\theSCS@rows}%
  \setcounter{SCS@cols}{0}%
  \setcounter{SCS@rows}{0}%
  \setcounter{SCS@numtokens}{0}%
  \SCS@notdonetrue%
  \SCS@input\expandafter{#2X}%
  \SCS@config\SCS@input%
  \SCS@matrix@start%
    \the\SCS@output%
  \SCS@matrix@end%
  \endgroup%
}