12.07.2015 Views

The memoir class - The UK TeX Archive

The memoir class - The UK TeX Archive

The memoir class - The UK TeX Archive

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

15. BOXES, VERBATIMS AND FILES\begin{boxedverbatim}...1 \newoutputstream{tryout}2 \openoutputfile{\jobname.fig}{tryout}3 \newcounter{pseudo}4 \renewcommand{\thefigure}{\thepseudo.\arabic{figure}}5 \newenvironment{writefigure}{%6 \ifnum\value{chapter}=\value{pseudo}\else7 \setcounter{pseudo}{\value{chapter}}8 \addtostream{tryout}{\protect\stepcounter{chapter}}9 \addtostream{tryout}{\protect\addtocounter{chapter}{-1}}10 \addtostream{tryout}{%11 \protect\setcounter{pseudo}{\thechapter}}12 \fi13 \addtostream{tryout}{\protect\begin{figure}}14 \writeverbatim{tryout}}%15 {\endwriteverbatim\finishwritefigure}16 \newcommand{\finishwritefigure}{%17 \addtostream{tryout}{\protect\end{figure}}}18 \newcommand{\printfigures}{%19 \closeoutputstream{tryout}%20 \input{\jobname.fig}%21 }<strong>The</strong> above code should be either put in the preamble or in a separate package file.<strong>The</strong> first four lines of the code perform the initial setup described earlier. Lines 1 and 2set up for outputting to a file \jobname.fig, which is where the figures will be collected.Lines 3 and 4 create the new counter we need and change the construction of the figurenumber. <strong>The</strong> rest of the code defines a new environment writefigure which is to be usedinstead of the figure environment. It writes its content out to the tryout stream.In line 6 a check is made to see if the current values of the chapter and pseudo countersare the same; nothing is done if they are. If they are different, it means that this isthe first figure in the chapter and we have to put appropriate information into the figurefile. Line 7 sets the pseudo counter to the value of the chapter counter (if there is anotherwritefigure in the chapter it will then skip over the code in lines 7 to 11). <strong>The</strong> next linesput (where N is the number of the current chapter):\stepcounter{chapter}\addtocounter{chapter}{-1}\setcounter{pseudo}{N}into the figure file. Stepping the chapter number (by one) resets the following figure number,and then subtracting one from the stepped number returns the chapter number to itsoriginal value. Finally the counter pseudo is set to the number of the current chapter.Line 13 puts290

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!