summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/trivfloat/trivfloat.dtx
blob: d9fafc28546439594dadc83c1b60114f65870037 (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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
% \iffalse meta-comment
% !TEX program  = pdflatex
% !TEX encoding = ISO-8859-1
%<*internal>
\iffalse
%</internal>
%<*readme>
----------------------------------------------------------------
trivfloat --- Quick floats in LaTeX
E-mail: joseph.wright@morningstar2.co.uk
Released under the LaTeX Project Public License v1.3c or later
See http://www.latex-project.org/lppl.txt
----------------------------------------------------------------

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.
%</readme>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\preamble
trivfloat --- Quick floats in LaTeX
E-mail: joseph.wright@morningstar2.co.uk
Released under the LaTeX Project Public License v1.3c or later
See http://www.latex-project.org/lppl.txt
----------------------------------------------------------------

\endpreamble
\postamble

Copyright (C) 2007,2009 by
  Joseph Wright <joseph.wright@morningstar2.co.uk>
  
It may be distributed and/or modified under the conditions of
the LaTeX Project Public License (LPPL), either version 1.3c of
this license or (at your option) any later version.  The latest
version of this license is in the file:

   http://www.latex-project.org/lppl.txt

This work is "maintained" (as per LPPL maintenance status) by
  Joseph Wright.

This work consists of the file  trivfloat.dtx
          and the derived files trivfloat.pdf,
                                trivfloat.ins and
                                trivfloat.sty.
                                
\endpostamble
\usedir{tex/latex/trivfloat}
\generate{
  \file{\jobname.sty}{\from{\jobname.dtx}{package}}
}
%</install>
%<install>\endbatchfile
%<*internal>
\usedir{source/latex/trivfloat}
\generate{
  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\nopreamble\nopostamble
\usedir{doc/latex/trivfloat}
\generate{
  \file{README.txt}{\from{\jobname.dtx}{readme}}
}
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
\immediate\write18{makeindex -s gglo.ist -o trivfloat.gls trivfloat.glo}
\immediate\write18{makeindex -s gind.ist -o trivfloat.ind trivfloat.idx}
%</internal>
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{trivfloat}
  [2009/04/23 v1.4 Quick floats in LaTeX]
%</package>
%<*driver>
\documentclass[a4paper]{ltxdoc}
\usepackage[T1]{fontenc}
\usepackage{lmodern,trivfloat}
\usepackage[osf]{mathpazo}
\usepackage[scaled=0.95]{helvet}
\usepackage[final]{listings,microtype}
\usepackage[numbered]{hypdoc}
\trivfloat{graph}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
%\CheckSum{295}
%
%\changes{v1.0}{2007/06/09}{Initial public release}
%\changes{v1.1}{2007/08/13}{Floats can be generated as package
%   options}
%\changes{v1.2}{2007/08/20}{Added \textsf{memoir} support}
%\changes{v1.2}{2007/08/20}{Improved emulation of default floats}
%\changes{v1.3b}{2007/09/20}{Fixed error with \textsf{hyperref}}
%\changes{v1.3b}{2007/09/20}{Licence changed from GPL to LPPL}
%\changes{v1.4}{2009/04/23}{Re-think of internal methods to make
%  work-flow clearer}
%\changes{v1.4}{2009/04/23}{Support for \textsf{babel} introduced}
%
%\GetFileInfo{\jobname.sty}
%
%\makeatletter
%
%^^A \DescribeOption is in l3doc but not ltxdoc
%\newcommand*{\DescribeOption}{^^A
%  \leavevmode
%  \@bsphack
%  \begingroup
%    \MakePrivateLetters
%    \Describe@Option
%}
%\newcommand*{\Describe@Option}[1]{^^A
%    \endgroup
%  \marginpar{^^A
%    \raggedleft
%    \PrintDescribeEnv{#1}^^A
%  }%
%  \SpecialOptionIndex{#1}^^A
%  \@esphack
%  \ignorespaces
%}
%\newcommand*{\SpecialOptionIndex}[1]{^^A
%  \@bsphack
%  \index{^^A
%    #1\actualchar{\protect\ttfamily#1} (option)\encapchar usage^^A
%  }^^A
%  \index{^^A
%    options:\levelchar#1\actualchar{\protect\ttfamily#1}
%    \encapchar usage^^A
%  }^^A
%  \@esphack
%}
%
%^^A For creating examples with nice highlighting of code, and so
%^^A on; based on the system used in the listings source (lstsample).
%\lst@RequireAspects{writefile}
%\newsavebox{\LaTeXdemo@box}
%\lstnewenvironment{LaTeXdemo}[1][code and example]{^^A
%  \global\let\lst@intname\@empty
%  \expandafter\let\expandafter\LaTeXdemo@end
%    \csname LaTeXdemo@#1@end\endcsname
%  \@nameuse{LaTeXdemo@#1}^^A
%}{^^A
%  \LaTeXdemo@end
%}
%\newcommand*\LaTeXdemo@new[3]{^^A
%  \expandafter\newcommand\expandafter*\expandafter
%    {\csname LaTeXdemo@#1\endcsname}{#2}^^A
%  \expandafter\newcommand\expandafter*\expandafter
%    {\csname LaTeXdemo@#1@end\endcsname}{#3}^^A
%}
%\newcommand*\LaTeXdemo@common{^^A
%  \setkeys{lst}{
%    basicstyle   = \small\ttfamily,
%    basewidth    = 0.51em,
%    gobble       = 3,
%    keywordstyle = \color{blue},
%    language     = [LaTeX]{TeX},
%    moretexcs    = {
%      trivfloat
%    }
%  }^^A 
%}
%\newcommand*\LaTeXdemo@input{^^A
%  \MakePercentComment
%  \catcode`\^^M=10\relax
%  \small
%  \begingroup
%    \setkeys{lst}{
%      SelectCharTable=\lst@ReplaceInput{\^\^I}{\lst@ProcessTabulator}
%    }^^A
%    \leavevmode 
%      \input{\jobname.tmp}^^A
%  \endgroup
%  \MakePercentIgnore
%}
%\LaTeXdemo@new{code and example}{^^A
%  \setbox\LaTeXdemo@box=\hbox\bgroup
%    \lst@BeginAlsoWriteFile{\jobname.tmp}^^A
%    \LaTeXdemo@common
%}{^^A
%    \lst@EndWriteFile
%  \egroup
%  \begin{center}
%    \ifdim\wd\LaTeXdemo@box>0.48\linewidth\relax
%      \hbox to\linewidth{\box\LaTeXdemo@box\hss}^^A
%        \begin{minipage}{\linewidth}
%          \LaTeXdemo@input
%        \end{minipage}
%    \else
%      \begin{minipage}{0.48\linewidth}
%        \LaTeXdemo@input
%      \end{minipage}
%      \hfill
%      \begin{minipage}{0.48\linewidth}
%        \hbox to\linewidth{\box\LaTeXdemo@box\hss}^^A
%      \end{minipage}
%    \fi
%  \end{center}
%}
%\LaTeXdemo@new{code only}{^^A
%  \LaTeXdemo@common
%}{}
%
%\LaTeXdemo@new{code and float}{^^A
%  \lst@BeginAlsoWriteFile{\jobname.tmp}^^A
%  \LaTeXdemo@common
%}{^^A
%  \lst@EndWriteFile
%  \LaTeXdemo@input
%}
%
%\providecommand*{\file}{\texttt}
%\providecommand*{\opt}{\texttt}
%\providecommand*{\pkg}{\textsf}
%
%\makeatother
%
%\title{^^A
%  \textsf{trivfloat} --- Quick floats in 
%    \texorpdfstring{\LaTeX}{LaTeX}\thanks{^^A
%    This file describes version \fileversion, last revised 
%    \filedate.^^A
%  }^^A
%}
%\author{^^A
%  Joseph Wright\thanks{E-mail: joseph.wright@morningstar2.co.uk}^^A
%}
%\date{Released \filedate}
%
%\maketitle
%
%\begin{abstract}
% The \pkg{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 \texttt{figure} and \texttt{table}
% float types.
%\end{abstract}
%
%\begin{multicols}{2}
%  \tableofcontents
%\end{multicols}
%
%\section{Introduction}
%
% The LaTeX kernel provides the \texttt{figure} and \texttt{table}
% floating environment, but does not provide an easy method for 
% defining new float types.  This problem is addressed by the 
% \pkg{float} and \pkg{floatrow} packages, which provides an array of 
% commands to create new float types. However, the one command missing 
% is a quick one to set up a new float type with no customisation.  
% This is addressed by the \pkg{trivfloat} package.
%
%\section{Installation}
%
% The entire bundle is supplied with the TDS-ready ZIP file,
% \file{trivfloat.tds.zip}.  Simply unzip this into your local texmf
% tree and run your hash program (\texttt{texhash} for \TeX{}Live or
% \texttt{initextmf -u} for MiK\TeX).
%
% To extract the package from \file{trivfloat.dtx}, run (pdf)\TeX\ on 
% \file{trivfloat.dtx}. This will produce all of the package
% files, and also \file{README.txt}.  To extract the
% files and build the documentation, run (pdf)\LaTeX\ on 
% \texttt{trivfloat.dtx}.  The files can then be installed as above.
% 
%\section{Using the package}
%
%\DescribeMacro{\trivfloat}
%\changes{v1.4}{2009/04/23}{\cs{trivfloat} now accepts a comma-list of
%  new float types}
% The package itself provides only a single command to the user,
% \cmd{\trivfloat}.  This takes a single argument \marg{name}, a 
% comma-separated list of new floating environments.  The new
% environment scan be used as normal; the new floats should behave
% exactly the same as \texttt{figure} and \texttt{table} environments.
% The \cs{trivfloat} macro does not check for an existing definition
% of \meta{float}: any existing definition will be overwritten.
% 
% As an example, this file has in the preamble the line:
%\begin{LaTeXdemo}[code only]
%  \trivfloat{graph}
%\end{LaTeXdemo} 
% This allows the ready production of floating graphs:
%\begin{LaTeXdemo}[code and float]
%  \begin{graph}
%    \centering
%    Something for a graph
%    \caption{My graph}
%  \end{graph}
%\end{LaTeXdemo} 
% and also lists of graphs
%\begin{LaTeXdemo}
%  \listofgraphs
%\end{LaTeXdemo} 
% 
% The \pkg{trivfloat} package works hard to ensure that the 
% newly-produced floats behave exactly like pre-defined ones. The 
% exact behaviour of the new floats is dependant on the document 
% class used: \pkg{trivfloat} knows about the standard classes, 
% \pkg{memoir} and \textsc{koma}-Script.  The \cs{trivfloat} command 
% should only be used in the preamble of the document: \LaTeX\ will 
% complain if you use it later. New floats can also be generated by 
% passing the name of the desired float type to the package as an option.  
% 
% The new floats will respect the normal position modifiers, \texttt{t},
% \texttt{b}, \texttt{h}, \texttt{p} and (if \pkg{memoir} is not in use) 
% \texttt{H} for \emph{really} here.
% 
%\DescribeOption{floatrow}
%\changes{v1.4}{2009/04/23}{Support for \textsf{floatrow} package}
% \pkg{trivfloat} will use the \pkg{float} package to produce new
% floats, unless the \pkg{memoir} class is in use. The package 
% will accept the load time option \opt{floatrow}, which will instead
% use the \pkg{floatrow} package to produce floats. If either
% \pkg{float} or \pkg{floatrow} is loaded before \pkg{trivfloat}, the
% loaded package will be used irrespective of this option.
% 
% When the \pkg{memoir} class is in use, the built-in function is used 
% to produce floats. If the user has loaded \pkg{float} or 
% \pkg{floatrow}, this will be safely detected.
% 
%\section{Known issues}
%
% If you wish to redefine \texttt{\textbackslash the\meta{float}}, to
% alter the number format, then you must do this after 
% |\begin{document}|. This is to allow \pkg{trivfloat} to work correctly
% with \pkg{hyperref}.
%
% The name passed to \cs{trivfloat} should contain only the letters
% A--Z and a--z.  This ensures that there are no strange errors
% generated by \TeX. Correctly handling non-English words is not
% possible using an automated system, and so after defining a new
% float type the macros \texttt{\textbackslash\meta{float}name} and
% \texttt{\textbackslash list\meta{float}name} should be corrected to
% give the desired names. 
%
% The \pkg{babel} system provides support for a wide range of
% language-specific strings.  It also makes changes to the typography
% of documents.  The changes made by \pkg{babel} can be in almost any
% area, and so floats created with \pkg{trivfloat} may not act like the
% standard ones once \pkg{babel} is loaded.  For example, the 
% \opt{french} option for \pkg{babel} alters the internal function used
% to make float captions.  Users should search through the
% \texttt{\meta{language}.ldf} file for the languages they use for
% ``figure'' and ``lof'' to see what changes \pkg{babel} makes to the
% standard floats.  The user can then correct the behaviour of the
% new floats as needed. 
% 
%\StopEventually{^^A
%  \PrintChanges
%  \PrintIndex
%}
%
%\section{Implementation}
%
%\begin{macro}{\iftfl@floatrow}
% There is a choice: use \pkg{float} or use \pkg{floatrow}.
%    \begin{macrocode}
%<*package>
\newif\iftfl@floatrow
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tlf@make@execute}
%\begin{macro}{\tlf@make@pkg}
% So that things work easily, the name of the package used to generate
% floats is stored for later use. The command to execute everything is
% also stored, as \pkg{floatrow} needs things to happen earlier than 
% \pkg{float} or \pkg{memoir}.
%    \begin{macrocode}
\newcommand*{\tfl@make@execute}{}
\newcommand*{\tfl@make@pkg}{}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%
% Option handling, including some faked key--value input.
%    \begin{macrocode}
\DeclareOption{floatrow}{\tfl@floatrowtrue}
\DeclareOption{floatrow=true}{\tfl@floatrowtrue}
\DeclareOption{floatrow=false}{\tfl@floatrowfalse}
\DeclareOption*{%
  \expandafterAtEndOfPackage\expandafter{%
    \expandafter\trivfloat\expandafter{\CurrentOption}%
  }%
}
\ProcessOptions\relax
%    \end{macrocode}
%    
% With options processed, the appropriate packages can be loaded as
% necessary. The are some checks so that only one package is tried. The
% order here means that \pkg{memoir} users can choose to load 
% \pkg{float} or \pkg{floatrow} if they use the extra functionality.
%    \begin{macrocode}
\@ifpackageloaded{floatrow}{%
  \renewcommand*{\tfl@make@pkg}{floatrow}
  \renewcommand*{\tfl@make@execute}{\@firstofone}
}{%
  \@ifpackageloaded{float}{%
    \renewcommand*{\tfl@make@pkg}{float}
    \renewcommand*{\tfl@make@execute}{\AtBeginDocument}
  }{%
    \@ifclassloaded{memoir}{%
      \renewcommand*{\tfl@make@pkg}{memoir}
      \renewcommand*{\tfl@make@execute}{\AtBeginDocument}
    }{%
      \iftfl@floatrow
        \RequirePackage{floatrow}
        \renewcommand*{\tfl@make@pkg}{floatrow}
        \renewcommand*{\tfl@make@execute}{\@firstofone}
      \else
        \RequirePackage{float}
        \renewcommand*{\tfl@make@pkg}{float}
        \renewcommand*{\tfl@make@execute}{\AtBeginDocument}
      \fi
    }%
  }%
}
%    \end{macrocode}    
%
%\begin{macro}{tfl@float@cnt}
% A track is needed of the number of floats created.
%    \begin{macrocode}
\newcounter{tfl@float@cnt}
%    \end{macrocode}
%\end{macro}
%\begin{macro}{\tfl@floatname}
% The name of the float currently being made.
%    \begin{macrocode}
\newcommand*{\tfl@floatname}{}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tfl@chapter}
%\begin{macro}{\tfl@chapter@hook}
% A method to add to the \cs{@chapter} macro is needed.  This is
% not compatible with \cs{g@addto@macro} directly, so a more
% complex method is used by providing a suitable hook.
%    \begin{macrocode}
\newcommand*{\tfl@chapter@hook}{}
\newcommand*{\tfl@chapter}{}
\ifx\@chapter\@undefined\else
  \let\tfl@chapter\@chapter
  \renewcommand*{\@chapter}{%
    \tfl@chapter@hook
    \tfl@chapter
  }
\fi
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\begin{macro}{\tfl@chapter@fix}
% So that floats inside chapters work correctly.
%    \begin{macrocode}
\newcommand*{\tfl@chapter@fix}[2]{%
  \g@addto@macro{\tfl@chapter@hook}{%
    \addtocontents{#2}{\protect\addvspace{10\p@}}%
  }%
  \@ifundefined{KOMAScriptVersion}{%
    \@namedef{the#1}{%
      \ifnum\c@chapter>\z@\relax
        \thechapter.%
      \fi 
      \arabic{#1}%
    }%
  }{}%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tfl@generate@ext}
%\changes{v1.2}{2007/08/20}{Removed \texttt{los} from list of possible
%  extensions}
%\begin{macro}{\tfl@ext}
% 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.
% The extensions \texttt{lof}, \texttt{log} and \texttt{lot} are taken
% by default, so they are not used.  The \pkg{chemscheme} package uses 
% \texttt{los}, so this is left alone as well. Also notice that if 
% people try to make too many new float types, then extension 
% \texttt{xxx} will be used.  This is very unlikely, but odd things 
% might happen so we warn them.
%    \begin{macrocode}
\newcommand*{\tfl@generate@ext}{%
  \edef\tfl@ext{%
    \ifcase\value{tfl@float@cnt}% 0 not possible
    \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
      lou%
    \or % 18
      lov%
    \or % 19
      low%
    \or % 20
      lox%
    \or % 21
      loy%
    \or % 22
      loz%
    \else % 23 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@make@float}
% When using \pkg{float}, definition depends on the existence of
% chapters. The name and ``list of'' macros are then created separately.
%    \begin{macrocode}
\newcommand*{\tfl@make@float}[2]{%
  \@ifundefined{chapter}{%
    \newfloat{#1}{tbp}{#2}%
  }{%
    \newfloat{#1}{tbp}{#2}[chapter]%
    \tfl@chapter@fix{#1}{#2}%
  }%
  \floatname{#1}{\@nameuse{#1name}}%
  \@namedef{listof#1s}{%
    \listof{#1}{\@nameuse{list#1name}}%
  }%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tfl@make@floatrow}
% For \pkg{floatrow}, the interface to everything is rather simple. The
% name here cannot use the original macros created by \pkg{trivfloat}, 
% which results in an infinite loop.
%    \begin{macrocode}
\newcommand*{\tfl@make@floatrow}[2]{%
  \@ifundefined{chapter}{%
    \DeclareNewFloatType{#1}{%
      fileext   = #2,
      placement = tbp,
      name      = {%
        \tfl@bgroup
        \tfl@name@format
        \tfl@upperfirst#1%
        \tfl@egroup
      } 
    }%
  }{%
    \DeclareNewFloatType{#1}{%
      fileext   = #2,
      placement = tbp,
      name      = {%
        \tfl@bgroup
        \tfl@name@format
        \tfl@upperfirst#1%
        \tfl@egroup
      }, 
      within    = chapter
    }%
    \tfl@chapter@fix{#1}{#2}%
  }%
  \@namedef{listof#1s}{%
    \listof{#1}{\@nameuse{list#1name}}%
  }%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tfl@make@memoir}
% \pkg{memoir} has a lot of things to set up for a float. This list is
% essentially the same as the \pkg{memoir} kernel uses.
%    \begin{macrocode}
\newcommand*{\tfl@make@memoir}[2]{%
  \newfloat[chapter]{#1}{#2}{\@nameuse{#1name}}%
  \newlistof{listof#1s}{#2}{\@nameuse{list#1name}}%
  \addtodef{\@smemfront}{}{\counterwithout{#1}{chapter}}%
  \addtodef{\@smemmain}{}{%
    \ifartopt\else
      \counterwithin{#1}{chapter}%
    \fi
  }%
  \addtodef{\backmatter}{}{%
    \ifartopt\else
      \counterwithout{#1}{chapter}%
      \setcounter{#1}{0}%
    \fi
  }%
  \newlistentry[chapter]{#1}{#2}{0}%
  \cftsetindents{#1}{0em}{2.3em}%
  \addtodef{\insertchapterspace}{}{%
    \addtocontents{#2}{\protect\addvspace{10pt}}%
  }%
  \ifartopt
    \counterwithout{#1}{chapter}%
  \fi
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tfl@make@names}
% The names for things are made in the same way for all float generation
% methods. The plural here is of course a guess!
%    \begin{macrocode}
\newcommand*{\tfl@make@names}{%
  \expandafter\edef\csname\tfl@floatname name\endcsname{%
    \noexpand\tfl@bgroup
    \noexpand\tfl@name@format
    \noexpand\tfl@upperfirst\tfl@floatname
    \noexpand\tfl@egroup
  }%
  \expandafter\edef\csname list\tfl@floatname name\endcsname{%
    List of \noexpand\tfl@upperfirst\tfl@floatname s
  }%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tfl@trivfloat}
% The internal macro which does the work. The \cs{edef} here makes sure
% that the name and extension are correct.
%    \begin{macrocode}
\newcommand*{\tfl@trivfloat}{%
  \stepcounter{tfl@float@cnt}%
  \tfl@generate@ext
  \tfl@make@names
  \begingroup
  \edef\@tempa{%
    \endgroup
    \expandafter\noexpand\tfl@make@execute{%
    \expandafter\noexpand\csname tfl@make@\tfl@make@pkg\endcsname
      {\tfl@floatname}{\tfl@ext}%
    }%
  }%
  \@tempa
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\tfl@uppercase}
%\begin{macro}{\tfl@uppercase@aux}
%\changes{v1.3a}{2007/08/22}{New macro}
% To get the correct kerning, a customised version of
% \cs{MakeUppercase} is needed. The use of 
% \cs{DeclareRobustCommand} here is essential. The change here is that
% the upper-cased letter is available outside of the group, hence using
% \cs{tfl@uppercase@aux} rather than \cs{reserved@a} as in the original.
%    \begin{macrocode}
\newcommand*{\tfl@uppercase}{}
\DeclareRobustCommand*{\tfl@uppercase}[1]{%
  {%
    \def\i{I}%
    \def\j{J}%
    \def\reserved@a##1##2{\let##1##2\reserved@a}%
    \expandafter\reserved@a\@uclclist\reserved@b{\reserved@b\@gobble}%
    \protected@edef\tfl@uppercase@aux{\uppercase{#1}}%
  \expandafter}%
  \tfl@uppercase@aux
}
\newcommand*{\tfl@uppercase@aux}{}
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\begin{macro}{\tfl@upperfirst}
%\changes{v1.2}{2007/08/20}{Made names change case correctly}
%\changes{v1.3}{2007/08/21}{Replaces \cs{tfl@genname} and
%  \cs{tfl@gennamea}}
%\changes{v1.3}{2007/08/21}{New macro}
%\changes{v1.3a}{2007/08/22}{Uses modified version of
%  \cs{MakeUppercase}}
% As suggested by Ulrich Diez, this is an improved method for making
% case changes than the previous version (v1.2).  Notice that it does
% mean that the user is responsible for the case of everything except
% the first letter.
%    \begin{macrocode}
\newcommand*{\tfl@upperfirst}[1]{%
  \protect\@gobble\noexpand\tfl@uppercase#1%
}
%    \end{macrocode}
%\end{macro}
%
%\begin{macro}{\trivfloat}
%\changes{v1.3}{2007/08/21}{Removed redundant numeral-based code}
%\changes{v1.4}{2009/04/23}{Extended to accept a comma-separated list}
% The user \cs{trivfloat} macro works by looping over each new float and
% calling the  internal macro \cs{tfl@trivfloat}
%    \begin{macrocode}
\newcommand*{\trivfloat}[1]{%
  \@for\tfl@floatname:=#1\do{%
    \tfl@trivfloat
  }%
}
\@onlypreamble\trivfloat
%    \end{macrocode}
%\end{macro}
%    
%\begin{macro}{\tfl@bgroup}
%\begin{macro}{\tfl@egroup}
%\begin{macro}{\tfl@name@format}
% When using \pkg{babel} in French, the caption format gets changed.
% This has to be tested twice: once to see if \pkg{babel} was loaded
% before \pkg{trivfloat} and once afterwards.
%    \begin{macrocode}
\newcommand*{\tfl@bgroup}{}
\let\tfl@bgroup\relax
\newcommand*{\tfl@egroup}{}
\let\tfl@egroup\relax
\newcommand*{\tfl@name@format}{}
\let\tfl@name@format\relax
\AtBeginDocument{%
\@ifpackageloaded{babel}{%
  \iflanguage{french}{%
    \let\floatc@plain\FB@makecaption
    \let\tfl@bgroup\bgroup
    \let\tfl@egroup\egroup
    \let\tfl@name@format\scshape
  }{}%
}{}%
}%
%</package>
%    \end{macrocode}
%\end{macro}
%\end{macro}
%\end{macro}
%
%\Finale