简体   繁体   中英

Temporarily changing document class in LaTeX/resetting pdfLaTeX

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

I think that the easiest way of doing this is to compile some small document and then include the resultant pdf as an image into the larger document. Much simpler even if not exactly what you want. I have done this to show, in a Beamer presentation, what LaTeX articles look like.

Of course if its a REALLY simple document (eg, a simple block of text) that you want to have inside beamer, I could recommend that you mimic the document with a TikZ "picture" that contains some text.

Maybe another approach: instead of trying to typeset things in beamer as if they would be done in article, simply typeset them with the article document class and include the result the in the beamer document.

With tcolorbox this can be done automatically:

% !TeX program = txs:///arara
% arara: pdflatex: {synctex: on, interaction: nonstopmode, shell: yes}

\documentclass{beamer}
\usepackage[most]{tcolorbox}

\begin{document}

\begin{frame}[fragile]

\begin{tcblisting}{
    comment only,
  pdf comment,
  compilable listing,
  run pdflatex,
}
\documentclass{article}
\begin{document}
\section{Section Title}
test
\end{document}
\end{tcblisting}

\end{frame}

\end{document}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM