summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/ufrgscca/latex/ufrgscca-gen.sty
blob: eb4fa95ff2a9fec93ea4b150d07c0417a41d163f (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
%%%==============================================================================
%% Copyright 2022-23 by Alceu Frigeri
%%
%% This work may be distributed and/or modified under the conditions of
%%
%% * The [LaTeX Project Public License](http://www.latex-project.org/lppl.txt),
%%   version 1.3c (or later), and/or
%% * The [GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html),
%%   version 3 (or later)
%%
%% This work has the LPPL maintenance status *maintained*.
%%
%% The Current Maintainer of this work is Alceu Frigeri
%%
%% This is version 1.11 (2023/05/29)
%%
%% The list of files that compose this work can be found in the README.md file at
%% https://ctan.org/pkg/ufrgscca
%%
%%%==============================================================================
%% UFRGS stands for "Federal University of Rio Grande do Sul" in south Brazil
%% EE    stands for "Engineering School"
%% CCA   stands for "Control and Automation Engineering Course" (Portuguese acronym)
%%%==============================================================================
\NeedsTeXFormat{LaTeX2e}[2022/06/01]
\def\tc@tmp@packname{ufrgscca-gen}
\def\tc@tmp@altpackname{ufrgsccagen}
\def\tc@tmp@packdesc{UFRGS/CCA generic/miscellany commands}
\def\tc@tmp@packdate{2023/05/29}
\def\tc@tmp@packversion{1.11}
\let\@exp\expandafter
\@exp\edef\csname\tc@tmp@altpackname version\endcsname{\tc@tmp@packversion}
\@exp\@exp\@exp\ProvidesPackage\@exp\@exp\@exp{\@exp\tc@tmp@packname\@exp}\@exp[\tc@tmp@packdate\space v\tc@tmp@packversion\space\tc@tmp@packdesc]

\def\tcgen@fam{tcdef}
\def\tcgen@factgrp{gen}%
%

\DeclareKeys[ufrgscca-gen]{
    family.usage = load,
	family.store = \tcgen@fam,

    group.usage = load,
	group.store = \tcgen@factgrp,
}
\ProcessKeyOptions[ufrgscca-gen]\relax



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
% \tcgen@cdef[fam]{#1}{#2} => \gdef\<fam>@#1{#2}%
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\NewDocumentCommand{\tcgen@cdef}{O{\tcgen@fam}D<>{\tcgen@factgrp} m +m}{%
    \expandafter\gdef\csname #1@#2@#3\endcsname{#4}%
}%
%
\NewDocumentCommand{\factory}{O{\tcgen@fam}D<>{\tcgen@factgrp}m}{%
				\expandafter\long\expandafter\xdef\csname #3\endcsname##1{\noexpand\tcgen@cdef[#1]<#2>{#3}{##1}}%
				%\csname #3\endcsname{-default-}
				\expandafter\def\csname #3.fam\endcsname{#1}%
				\@ifundefined{#3undef}{}{\expandafter\gdef\csname tc@factdup@#3\endcsname{}}
         \expandafter\def\csname #3undef\endcsname{\expandafter\let\csname #1@#2@#3\endcsname\undefined}%
}%
\NewDocumentCommand{\cmdfactory}{O{\tcgen@fam}D<>{\tcgen@factgrp}m}{%
		\forcsvlist{\factory[#1]<#2>}{#3}%
		\ifcsundef{tc@factgrplist@#2}{%
		    \ifcsundef{tc@factgrplist}{\csgdef{tc@factgrplist}{#2}}{\csgappto{tc@factgrplist}{,#2}}%
		    \csgdef{tc@factgrplist@#2}{#3}%
		}{\csgappto{tc@factgrplist@#2}{,#3}}%
}%
%
%
% 'debug' auxiliary commands (mainly to find out dups, defined/undefined ones)
%
%
\NewDocumentCommand{\tcgen@factcmd@prt}{m}{\@ifundefined{tc@factdup@#1}{#1}{#1 (dup)}
\expandafter\@ifundefined\expandafter{\csname #1.fam\endcsname @#1}{\textbf{ NOT Defined} \\}{ {\csname\csname #1.fam\endcsname @#1\endcsname} \\}}
\NewDocumentCommand{\tcgen@factcmd@def}{m}{\csname #1.fam\endcsname @\@ifundefined{tc@factdup@#1}{#1}{#1 (dup)} %
	\expandafter\@ifundefined\expandafter{\csname #1.fam\endcsname @#1}{\textbf{ NOT Defined} \\}{ {\slshape Defined} \\} }
%\NewDocumentCommand{\tcgen@factcmd@prt}{m}{{#1}  \\}
%\NewDocumentCommand{\tcgen@factcmd@def}{m}{{#1} :: \@ifundefined{tc@#1}{-- \textbf{NOT Defined} --\\}{Defined \\} }
\NewDocumentCommand{\tcgen@factgrp@prt}{m}{\tightul{#1}  \\%
    		\expandafter\expandafter\expandafter\forcsvlist\expandafter\expandafter\expandafter\tcgen@do\expandafter\expandafter\expandafter{\csname tc@factgrplist@#1\endcsname}%
}
\NewDocumentCommand{\listfactorycmds}{sO{}}{%
    \IfBooleanTF{#1}{\def\tcgen@do##1{\tcgen@factcmd@def{##1}}}{\def\tcgen@do##1{\tcgen@factcmd@prt{##1}}}
    \ifblank{#2}{%
		    \ifcsundef{tc@factgrplist}{Factories Groups: \textbf{empty list}\\ }{%
				     Factories:  \\ %
				    \expandafter\expandafter\expandafter\forcsvlist\expandafter\expandafter\expandafter\tcgen@factgrp@prt\expandafter\expandafter\expandafter{\csname tc@factgrplist\endcsname}%
						%
				}
		}{%
		}%
}


%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%
%
%  \mkswitch creates a switch (somewhat 'like' a programming switch)
%    a 'default case' is associated with the switch when creating it
%    one can add many 'cases' later on.
%    one can have any code associated with a 'switch/case'
%
%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%


\NewDocumentCommand\mkswitch{O{}m}{%
    \NewDocumentCommand{#2}{m}{%
        \ifcsname\string#2@case@##1\endcsname\csname\string#2@case@##1\endcsname\else#1\fi%
    }%
}%
\NewDocumentCommand{\addcase}{mmm}{\expandafter\def\csname\string#1@case@#2\endcsname{#3}}%
\let\addswitchcase\addcase