I'm writing a small tutorial about LaTeX. So I'd like to insert some code and obtain the result on the right.
I'm almost there. I got the desired output but I'd like something more clear, that is, an easier to type the code.
Consider the following MWE:
\documentclass[draft,11pt,a4paper]{article}
\usepackage{showexpl}
\usepackage[section]{minted}
\newminted{tex}{
bgcolor=bg,
gobble=1,
linenos=true,
firstline=1,
firstnumber=1,
fontfamily=courier,
fontsize=\footnotesize,
numberblanklines=false,
numbersep=3mm,
xleftmargin=6mm,
xrightmargin=5mm,
}
\definecolor{bg}{rgb}{0.95,0.95,0.95}
\usepackage{lipsum}
\newlength\ideal
\setlength{\ideal}{.5\linewidth - 2\fboxsep -2\fboxrule}
\begin{document}
\lipsum[4]
\begin{listing}
\begin{texcode}
\begin{equation}
\frac{3}{2}=\frac{a}{b}
\end{equation}
\end{texcode}
\end{listing}
\lipsum[4]
\begin{listing}
\begin{minipage}{\ideal}
\begin{texcode}
\begin{equation}
\frac{3}{2}=\frac{a}{b}
\end{equation}
\end{texcode}
\end{minipage}
\hfill
\begin{minipage}{\ideal}
\begin{equation}
\frac{3}{2}=\frac{a}{b}
\end{equation}
\end{minipage}
\caption{title}
\end{listing}
\lipsum[4]
\end{document}
The output is:
I'd like to know if this is the right way or if is possible to avoid typing code twice.
I'd like to define an environment myenv
and then obtain the same as Listing 0.1 simply using
\begin{myenv}
\begin{equation}
\frac{3}{2}=\frac{a}{b}
\end{equation}
\end{myenv}
And also the caption would be optional. I tried to use showexpl
but no success until now.
Edit
I've just found this topic but the result there does not produce the output on the right.
minted
? Would you consider usinglistings
?minted
for the colored code. Only this.