The sepfigs package^{∗}

Andrew D. Lewis

1998/03/05

1 Using the sepfig macros

The basic idea of sepfigs is to allow you to have all the figures appear at the end of the document. This borrows heavily from Jeff Goldberg’s endfloat. I have tried to improve its flexibility and features, and in doing so have changed it substantially in structure.

1.1 Options

I tried to build a large degree of flexibility into sepfigs by making certain behaviour controllable by options. These are as follows.

display Selecting this option will ensure the figures are displayed at the end of the document.

nodisplay In this case, the figures will not appear. This can save printing time, etc.

figlist A list of figures is generated.

nofiglist No figure list is generated.

write The figures created in the document will be built anew.

nowrite The existing figures from previous runs will not be overwritten by the ones from this run. I recall this feature being useful for something — can’t remember what now though.

The defaults are nodisplay, nofiglist, and nowrite.

1.2 Usage

Well, there shouldn’t be much to say here. Just load the package with the options you want and the figures should appear at the end (or not depending on the options you select).

∗This file has version number v1.0a, last revised 1998/03/05.

2 Implementation

1 ⟨∗package⟩

The initial part of the file is dedicated to the options and the commands to be run when the options are specified. Nothing fancy here.

2

 3 \newif\if@ADL@figlist\global\@ADL@figlistfalse
 4 \newcommand\@ADL@figlist{\global\@ADL@figlisttrue
 5 \PackageWarning{sepfigs}{Making figure list}}
 6 \newcommand\@ADL@nofiglist{\global\@ADL@figlistfalse
 7 \PackageWarning{sepfigs}{Not making figure list}}

8

 9 \newif\if@ADL@displayfigs\global\@ADL@displayfigsfalse
10 \newcommand\@ADL@displayfigs{\global\@ADL@displayfigstrue
11 \PackageWarning{sepfigs}{Displaying figures at end of document}}
12 \newcommand\@ADL@nodisplayfigs{\global\@ADL@displayfigsfalse
13 \PackageWarning{sepfigs}{Not displaying figures at end of document}}

14

15 \newif\if@ADL@write\global\@ADL@writefalse
16 \newcommand\@ADL@write{\global\@ADL@writetrue
17 \PackageWarning{sepfigs}{Writing new figures to \jobname.figs}}
18 \newcommand\@ADL@nowrite{\global\@ADL@writefalse
19 \PackageWarning{sepfigs}{Not writing new figures}}

20

21 \DeclareOption{display}{\@ADL@displayfigs}
22 \DeclareOption{nodisplay}{\@ADL@nodisplayfigs}
23 \DeclareOption{figlist}{\@ADL@figlist}
24 \DeclareOption{nofiglist}{\@ADL@nofiglist}
25 \DeclareOption{write}{\@ADL@write}
26 \DeclareOption{nowrite}{\@ADL@nowrite}
27 \ProcessOptions

Here’s the internal file handling macros. \@ADL@postfigs gets assigned to the file \jobname.figs and to this file are written the L^{A}TEX commands for the figures. These then get read in at the end of the document.

28

29 \newwrite\@ADL@postfigs
30 \newif\if@ADL@postfigsopen\global\@ADL@postfigsopenfalse
31 \newcommand\@ADL@openpostfigs{\immediate\openout\@ADL@postfigs=\jobname.figs
32 \relax\message{(\jobname.figs)}%
33 \global\@ADL@postfigsopentrue}

Here are a few internal macro definitions. Just shorthands.

34

