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.

FifteenBoxes, verbatims and files<strong>The</strong> title of this chapter indicates that it deals with three disconnected topics, but there ismethod in the seeming peculiarity. By the end of the chapter you will be able to writeLa<strong>TeX</strong> code that lets you put things in your document source at one place and have themtypeset at a different place, or places. For example, if you are writing a text book thatincludes questions and answers then you could write a question and answer together yethave the answer typeset at the end of the book.Writing in one place and printing in another is based on outputting stuff to a file andthen inputting it for processing at another place or time. This is just how La<strong>TeX</strong> producesthe ToC. It is often important when writing to a file that La<strong>TeX</strong> does no processing of anymacros, which implies that we need to be able to write verbatim. One use of verbatim inLa<strong>TeX</strong> is to typeset computer code or the like, and to clearly distinguish the code from themain text it is often typeset within a box. Hence the chapter title.<strong>The</strong> <strong>class</strong> extends the kinds of boxes normally provided, extends the default verbatims,and provides a simple means of writing and reading files.One problem with verbatims is that they can not be used as part of an argument to acommand. For example to typeset something in a framed minipage the obvious way is touse the minipage as the argument to the \fbox macro:\fbox{\begin{minipage}{6cm}Contents of framed minipage\end{minipage}}This works perfectly well until the contents includes some verbatim material, whereuponyou will get nasty error messages. However this particular conundrum is solvable, even ifthe solution is not particularly obvious. Here it is.We can put things into a box, declared via \newsavebox, and typeset the contents ofthe box later via \usebox. <strong>The</strong> most common way of putting things into a save box isby the \sbox or \savebox macros, but as the material for saving is one of the argumentsto these macros this approach fails. But, lrbox is an environment form of \sbox, so itcan handle verbatim material. <strong>The</strong> code below, after getting a new save box, defines anew framedminipage environment which is used just like the standard minipage. <strong>The</strong>framedminipage starts an lrbox environment and then starts a minipage environment,after which comes the contents. At the end it closes the two environments and calls \fboxwith its argument being the contents of the saved box which have already been typeset.\newsavebox{\minibox}\newenvironment{framedminipage}[1]{%\begin{lrbox}{\minibox}\begin{minipage}{#1}}%273Chapter last updated 2013/04/24 (revision 442)

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

Saved successfully!

Ooh no, something went wrong!