% \iffalse meta-comment % !TEX program = pdflatex % !TEX encoding = ISO-8859-1 %<*internal> \iffalse % %<*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. % %<*internal> \fi \def\nameofplainTeX{plain} \ifx\fmtname\nameofplainTeX\else \expandafter\begingroup \fi % %<*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 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}} } % %\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} % %<*package> \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{trivfloat} [2009/04/23 v1.4 Quick floats in LaTeX] % %<*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} % % \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 }{}% }{}% }% % % \end{macrocode} %\end{macro} %\end{macro} %\end{macro} % %\Finale