Introduction
I was preparing some examples of how to use LaTeX and then I found out the package showexpl (showexpl) which worked much better than others such as verbatim, moreverb and fancyvrb-ex. Mainly because it not only shows source code and results but also has access to any style defined by the listings package through lstdefinestyle.
One day, I had to insert (external) files with preamble (\documentclass{} and \begin{document}) as examples, and showexpl also worked fine.
Later, I learned about tcolorbox (tcolorbox) and its large set of possibilities and flexibilities.
The following images are from the MWE below and ilustrates both styles.
I could then create new styles to LaTeX examples until the point I had to use files with preamble.
In this case, there a solution inserting the generated PDF, which by the way is indeed much better than I had with pdfpages. But it needs some clipping as follows.
Main issue
An alternative I built was to insert \LTXinputExample inside a tcolorbox, but I don't understand how could I format the box as I previously did. I mean, bicolor with the division dashed line (overlay, since bicolor seems to remove the default separation line).
Questions
Is there any method to get the style from section (3) (MWE) of
tcolorboxwith an example that contains preamble without loading the PDF as a comment?If 1 is false. Is there any method the make the clipping of PDF automatically find the boundaries of the text? (some math with
\textwidthand others measures ingraphics options={viewport=5cm 24.5cm 8cm 25.5cm,clip}?)If 2 is false. Is there any method to format the box with two colors and a corrected place division line.
OBS: I'm aware I don't need to present every single result of every single example source. What bothers me is the impossibility of not being able to get style (3) with tcolorbox when there is a preamble in the example.
Sources
- Article example inside beamer frame
- How to use showexpl with an external class?
- `showexpl` doesn't work with accents
- showexpl LTXexample and references inside enumerate
External file and MWE
File: input_example
This is {\LaTeX}.
File: input_example_preamble
\documentclass{article}
\begin{document}
This is {\LaTeX}.
\end{document}
MWE with listing and tcolorbox styles
\documentclass{article}
\usepackage{showexpl}
\usepackage[skins,listings,breakable,raster]{tcolorbox}
\lstdefinestyle{estiloExemVerm}{
numbers=left,
numbersep=1em,
numberstyle=\tiny,
frame=single,
framesep=\fboxsep,
framerule=\fboxrule,
xleftmargin=\dimexpr\fboxsep+\fboxrule\relax,
xrightmargin=\dimexpr\fboxsep+\fboxrule\relax,
breaklines=true,
breakatwhitespace=true,
keepspaces=true,
breakindent=0pt,
tabsize=2,
columns=flexible,
language={[LaTeX]TeX},
aboveskip=0.1em,
belowskip=1.0em,
basicstyle=\small\ttfamily\hbox{},
pos=r,
width=0.5\linewidth,
preset=\small\setlength{\parindent}{10pt},
extendedchars=true,
keywordstyle=\color{red},
rulecolor=\color{red},
backgroundcolor=\color{white}
}
\newtcbinputlisting[]{\mytcbRed}[2][]{%
bicolor,
lower separated=true,
colbacklower=white,
fonttitle=\large\sffamily\bfseries,
breakable,
listing and text,
colframe=red!70!black, colback=red!10!white, coltitle=red!10!white,
sidebyside,
overlay={
\draw[dashed, red!80!black,thick] (segmentation.north)--(segmentation.south);
},
listing options={style=estiloExemVerm},
listing file={#2}, #1
}
\newtcbinputlisting[]{\mytcbInputListing}[2][]{%
enhanced,
colback=red!10!white, colframe=red!70!black, fonttitle=\large\sffamily\bfseries,
sidebyside, bicolor, colbacklower=white,
listing and comment,
overlay={
\draw[dashed, red!80!black,thick] (segmentation.north)--(segmentation.south);
},
listing options={style=estiloExemVerm},
listing file={#2},
pdf comment={#2.pdf},
% comment style={raster columns=1, colframe=red!85!black, boxrule=2pt, %drop fuzzy shadow, %shadow={2mm}{-2mm}{0mm}{black!50!white},
% graphics options={viewport=5cm 24.5cm 8cm 25.5cm,clip}},
#1,
}
\begin{document}
\section{LTXinputExample -- preamble}
\LTXinputExample[style=estiloExemVerm]{input_example_preamble}
\section{LTXinputExample -- without preamble}
\LTXinputExample[style=estiloExemVerm]{input_example}
\section{tcbinputlisting -- without preamble}
\mytcbRed{input_example}
\section{tcbinputlisting -- preamble -- PDF}
\mytcbInputListing{input_example_preamble}
\mytcbInputListing[comment style={raster columns=1, colframe=red!85!black, boxrule=2pt,
graphics options={viewport=5cm 24.5cm 8cm 25.5cm,clip}}]{input_example_preamble}
\section{LTXinputExample -- preamble -- inside tcolobox}
\begin{tcolorbox}[colframe=red!70!black, colback=red!10!white, coltitle=red!10!white]
\LTXinputExample[style=estiloExemVerm]{input_example_preamble}
\end{tcolorbox}
\begin{tcolorbox}[
bicolor,
lower separated=true,
breakable,
colframe=red!70!black, colback=red!10!white, coltitle=red!10!white,
colbacklower=white,
%sidebyside,
overlay={
\draw[dashed, red!80!black,thick] (segmentation.north)--(segmentation.south);
},
]
\LTXinputExample[style=estiloExemVerm, rframe={}]{input_example_preamble}
\end{tcolorbox}
\end{document}



standalonepackage loaded,\tcbinputlisting{listing file=input_example_preamble, sidebyside}would do part of the job. But it gets more complex if you don't want to fully ignore the preamble of subfile. – muzimuzhi Z Nov 27 '20 at 10:33standalonesolves the preamble part of the job, but the idea of the example is have something functional in a file, that an be showed at other file, pretty much that's possible withshowexplthrough\LTXinputExample. I got pretty close in section 4, which would be perfect if I could answer Q2 to automatically find the limits of the text as I manually did. At the moment, this is the best solution (with these restrictions) I found out. – FHZ Nov 30 '20 at 01:25