35 \@ifundefined{makeinnocent}{\newcommand\makeinnocent[1]{\catcode`#1=12 }}{}
36 \def\@ADL@gobbleuntilnext[#1]{}
37 \let\@ADL@bfig\figure
38 \let\@ADL@efig\endfigure
39 \let\endfigure\relax

Here’s the new definition of the figure environment. It opens the .figs file if it’s not already open, and writes the figure commands to it. The hard part here is that the lines haves to be scanned for \end{figure} so it stops writing.

40

41 \renewcommand\figure{%
42  \if@ADL@write\if@ADL@postfigsopen \else \@ADL@openpostfigs \fi\fi%
43  \@ADL@optwrite{\string\begin{figure}}%
44  \def\@currenvir{figure}%
45  \begingroup%
46  \let\do\makeinnocent \dospecials%
47  \makeinnocent\^^L% and whatever other special cases
48  \endlinechar`\^^M \catcode`\^^M=12 \xfigure}%
49 {\catcode`\^^M=12 \endlinechar=-1 %
50 \gdef\xfigure#1^^M{\def\test{#1}%
51  \ifx\test\endfiguretest%
52  \def\next{\endgroup\end{figure}%
53  \@ADL@optwrite{\string\end{figure}}%
54  \@ADL@optwrite{\string\clearpage}%
55  \@ADL@optwrite{ }}%
56  \else\ifx\test\enddblfiguretest%
57  \def\next{\endgroup\end{figure}%
58  \@ADL@optwrite{\string\end{figure}}%
59  \@ADL@optwrite{\string\clearpage}%
60  \@ADL@optwrite{ }}%

61 %

62  \else\@ifnextchar[%
63  \@whilesw \ifx\test\CB \fi%
64  \@gobble%
65  \else%
66  \if@ADL@write\if@ADL@postfigsopen \else \@ADL@openpostfigs \fi\fi%
67  \@ADL@optwrite{#1}%
68  \let\next\xfigure%
69  \fi \fi \next}%
70 }%
71 \@namedef{figure*}{\figure}

This command is used to write the stuff to the file (depending on whether you have chosen the write option.

72

73 \newcommand\@ADL@optwrite[1]{\if@ADL@write\immediate\write\@ADL@postfigs{#1}
74 \else\relax\fi}

These are the characters which get tested when we are trying to stop writing figures.

75

76 {\escapechar=-1%
77 \xdef\CB{]}%
78 \xdef\endfiguretest{\string\\end\string\{figure\string\}}%
79 \xdef\enddblfiguretest{\string\\end\string\{figure*\string\}}%
80 }%

\@ADL@makeemptyfigs is used when we reach the end of the file and we have chosen not to display the figures. It simply undefines all the possible figure commands which come from floatlib (it doesn’t matter if you are not using floatlib). Also in this chunk of the code are the commands to which the floatlib figure commands get assigned. These are all given the value \relax.

81

 82 \newcommand\@ADL@makeemptyfigs{\global
 83 \let\@ADL@makecaption\@ADL@empty@makecaption
 84 \global\let\cfigure\@ADL@emptyfigure
 85 \global\let\ctwofigure\@ADL@emptyctwofigure
 86 \global\let\@ADL@@dblcaption\@ADL@empty@@dblcaption
 87 \global\let\clearpage\relax}

88

 89 \let\@ADL@clearpage\clearpage

90

 91 \newcommand\@ADL@empty@makecaption[2]{\relax}

92

 93 \def\@ADL@empty@@dblcaption#1[#2]#3{\relax}

94

 95 \newcommand\@ADL@emptycfigure{\@ifnextchar[{\@ADL@@emptycfigure}
 96 {\@ADL@@emptycfigure[d]}}

97

 98 \def\@ADL@@emptycfigure[#1]#2{\relax}

99

100 \newcommand\@ADL@emptyctwofigure{\@ifstar{\@ADL@@emptyctwofigure}
101 {\@ADL@@emptyctwofigure}}
102 \newcommand\@ADL@@emptyctwofigure{\@ifnextchar[{\@ADL@@@emptyctwofigure}
103 {\@ADL@@@emptyctwofigure[d]}}
104 \def\@ADL@@@emptyctwofigure[#1]#2#3{\relax}

The command \processfigures is executed at the end of the document. It simply closes the file to which the figures were being written and then reads it (if that’s what you want.

105

106 \newcommand\processfigures{
107 \if@ADL@postfigsopen
108 \immediate\closeout\@ADL@postfigs \global\@ADL@postfigsopenfalse\fi
109 \let\figure\@ADL@bfig
110 \let\endfigure\@ADL@efig
111 \clearpage
112 \if@ADL@figlist
113  {\normalsize\listoffigures}
114  \clearpage
115 \fi
116 \if@ADL@displayfigs\else\@ADL@makeemptyfigs\fi
117 \@input{\jobname.figs}\let\clearpage\@ADL@clearpage}

118

119 \AtEndDocument{\processfigures}

120

121 ⟨/package⟩