[Tex/LaTex] Show output of a full LaTeX document

pdftex

A couple of days ago, I found showexpl, it is wonderful and works very well. But there is one thing missing that it doesn't let me do and it is to only show the output/result of some commands. For little commands, there are no problems, a minipage inside an fbox works well, but for displaying titles and sections without affecting the number count in the document I have no idea how to do (except by embedded an image of the rendered document, which isn't that great of an idea).

For an example of what I am saying, I saw this a while ago while reading this tutorial (on page 4 there is an example of a document): https://dataninja.files.wordpress.com/2008/09/texpert2.pdf

Best Answer

You will need to manually rewind the counters after they have been executed, as well as write quite a few macros to save state and restore state. I use a similar package called tcolorbox, here is a MWE illustrating the technique for keeping section numbers consistent.

enter image description here

\documentclass{article}
\usepackage[listings]{tcolorbox}
\title{My Title}
\begin{document}
\makeatletter
\begin{tcblisting}{colback=blue!5,boxrule=2pt,colframe=blue!75!black,title=\textbf{Cases},width=1.05\textwidth}
\maketitle
\section{One}
\section{Two}
\end{tcblisting}
\advance\c@section by -2
\section{Test}
\end{document}

I am not aware of any package that can be used to run full minimal examples though. One way is to save them on disc using a verbatimwrite, execute them via enabling write18 and then import the pdf. Perhaps FMi can describe what they used when they wrote the LaTeX Companion.

Quick implementation hack to display MWE.

\newenvironment{tex}{\ttfamily\string\documentclass\{article\}\par\string\begin\{document\}
  \tcblisting{boxrule=0pt}}
{\endtcblisting\ttfamily\string\end\{document\}}
\begin{tex}
\section{test}
\end{tex}