6

How can I temporarily cause pdfLaTeX to forget everything that I've told it and start with a new document class?

I've modified the example environment from the lshort document:

\newwrite\examplesx@out
\newenvironment{examplesx}{%
  \begingroup% Lets Keep the Changes Local
    \@bsphack
    \immediate\openout \examplesx@out \jobname.exa
    \let\do\@makeother\dospecials\catcode`\^^M\active
    \def\verbatim@processline{%
      \immediate\write\examplesx@out{\the\verbatim@line}}%
    \verbatim@start
  }{%
  \immediate\closeout\examplesx@out\@esphack\endgroup%
  \noindent\makebox[\textwidth][l]{%
    \begin{minipage}[c]{0.45\textwidth}%
      \small\verbatiminput{\jobname.exa}
    \end{minipage}%
    \hspace*{0.1\textwidth}%
    \framebox{%
      \begin{minipage}{0.45\textwidth}%
        \small\input{\jobname.exa}%
      \end{minipage}
    }%
  }\vspace*{\parskip}%
}

and it mostly works, but I want to be able to do something like

\begin{examplesx}
\section{Section}
\end{examplesx}

and have it show up as a section in a box. I also would like it to typeset lists using the standard article style, even if I use it in beamer

3

You can't. LaTeX assumes global operation most of the time.

With respect to the problem you're trying to solve, I don't think there are any "canned" workflows for doing this. My general approach is to

  1. write the example out into an auxiliary file (including some canned preamble),
  2. compile the auxiliary file separately using the preview package to get a cropped image, then
  3. insert it the generated image.

You can find a slightly complex example in the source to the fontspec documentation (fontspec.dtx) from the line starting \newenvironment{Fexample}. It uses fancyvrb to do the verbatim writing and the compilation is done ‘on-the-fly’ using \immediate\write18. (Otherwise you could use a shell script.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.