summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/easyfloats/doc/preamble/macros.tex
blob: 2be2bc74cb42a9ba1eef41f530f99ff99d97992c (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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
% !TeX root = ../easyfloats.tex

% Copyright © 2020 E. Zöllner
% Alternatively to the terms of the LPPL, at your choice,
% you can redistribute and/or modify this file under the
% terms of the Do What The Fuck You Want To Public License, Version 2,
% as published by Sam Hocevar. See http://www.wtfpl.net/about/.

% Defines additional macros which are not provided
% by the document class or other packages.
%
% \TikZ
% Typesets the name of the TikZ package.
% dtxdescribe defines the \tikz macro for that
% but it's wrong, the Z is not capitalized.
%
% \eTeX
% Typesets the name of eTeX.
% In standard LaTeX there are \TeX, \LaTeX and \LaTeXe.
% metalogo and dtxdescribe define more logos.
% But I have failed to find a package which provides
% the eTeX logo.
% In contrast to the other logo macros \eTeX includes a
% link to the eTeX manual on CTAN.
%
% \radioon
% draws an activated radio button
% \radiooff
% draws a deactivated radio button
%
% \DescribeHandler[<class>]{<name>}
% Typesets the handler name as a \marginpar.
% The same like all other \Describe* macros defined by dtxdescribe
% just for handlers.
%
% \handler{<name>}
% To reference a handler described with \DescribeHandler.
%
% \filename{<filename>}
% Typesets a file name in the pdf.
%
% \pkgoptn{<option>}
% Typesets a package option in the pdf.
% \key{<option>}
% Typesets a macro/environment option in the pdf.
% Usually \optn is used for both macro options and package options.
% However, I am using pgfkeys for macro options and standard LaTeX
% for package options making the two types of options quite different.
% Unlike some other packages the easyfloats package does not allow to
% pass macro options as package options.
% Therefore I like to have a better distinction between them even
% if they are formatted in the same way.
% Also, dtxdescribe defines two different macros for the description:
% \DescribeOption for package/class options and
% \DescribeKey for macro/environment options.
% So it is only consistent to have two different macros for typesetting
% macro/environment and package/class options.
% I have redefined \optn to print an error in order to avoid ambiguity.
% \val{<value>}
% typesets the value of a key. Package options don't have values.
%
% \errormessage{<message>}
% Typesets an error message in the pdf. Changes category codes so that
% control sequences and active characters do *not* need to be prefixed
% by \string.
%
% \sectionname{<title>}
% Format the name of a section of a different document which I am referring to.
% For sections of this document use \cref or \Cref instead.
%
% \newlicense{<name>}{<display text>}{<url>}
% \license{<name>}
% Define a license in the preamble with displayed name and URL with \newlicense
% and use it in the document with \license.
% Changes catcodes for the <url> only so that special characters
% can be used there without worrying (except for curly braces).
%
% \formatcode{<texcode>}
% Formats inline code.
% It does not change catcodes or performs any other kind of magic.
% <texcode> is executed as TeX code.

\usepackage{relsize}


\makeatletter
\newcommand{\version}{\newcommand\theversion}
\newcommand{\package}{\newcommand\thepackage}
\newcommand{\thedate}{\@date}
\AtBeginDocument{%
	\let\thedate=\@date
	\ifundef{\theversion}{}{\appto\@date{\strut\\\strut\thepackage~\theversion}}%
}
\makeatother

\makeatletter
\newcommand\parskipintoc[1]{%
	\def\@starttoc##1{%
		\begingroup
			\makeatletter
			\parskip=#1\relax
			\@input{\jobname.##1}%
			\if@filesw
				\expandafter\newwrite\csname tf@##1\endcsname
				\immediate\openout\csname tf@##1\endcsname \jobname.##1\relax
			\fi
			\@nobreakfalse
		\endgroup
	}
}
\makeatother
\parskipintoc{0pt plus .6em minus 1pt}

\newcommand{\bigpar}{\par{\centering*~*~*\pagebreak[3]\par}}
\newcommand{\bigparinlist}{\par\medskip\pagebreak[3]\par}
\let\OriginalItemize=\itemize
\def\itemize{\OriginalItemize\let\bigpar\bigparinlist}

\newcommand{\eTeX}{\texorpdfstring{\href{https://ctan.org/pkg/etex}{\ensuremath{\varepsilon}-\TeX}}{eTeX}}
\newcommand{\TikZ}{Ti\emph{k}Z}

\newcommand{\radioon}{\radio{\fill circle (.45);}}
\newcommand{\radiooff}{\radio\relax}
\newcommand{\radio}[1]{\tikz[x=1ex,y=1ex,baseline=-.6ex,very thin]{\draw circle (.75);#1}}


\newcommand{\filename}{\emph}

\newcommand{\pkgoptn}{\optn}
\newcommand{\key}{\optn}
\let\pkgoptn=\optn
\let\key=\optn
\let\handler=\optn
% Do *not* add the optional argument, otherwise \renewcommand would not only redefine \optn
% but also two internal macros which \pkgoptn and \key depend on.
\renewcommand{\optn}[1]{\PackageError{macros}{\string\optn\space is ambiguous}{Please use \string\key\space for macro/environment options and \string\pkgoptn\space for package/class options.}}

\newcommand{\val}[1]{#1}

\makeatletter
\newcommand*{\DescribeHandler}[2][]{\DTXD@margintagindex{#1}{#2}{Handler}{handler}{usage}}

\newcommand{\errormessage}{%
	\begingroup
	\let\do=\@makeother
	\dospecials
	\@makeother`
	\catcode`{=1
	\catcode`}=2
	\catcode` =10
	\do@errormessage
}
\newcommand{\do@errormessage}[1]{%
	\endgroup
	\enquote{\texttt{#1}}%
}
\makeatother


\newrobustcmd{\sectionname}[1]{{\let\formatcode\formatcodeinsection\emph{#1}}}


\makeatletter
\newcommand{\license@csname}[1]{license@cs@#1}
\newcommand{\FormatLicense}{\emph}

\newcommand{\newlicense}[2]{%
	\begingroup
	\let\do=\@makeother
	\dospecials
	\catcode`{=1
	\catcode`}=2
	\newlicense@do{#1}{#2}%
}
\newcommand{\newlicense@do}[3]{% #1: name, #2: display text, #3: url
	\endgroup
	\expandafter \newcommand \csname\license@csname{#1}\endcsname{\href{#3}{\FormatLicense{#2}}}%
}

\newcommand{\license}[1]{% #1: name
	\ifcsname\license@csname{#1}\endcsname
		\csname\license@csname{#1}\endcsname
	\else
		\PackageError{macros}{license name `#1' undefined}{}%
	\fi
}


% ---------- \formatcode ---------

\newcommand{\formatcode}[1]{{\ttfamily\smaller[.5]\fboxsep=.5pt\colorbox{codebackground!50}{\vphantom\}\colorlet{linkcolor}{codelinkcolor}#1}}}
\newcommand{\formatcodeinsection}[1]{{\ttfamily#1}}
\newcommand{\formatcodeinmarginpar}[1]{\formatcodeinsection{\small#1}}

% patch section commands and toc to use \formatcodeinsection instead of \formatcode
\newcommand{\patchsection}[3]{% #1: command to be patched, #2: code to be inserted before, #3 code to be appended
	\expandafter\let\csname @@originalsec@\string#1\endcsname #1%
	\expandafter\def\csname @@sec@\string#1\endcsname##1##2{#2\csname @@originalsec@\string#1\endcsname##1{##2}#3}%
	\def#1##1##{\csname @@sec@\string#1\endcsname{##1}}%
}
\@tfor \@sec@cmd :=\section\subsection\subsubsection \do{%
	\expandafter\expandafter\expandafter\patchsection\expandafter\@sec@cmd\expandafter{%
		\csname My\expandafter\string\@sec@cmd Hook\endcsname
		\let\@original@formatcode=\formatcode
		\let\formatcode=\formatcodeinsection
	}{%
		\let\formatcode=\@original@formatcode
	}%
}
\let\@@original@toc=\tableofcontents
\def\tableofcontents{{\let\formatcode\formatcodeinsection\DisableLinks\@@original@toc}}

% patch \marginpar to use \formatcodeinmarginpar instead of \formatcode
\let\@@original@marginpar=\marginpar
\renewcommand\marginpar[1]{\@@original@marginpar{\let\formatcode=\formatcodeinmarginpar#1}}


\makeatother