summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/templatetools/templatetools.sty
blob: fd20ab3336735fd5049e31e16361979bba68f6ea (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
%%
%% This is file `templatetools.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% templatetools.dtx  (with options: `templatetools.sty')
%% 
%% IMPORTANT NOTICE:
%% 
%% For the copyright see the source file.
%% 
%% Any modified versions of this file must be renamed
%% with new filenames distinct from templatetools.sty.
%% 
%% For distribution of the original source see the terms
%% for copying and modification in the file templatetools.dtx.
%% 
%% This generated file may be distributed as long as the
%% original source files, as listed above, are part of the
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)

\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesPackage{templatetools}
          [2014/06/27 v0.1 Collection of conditional commands useful inside templates]
%%% --- Necessary Packages
%%% ------------------------------------------------------------------
\RequirePackage{ifpdf}
\RequirePackage{etoolbox}
\RequirePackage{ltxcmds}
\RequirePackage{array} % for column types
\RequirePackage{ifdraft} % check draft
\RequirePackage{scrlfile}
%%% --- Check if command is defined
%%% ------------------------------------------------------------------
\newcommand{\IfDefined}[2]{\ifcsdef{#1}{#2}{}}%
\newcommand{\IfUndefined}[2]{\ifcsdef{#1}{}{#2}}%
\newcommand{\IfElseDefined}[3]{\ifcsdef{#1}{#2}{#3}}%
\newcommand{\IfElseUndefined}[3]{\ifcsdef{#1}{#3}{#2}}%
\newcommand{\IfMultDefined}[1]{%
  \@tempswatrue
  \def\do##1{%
%% define \@tempa with trimmed index element.
    \edef\@tempa{\zap@space##1 \@empty}%
%% check if package of current index is loaded
    \ifcsdef{\@tempa}{}{\@tempswafalse}%
  }%
%% Process csv list with command \do (etoolbox)
  \docsvlist{#1}%
%% makes sure that the conditional works with one or two (if, else) parameters.
  \if@tempswa\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi%
}
\newcommand{\IfDraft}[1]{\ifx\@draft\@undefined \else #1 \fi}

\newcommand{\IfNotDraft}[1]{\ifx\@draft\@undefined #1 \fi}
\newcommand{\IfNotDraftElse}[2]{\ifx\@draft\@undefined #1 \else #2 \fi}
\newcommand{\IfPackageLoaded}[2]{\ltx@ifpackageloaded{#1}{#2}{}}
\newcommand{\IfPackageNotLoaded}[2]{\ltx@ifpackageloaded{#1}{}{#2}}
\let\IfElsePackageLoaded\ltx@ifpackageloaded
\newcommand{\IfPackagesLoaded}[1]{%
  \@tempswatrue
  \def\do##1{%
    \edef\@tempa{\zap@space##1 \@empty}%
    \ltx@ifpackageloaded{\@tempa}{}{\@tempswafalse}%
  }%
  \docsvlist{#1}%
  \if@tempswa\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi%
}
\newcommand{\IfPackagesNotLoaded}[1]{%
  \@tempswatrue
  \def\do##1{%
    \edef\@tempa{\zap@space##1 \@empty}%
    \ltx@ifpackageloaded{\@tempa}{\@tempswafalse}{}%
  }%
  \docsvlist{#1}%
  \if@tempswa\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi%
}
\newcommand{\ExecuteAfterPackage}[2]{%
%% #1: after this package
%% #2: code to execute
  \AfterAtEndOfPackage{#1}{
    #2%
  }
  \AtEndPreamble{%
    \IfPackageNotLoaded{#1}{%
     #2%
    }
  }
}
\newcommand{\ExecuteBeforePackage}[2]{%
%% #1: before this package
%% #2: code to execute
  \BeforePackage{#1}{
    #2%
  }
  \AtEndPreamble{%
    \IfPackageNotLoaded{#1}{%
     #2%
    }
  }
}
\def\IfTikzLibraryLoaded#1{%
  \ifcsname tikz@library@#1@loaded\endcsname
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}
\expandafter\let\csname columntype@l\endcsname\@empty
\expandafter\let\csname columntype@c\endcsname\@empty
\expandafter\let\csname columntype@r\endcsname\@empty
\expandafter\let\csname columntype@p\endcsname\@empty
\expandafter\let\csname columntype@m\endcsname\@empty
\expandafter\let\csname columntype@b\endcsname\@empty
\expandafter\let\csname columntype@@\endcsname\@empty
\expandafter\let\csname columntype@!\endcsname\@empty
\expandafter\let\csname columntype@|\endcsname\@empty
\expandafter\let\csname columntype@<\endcsname\@empty
\expandafter\let\csname columntype@>\endcsname\@empty
\expandafter\let\csname columntype@=\endcsname\@empty
\newcommand\CheckIfColumntypeDefined[1]{%
%% create the bool variable for column type
  \providebool{tpl@coltype@#1}
%% check if new column type of this name was created
  \ifcsdef{NC@find@\string#1}%
    {\setbool{tpl@coltype@#1}{true}}%
%% if not check if it is a predefined column type
    {\ifcsdef{columntype@\string#1}
      {\setbool{tpl@coltype@#1}{true}}%
      {\setbool{tpl@coltype@#1}{false}}%
    }%
}
\newcommand\isColumntypeDefined[1]{tpl@coltype@#1}
\newcommand\IfColumntypeDefined[3]{%
%% Execute check which create bool variable
  \CheckIfColumntypeDefined{#1}
%% use bool variable for if sequence
  \ifboolexpr{ bool{\isColumntypeDefined{#1}} }{#2}{#3}%
}
\newcommand{\IfColumntypesDefined}[1]{%
  \@tempswatrue
  \def\do##1{%
    \edef\@tempa{\zap@space##1 \@empty}%
%% check if column is defined.
%%   Here with \expandafter because of the \string definition
%%   in \CheckIfColumntypeDefined.
    \expandafter\IfColumntypeDefined
        \expandafter{\@tempa}{}{\@tempswafalse}
  }%
  \docsvlist{#1}%
  \if@tempswa\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi%
}
\newcommand{\IfColorDefined}[3]{%
  \ifcsdef{\string\color @#1}
    {#2} % color string is defined
    {#3}} % color string is not defined
\newcommand{\IfColorsDefined}[1]{%
  \@tempswatrue
  \def\do##1{%
    \edef\@tempa{\zap@space##1 \@empty}%
    \expandafter\IfColorDefined
        \expandafter{\@tempa}{}{\@tempswafalse}
  }%
  \docsvlist{#1}%
  \if@tempswa\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi%
}
\newcommand{\IfMathVersionDefined}[3]{\ifcsdef{mv@#1}{#2}{#3}}
\newcommand{\IfGlossariesStyleDefined}[2]{\ifcsdef{@glsstyle@#1}{#2}{}}

\newcommand\SetTemplateDefinition[3]{% 1: group, 2: property, 3: code
  \csdef{tpl@definition@#1@#2}{#3}
}
\newcommand\UseDefinition[2]{%
  \ifcsdef{tpl@definition@#1@#2}
    {\csuse{tpl@definition@#1@#2}}
    {\PackageWarning{templatetools}%
      {Definition #1->#2 is unknown\MessageBreak}{}}%
}%
\endinput
%%
%% End of file `templatetools.sty'.