summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/trivfloat/trivfloat.dtx
blob: 77bce62563325fbb1f641fa4ec5ecc2f5171f430 (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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
% \iffalse meta-comment
%
% Copyright (C) 2007 by
%    Joseph Wright <joseph.wright@morningstar2.co.uk>
%
% Released under the GNU General Public License v2
% See http://www.gnu.org/licenses/gpl.txt
%
% This work consists of the main source file chemextra.dtx
% and the derived files
%
%<*driver>
\documentclass{ltxdoc}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
%\OnlyDescription
\usepackage[T1]{fontenc}
\usepackage[english,UKenglish]{babel}
\usepackage{mathpazo,booktabs,array,url}
\usepackage{\jobname}
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{107}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \GetFileInfo{\jobname.sty}
%
% \changes{v1.0}{2007/06/09}{Initial public release}
%
% \DoNotIndex{\@eha,\@ne,\advance,\begingroup,\csname,\def,\edef}
% \DoNotIndex{\else,\end,\endcsname,\endgroup,\expandafter,\fi}
% \DoNotIndex{\ifcase,\jobname,\MakeLowercase,\MakeUppercase}
% \DoNotIndex{\MessageBreak,\NeedsTeXFormat,\newcommand,\newcount}
% \DoNotIndex{\noexpand,\or,\PackageError,\PackageInfo}
% \DoNotIndex{\PackageWarning,\ProvidesPackage,\RequirePackage}
% \DoNotIndex{\romannumeral,\x}
%
% \title{Quick floats in LaTeX}
% \author{Joseph Wright%
% \thanks{E-mail: joseph.wright@morningstar2.co.uk}}
% \date{\filedate}
%
% \maketitle
%
% \begin{abstract}
%
% The |trivfloat| package provides a quick method for defining new
% float types in LaTeX.  A single command sets up a new float in the
% same style as the LaTeX kernel |figure| and |table| float types.
%
% \end{abstract}
%
% \section{Introduction}
%
% The LaTeX kernel provides the |figure| and |table| floating
% environment, but does not provide an easy method for defining new
% float types.  This problem is addressed by the |float| package,
% which provides an array of commands to create new float types.
% However, the one command missing is a quick-and-dirty one to
% set up a new float type with no customisation.  This is addressed
% by the |trivfloat| package.
%
% \section{Usage}
%
% \DescribeMacro{\trivfloat}
% \DescribeMacro{\listoffloat-names}
% The package provides a single command to produce the new float
% type, |\trvifloat|.  This takes a single argument
% \marg{float-name}, which will be the name of the new floating
% environment.  The new environment can be used as normal; the new
% floats should behave exactly the same as |figure| and |table|
% environments.  The command |\listof|\meta{float-name}|s| is also
% provided.
%
% \StopEventually{}
%
% \iffalse
%<*package>
% \fi
%
% \section{Implementation}
%
% \subsection{Setup code}
%
% The first part of the package is concerned with basic
% identification and loading support packages.
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{trivfloat}
  [2007/06/09 v1.0 Quick floats in LaTeX]
\RequirePackage{float}
%    \end{macrocode}
%
% \subsection{Internal macros}
%
% \begin{macro}{\tfl@floatcount}
% A new counter is needed to track how many floats have been
% generated by |trivfloat|.
%    \begin{macrocode}
\newcount\tfl@floatcount%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\tfl@genext}
% \begin{macro}{\tfl@ext@i}
% Each float type needs a list to store entries when generating
% a contents listing.  Rather than try complex things with the
% initial characters of the float name, an arbitrary file extension
% is used.  Note that |lof|, |log| and |lot| are taken by default,
% so we don't use them.  Also notice that if people try to make too
% many new float types, then extension |xxx| will be used.  This is
% very unlikely, but odd things might happen so we warn them.
%    \begin{macrocode}
\def\tfl@genext{%
  \expandafter\def\csname tfl@ext@\romannumeral\tfl@floatcount%
      \expandafter\endcsname{%
    \ifcase\tfl@floatcount%
      \PackageError{trivfloat}%
        {Something's wrong here --- Contact the package author!}%
      \@eha%
    \or % 1
      loa%
    \or % 2
      lob%
    \or % 3
      loc%
    \or % 4
      lod%
    \or % 5
      loe%
    \or % 6
      loh%
    \or % 7
      loi%
    \or % 8
      loj%
    \or % 9
      lok%
    \or % 10
      lol%
    \or % 11
      lom%
    \or % 12
      lon%
    \or % 13
      loo%
    \or % 15
      loq%
    \or % 16
      lor%
    \or % 17
      los%
    \or % 18
      lou%
    \or % 19
      lov%
    \or % 20
      low%
    \or % 21
      lox%
    \or % 22
      loy%
    \or % 23
      loz%
    \else % 24 or more
      \PackageWarning{trivfloat}%
        {I've run out of extensions \MessageBreak%
         I'm using \jobname.xxx to list all future floats}%
      xxx%
    \fi%
  }%
}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\tfl@gennamea}
% \begin{macro}{\tfl@genname}
% \begin{macro}{\tfl@name@i}
% The conversion of the supplied float name to a form suitable for
% using as a title is achieved here.  We strip off the first letter,
% convert to uppercase, then convert the rest to lowercase. Thanks
% to Martin Heller for the method to strip the first letter off.
%    \begin{macrocode}
\def\tfl@gennamea#1#2\end{%
  \expandafter\def\csname tfl@name@\romannumeral\tfl@floatcount%
      \expandafter\endcsname{%
    \MakeUppercase{#1}%
    \MakeLowercase{#2}%
  }%
}%
\def\tfl@genname#1{%
  \tfl@gennamea#1\end%
}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\tfl@list}
% \begin{macro}{\listoffloat-names}
% An auxiliary function is needed to define the
%|\listof\emph{float-name}s| macros.  This is to ensure that
% expansion occurs properly.
%    \begin{macrocode}
\def\tfl@list#1#2#3{%
  \newcommand*{#1}{\listof{#2}{#3}}%
}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{User space macros}
%
% \begin{macro}{\trivfloat}
% The only user-facing macro we need is |\trivfloat|. This does the
% work of setting up the new float type. Thanks to Heiko Oberdiek for
% the method to expand arguments correctly.  Notice that a single
% command for the extension would work.  However, the float name does
% need different commands for each float.  So for consistency, both
% have numerals appended.
%    \begin{macrocode}
\newcommand*{\trivfloat}[1]{%
  \advance\tfl@floatcount\@ne%
  \tfl@genext%
  \tfl@genname{#1}%
  \PackageInfo{trivfloat}%
    {Listing all floats of type #1 in \jobname.%
     \csname tfl@ext@\romannumeral\tfl@floatcount\endcsname}%
  \begingroup%
    \edef\x{\endgroup%
      \noexpand\newfloat{#1}{tbp}{%
        \csname tfl@ext@\romannumeral\tfl@floatcount\endcsname%
      }%
      \noexpand\floatname{#1}{%
        \expandafter\noexpand%
        \csname tfl@name@\romannumeral\tfl@floatcount\endcsname%
      }%
      \noexpand\tfl@list{\csname listof#1s\endcsname}{#1}{%
        List of \expandafter\noexpand%
        \csname tfl@name@\romannumeral\tfl@floatcount\endcsname s%
      }%
    }%
  \x%
}%
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%</package>
% \fi
% \PrintChanges
% \PrintIndex
% \Finale