Debian Codegraph @

texmf-dist/source/latex/realhats/realhats.dtx

raw
1 %\iffalse meta-comment
2 %Copyright (c) 2019 Matthew Scroggs & Adam Townsend
3 %
4 %Permission is hereby granted, free of charge, to any person obtaining a copy
5 %of this software and associated documentation files (the "Software"), to deal
6 %in the Software without restriction, including without limitation the rights
7 %to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 %copies of the Software, and to permit persons to whom the Software is
9 %furnished to do so, subject to the following conditions:
10 %
11 %The above copyright notice and this permission notice shall be included in all
12 %copies or substantial portions of the Software.
13 %
14 %THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 %IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 %FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 %AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 %LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 %OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 %SOFTWARE.
21 %\fi
22 %\lstinline{realhats} is a package for \LaTeX{} that makes the \lstinline{\hat} command
23 %put real hats on symbols.
24 %For example, the input \lstinline@\hat{a}=\hat{b}@ will produce the output:
25 %\[\hat{a}=\hat{b}\]
26 %To make a vector with a hat, the input \lstinline@\hat{\mathbf{a}}@ produces:
27 %\[\hat{\mathbf{a}}\]
28 %
29 %The command \lstinline{\hat} will choose a hat randomly from eighteen hats:
30 %\begin{center}
31 %\begin{tabular}{cp{4cm}cl}
32 %\(\hatn{a}{beret}\) & beret &
33 %\(\hatn{a}{santa}\) & Santa hat \\
34 %\(\hatn{a}{sombrero}\) & sombrero &
35 %\(\hatn{a}{witch}\)& witch's hat \\
36 %\(\hatn{a}{tophat}\) & top hat &
37 %\(\hatn{a}{ash}\) & Ash's hat \\
38 %\(\hatn{a}{fez}\) & fez &
39 %\(\hatn{a}{cowboy}\) & cowboy hat \\
40 %\(\hatn{a}{crown}\) & crown &
41 %\(\hatn{a}{dunce}\) & dunce's cap \\
42 %\(\hatn{a}{policeman}\) & policeman's hat \qquad&
43 %\(\hatn{a}{scottish}\) & Scottish hat \\
44 %\(\hatn{a}{birthday}\) & birthday hat &
45 %\(\hatn{a}{mortarboard}\) & mortarboard \\
46 %\(\hatn{a}{tile-white}\) & aperiodic tile (white) &
47 %\(\hatn{a}{tile-gray}\) & aperiodic tile (gray)\\
48 %\(\hatn{a}{tile-light-blue}\) & aperiodic tile (light blue) &
49 %\(\hatn{a}{tile-blue}\) & aperiodic tile (blue)
50 %\end{tabular}
51 %\end{center}
52 %
53 %Variables can be given a non-random hat, using the command \lstinline{\hat} with an optional parameter:
54 %\begin{center}
55 %\begin{tabular}{lp{2cm}ll}
56 % \textbf{command} & \textbf{produces} & % \textbf{command} & \textbf{produces} \\
57 % \lstinline@\hat[beret]{a}@ & \(\hat[beret]{a}\) &
58 % \lstinline@\hat[santa]{a}@ & \(\hat[santa]{a}\) \\
59 % \lstinline@\hat[sombrero]{a}@ & \(\hat[sombrero]{a}\) &
60 % \lstinline@\hat[witch]{a}@ & \(\hat[witch]{a}\) \\
61 % \lstinline@\hat[tophat]{a}@ & \(\hat[tophat]{a}\) &
62 % \lstinline@\hat[ash]{a}@ & \(\hat[ash]{a}\) \\
63 % \lstinline@\hat[fez]{a}@ & \(\hat[fez]{a}\) &
64 % \lstinline@\hat[cowboy]{a}@ & \(\hat[cowboy]{a}\) \\
65 % \lstinline@\hat[crown]{a}@ & \(\hat[crown]{a}\) &
66 % \lstinline@\hat[dunce]{a}@ & \(\hat[dunce]{a}\) \\
67 % \lstinline@\hat[policeman]{a}@ & \(\hat[policeman]{a}\) &
68 % \lstinline@\hat[scottish]{a}@ & \(\hat[scottish]{a}\) \\
69 % \lstinline@\hat[birthday]{a}@ & \(\hat[birthday]{a}\) &
70 % \lstinline@\hat[mortarboard]{a}@ & \(\hat[mortarboard]{a}\) \\
71 % \lstinline@\hat[tile-white]{a}@ & \(\hat[tile-white]{a}\) &
72 % \lstinline@\hat[tile-gray]{a}@ & \(\hat[tile-gray]{a}\) \\
73 % \lstinline@\hat[tile-light-blue]{a}@ & \(\hat[tile-light-blue]{a}\) &
74 % \lstinline@\hat[tile-blue]{a}@ & \(\hat[tile-blue]{a}\)
75 %\end{tabular}
76 %\end{center}
77 %
78 %You can also pass these same options when loading the package.
79 %For example, \verb@\usepackage[cowboy]{realhats}@ will cause the package to use cowboy hats
80 %everywhere (unless a different hat is given to the \verb@\hat@ command).
81 %\iffalse
82 %<*documentation>
83 \documentclass{article}
84 \usepackage{realhats}
85 \usepackage{doc}
86 \usepackage{listings}
87 \lstset{basicstyle=\ttfamily\footnotesize,commentstyle=\color{white},language=TeX}
88 \title{realhats v\input{VERSION}}
89 \author{Matthew W.~Scroggs \& Adam K.~Townsend}
90 \setlength\parindent{0pt}
91 \begin{document}
92 \maketitle
93 \DocInput{realhats.dtx}
94 \end{document}
95 %</documentation>
96 %\fi
97
98 %\iffalse
99 %<*realhats>
100 \NeedsTeXFormat{LaTeX2e}
101 \ProvidesPackage{realhats}[2022/06/13 realhats 6.0]
102
103 \RequirePackage{amsmath}
104 \RequirePackage{graphicx}
105 \RequirePackage{ifthen}
106 \RequirePackage[first=0, last=14, counter=hat]{lcg}
107 \RequirePackage{calc}
108 \RequirePackage{stackengine}
109
110 \newcommand\myhat{}
111 \newlength{\hatwidth} %hat width
112 \newlength{\hshif} %horizontal shift
113 \newlength{\vshif} %vertical shift
114
115 \global\def\hatused{-1}
116 \DeclareOption{beret}{\global\def\hatused{beret}}
117 \DeclareOption{santa}{\global\def\hatused{santa}}
118 \DeclareOption{sombrero}{\global\def\hatused{sombrero}}
119 \DeclareOption{witch}{\global\def\hatused{witch}}
120 \DeclareOption{tophat}{\global\def\hatused{tophat}}
121 \DeclareOption{ash}{\global\def\hatused{ash}}
122 \DeclareOption{fez}{\global\def\hatused{fez}}
123 \DeclareOption{cowboy}{\global\def\hatused{cowboy}}
124 \DeclareOption{crown}{\global\def\hatused{crown}}
125 \DeclareOption{dunce}{\global\def\hatused{dunce}}
126 \DeclareOption{policeman}{\global\def\hatused{policeman}}
127 \DeclareOption{scottish}{\global\def\hatused{scottish}}
128 \DeclareOption{birthday}{\global\def\hatused{birthday}}
129 \DeclareOption{mortarboard}{\global\def\hatused{mortarboard}}
130 \DeclareOption{tile-white}{\global\def\hatused{tile-white}}
131 \DeclareOption{tile-gray}{\global\def\hatused{tile-gray}}
132 \DeclareOption{tile-light-blue}{\global\def\hatused{tile-light-blue}}
133 \DeclareOption{tile-blue}{\global\def\hatused{tile-blue}}
134 \ProcessOptions\relax
135
136 \newcommand{\gethat}{%
137 \ifcase\thehat beret%
138 \or santa%
139 \or sombrero%
140 \or witch%
141 \or tophat%
142 \or ash%
143 \or fez%
144 \or cowboy%
145 \or crown%
146 \or dunce%
147 \or policeman%
148 \or scottish%
149 \or birthday%
150 \or mortarboard%
151 \or tile-white%
152 \or tile-gray%
153 \or tile-light-blue%
154 \or tile-blue%
155 \fi
156 }
157
158 \renewcommand{\hat}[2][]{%
159 \ifthenelse{\equal{#1}{}}{%
160 \ifthenelse{\equal{\hatused}{-1}}%
161 {\rand\hatn{#2}{\gethat}}%
162 {\hatn{#2}{\hatused}}%
163 }{%
164 \ifthenelse{\equal{#1}{beret}}{\hatn{#2}{beret}}{}%
165 \ifthenelse{\equal{#1}{santa}}{\hatn{#2}{santa}}{}%
166 \ifthenelse{\equal{#1}{sombrero}}{\hatn{#2}{sombrero}}{}%
167 \ifthenelse{\equal{#1}{witch}}{\hatn{#2}{witch}}{}%
168 \ifthenelse{\equal{#1}{tophat}}{\hatn{#2}{tophat}}{}%
169 \ifthenelse{\equal{#1}{ash}}{\hatn{#2}{ash}}{}%
170 \ifthenelse{\equal{#1}{fez}}{\hatn{#2}{fez}}{}%
171 \ifthenelse{\equal{#1}{cowboy}}{\hatn{#2}{cowboy}}{}%
172 \ifthenelse{\equal{#1}{crown}}{\hatn{#2}{crown}}{}%
173 \ifthenelse{\equal{#1}{dunce}}{\hatn{#2}{dunce}}{}%
174 \ifthenelse{\equal{#1}{policeman}}{\hatn{#2}{policeman}}{}%
175 \ifthenelse{\equal{#1}{scottish}}{\hatn{#2}{scottish}}{}%
176 \ifthenelse{\equal{#1}{birthday}}{\hatn{#2}{birthday}}{}%
177 \ifthenelse{\equal{#1}{mortarboard}}{\hatn{#2}{mortarboard}}{}%
178 \ifthenelse{\equal{#1}{tile-white}}{\hatn{#2}{tile-white}}{}%
179 \ifthenelse{\equal{#1}{tile-gray}}{\hatn{#2}{tile-gray}}{}%
180 \ifthenelse{\equal{#1}{tile-light-blue}}{\hatn{#2}{tile-light-blue}}{}%
181 \ifthenelse{\equal{#1}{tile-blue}}{\hatn{#2}{tile-blue}}{}%
182 }%
183 }
184
185 \newcommand{\hatn}[2]{\hatnoptions{#1}{#2}{0ex}{0ex}}
186
187 \newcommand{\hatnoptions}[4]{%
188 \setlength{\hshif}{1pt}
189 \setlength{\hatwidth}{2ex}
190 \ifthenelse{\equal{#2}{beret}}{\renewcommand\myhat{hats/realhats-beret}\setlength{\vshif}{-0.6ex} \setlength{\hshif}{0.5ex} }{}%
191 \ifthenelse{\equal{#2}{santa}}{\renewcommand\myhat{hats/realhats-santa}\setlength{\vshif}{-0.1ex} }{}%
192 \ifthenelse{\equal{#2}{sombrero}}{\renewcommand\myhat{hats/realhats-sombrero}\setlength{\vshif}{-0.17ex} \addtolength{\hshif}{-1pt}}{}%
193 \ifthenelse{\equal{#2}{witch}}{\renewcommand\myhat{hats/realhats-witch}\setlength{\vshif}{-0.12ex} \addtolength{\hshif}{-1pt}}{}%
194 \ifthenelse{\equal{#2}{tophat}}{\renewcommand\myhat{hats/realhats-tophat}\setlength{\vshif}{-0.4ex} \setlength{\hatwidth}{1.8ex} \addtolength{\hshif}{-1pt}}{}%
195 \ifthenelse{\equal{#2}{ash}}{\renewcommand\myhat{hats/realhats-ash}\setlength{\vshif}{-0.6ex} \setlength{\hatwidth}{1.8ex} \addtolength{\hshif}{-1pt}}{}%
196 \ifthenelse{\equal{#2}{fez}}{\renewcommand\myhat{hats/realhats-fez}\setlength{\vshif}{-0.4ex} \setlength{\hatwidth}{1ex} \addtolength{\hshif}{-1pt}}{}%
197 \ifthenelse{\equal{#2}{cowboy}}{\renewcommand\myhat{hats/realhats-cowboy}\setlength{\vshif}{-0.3ex} \setlength{\hshif}{0.2ex}}{}%
198 \ifthenelse{\equal{#2}{crown}}{\renewcommand\myhat{hats/realhats-crown}\setlength{\vshif}{-0.3ex} \setlength{\hshif}{0.2ex}}{}%
199 \ifthenelse{\equal{#2}{dunce}}{\renewcommand\myhat{hats/realhats-dunce}\setlength{\vshif}{-0.3ex} \setlength{\hatwidth}{1.4ex}}{}%
200 \ifthenelse{\equal{#2}{policeman}}{\renewcommand\myhat{hats/realhats-policeman}\setlength{\vshif}{-0.4ex} \setlength{\hatwidth}{1.8ex} \addtolength{\hshif}{-1pt}}{}%
201 \ifthenelse{\equal{#2}{scottish}}{\renewcommand\myhat{hats/realhats-scottish}\setlength{\vshif}{-0.6ex} \setlength{\hshif}{0.5ex} }{}%
202 \ifthenelse{\equal{#2}{birthday}}{\renewcommand\myhat{hats/realhats-birthday}\setlength{\vshif}{-0.2ex} \setlength{\hshif}{-0.1ex} }{}%
203 \ifthenelse{\equal{#2}{mortarboard}}{\renewcommand\myhat{hats/realhats-mortarboard}\setlength{\vshif}{-0.15ex} \setlength{\hshif}{0ex} }{}%
204 \ifthenelse{\equal{#2}{tile-white}}{\renewcommand\myhat{hats/realhats-tile-white}\setlength{\vshif}{-0.3ex} \setlength{\hshif}{0ex} }{}%
205 \ifthenelse{\equal{#2}{tile-gray}}{\renewcommand\myhat{hats/realhats-tile-gray}\setlength{\vshif}{-0.3ex} \setlength{\hshif}{0ex} }{}%
206 \ifthenelse{\equal{#2}{tile-light-blue}}{\renewcommand\myhat{hats/realhats-tile-light-blue}\setlength{\vshif}{-0.3ex} \setlength{\hshif}{0ex} }{}%
207 \ifthenelse{\equal{#2}{tile-blue}}{\renewcommand\myhat{hats/realhats-tile-blue}\setlength{\vshif}{-0.3ex} \setlength{\hshif}{0ex} }{}%
208 \ifthenelse{\equal{#2}{,1}}{\renewcommand\myhat{hats/realhats-,1}\setlength{\vshif}{-0.15ex} \setlength{\hshif}{0ex} }{}%
209 \addtolength{\hshif}{#3}%
210 \addtolength{\vshif}{#4}%
211 \stackMath %
212 \stackon[\vshif]{#1}{\hspace{\hshif}\includegraphics[width=\hatwidth]{\myhat}}
213 }
214 %</realhats>
215 %\fi