I'd like to make an environment or command to wrap the this 2-column REPL formatting. For example, as a command (\format{TEXT}{CODE}
) it would look like this:
\format2cols{
Description of the code
}{
The actual code
}
Having a shortcut like this would clean up my document exponentially!
Here's what it looks like, with the TEXT is on the left and the CODE on the right:
The difficulty here is that LaTex doesn't allow for passing verbatim arguments. So I'm at an impasse.
MWE:
\documentclass{book}
\usepackage{a4wide}
\usepackage{tabularx}
\usepackage[]{sourcecodepro}
\usepackage[T1]{fontenc}
\usepackage{ragged2e}
\newlength\textlen
\newlength\codelen
\newlength\halflen
\setlength\halflen{\dimexpr.5\columnwidth-2\tabcolsep-0.5\arrayrulewidth\relax}
\setlength\textlen{.95\halflen}
\setlength\codelen{1.05\halflen}
\usepackage{color}
\definecolor{mygray}{rgb}{0.9,0.9,0.9}
\usepackage{minted}
\setminted{
baselinestretch=1,
tabsize=4,
fontsize=\fontsize{8}{11}
}
\begin{document}
\fontsize{12}{14}\selectfont
\justify
We restrict our sorting functions to permutations of the numbers $1\cdots n$. A simple way to visualize the amount of ``sortedness'' in such a list of numbers is a picture obtained with {\fontsize{10}{12}\selectfont\texttt{ListPlot}}.
\vspace{1.5mm}
{
\fontfamily{ptm}\selectfont
\fontsize{9}{11}\selectfont
\def\arraystretch{2}
\noindent\begin{tabular}{@{}p{\textlen}p{\codelen}@{}}
This definition is used to plot permutations of the numbers $1\cdots n$ with suitable settings of graphics options. &
\begin{minipage}[t]{0.5\textwidth}
\begin{minted}{Mathematica}
In[1]:= PermutationPlot[l_List, opts___] :=
ListPlot[ l,
PlotRange -> { {0.5, Length[l]+0.5},
{0.5, Length[l]+0.5} },
PlotStyle -> PointSize[0.75/Length[l]],
opts, Axes->None, FrameTicks->None,
Frame->True, AspectRatio->1 ]
\end{minted}
\end{minipage}
\end{tabular}
}
\vspace{1.5mm}
\justify
Sed efficitur diam eget ante elementum pharetra. Nullam dignissim pulvinar molestie. Sed dapibus tristique feugiat.
\end{document}
\fontsize
and similar macros is not recommended. If you want 12pt as default font size use it as a class option ([12pt]{book}
) and then use macros like\small
etc.