[OS X TeX] Side by Side

Luis Sequeira lfsequeira at gmail.com
Mon Apr 4 09:53:32 CEST 2011


> 
> On 02/04/2011 05:06, Don Green Dragon wrote:
>> Hi All,
>> 
>> Reading The LaTeX Companion (2nd) is an exercise in frustration and amazement. What constantly amazes me are their displays where, for example, two boxes of prose will appear side by side. On page 140 there is an example wherein theorem-like environments are defined --- source code for that given --- then the typeset version of that code is placed "on the left" while the source code sits to the right. I understand the code, but have no clue how they set things up so that (roughly displayed)
>> 
>> Typeset version		Source code is to the
>> intrudes into		right of the typeset
>> left margin and		version and extends to
>> into the page		the regular right margin.
>> 
>> The example in question is 3-3-20. How in heavens name do they do that?
>> 
>> The above is prompted by trying to include a small figure as if it were in inline mode; ie., something like
>> 
>> 	The line begins here and the icon <<figure for icon>> is placed within the line.
>> 
>> I expected that what I tried would not work, and I was not disappointed!  ;-)
> 
> The way that it was done for the book was to use multiple LaTeX passes.
> Each example is a separate LaTeX file, which was compiled independently.
> The source was then included by reading the file verbatim, while the
> output went in as an image. This is mentioned at the end of the book.
> -- 
> Joseph Wright
> 
> 

This may have been the most adequate workflow for a complex and large body of work such as the book, but…

There are a few ways that a common user such as myself can achieve this. One simple way to achieve the desired effect is simply to combine multicols with a verbatim environment. 
I use the fancyvrb package, that gives a more sofisticated Verbatim (with capital V) environment. Try something like

\begin{multicols}{2}

your code

\columnbreak

\begin{Verbatim}
 your code
\end{Verbatim}
\end{multicols}


If the code is a bit large, then place it in a file - say, mycode.tex - and use the following

\begin{multicols}

\input{mycode}

\columnbreak

\VerbatimInput{mycode}

\end{multicols}

Depending on the code, you  may want or need to enclose it in a minipage environment, put a box around it, etc. - once you get the basic version working, use the regular LaTeX constructs, and the several options in the fancyvrb package, to get both the typeset code and its source to display exactly as you want.

Here is a small compilable example that places the typeset code inside a box on the left, and the source on the right. Note that many effects can be added to the Verbatim environment.


\documentclass{scrartcl}
\usepackage{fancyvrb}
\usepackage{multicol}

\begin{document}

Enumerations are easy to do in \LaTeX:

\begin{multicols}{2}

\fbox{\begin{minipage}{0.9\linewidth}
\begin{enumerate}
\item bla
\item ble
\item bli
\end{enumerate}
\end{minipage}}

\columnbreak

\begin{Verbatim}
\begin{enumerate}
\item bla
\item ble
\item bli
\end{enumerate}
\end{Verbatim}

\end{multicols}

\end{document}



Luis Sequeira







More information about the macostex-archives mailing list