# Output and Code on the same Sheet

I'm thinking of creating a query material so that I can see the compilation result with your code just below.

As I'm starting in this TEX world, I do not want to accumulate multiple TEX files on my system. I'd rather create a PDF that has everything I'm studying.

I was advised to use the tcolorbox package, but I do not think I did anything right.

I tried to compile the code below, but I did not succeed.

\documentclass{article}
\usepackage{tcolorbox}
\usepackage[listings]{tcolorbox}
\usepackage{tikz}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview} \PreviewEnvironment{tikzpicture} \setlength{\PreviewBorder}{10pt}%
%%%>
\usetikzlibrary{calc}
\usepackage{amssymb}

%----------------------------------------------------------------------------------------
%   Definition in the preamble
%----------------------------------------------------------------------------------------
\tcbset{
texexp/.style={colframe=red!50!yellow!50!black, colback=red!50!yellow!5!white,
coltitle=red!50!yellow!3!white,
fonttitle=\small\sffamily\bfseries, fontupper=\small, fontlower=\small},
example/.style 2 args={texexp,
title={Example \thetcbcounter: #1},label={#2}},
}
\newtcblisting{texexp}[1]{texexp,#1}
\newtcblisting[auto counter,number within=section]{texexptitled}[3][]{%
example={#2}{#3},#1}
\newtcolorbox[use counter from=texexptitled]{texexptitledspec}[3][]{%
example={#2}{#3},#1}

\begin{document}

\begin{tikzpicture}
\draw[dashed,color=gray] (0,0) arc (-90:90:0.5 and 1.5);
\draw[semithick] (0,0) -- (4,1);
\draw[semithick] (0,3) -- (4,2);
\draw[semithick] (0,0) arc (270:90:0.5 and 1.5); \draw[semithick] (4,1.5) ellipse (0.166 and 0.5);
\draw (-1,1.5) node {$\varnothing d_1$};
\draw (3.3,1.5) node {$\varnothing d_2$};
\draw[|-,semithick] (0,-0.5) -- (4,-0.5);
\draw[|->,semithick] (4,-0.5) -- (4.5,-0.5);
\draw (0,-1) node {$x=0$};
\draw (4,-1) node {$x=l$};
\end{tikzpicture}

\end{document}


And just below the PDF template I want to create:

EDIT

I was able to advance a little more with the help of Christian-Hupfer.

My attempt:

\documentclass{article}

\usepackage[most]{tcolorbox}
\begin{document}

\begin{tcblisting}{% Some options here
}
\newcommand{\codewithoutput}[1]
{
\begin{tikzpicture}
\draw[dashed,color=gray] (0,0) arc (-90:90:0.5 and 1.5);
\draw[semithick] (0,0) -- (4,1);
\draw[semithick] (0,3) -- (4,2);
\draw[semithick] (0,0) arc (270:90:0.5 and 1.5); \draw[semithick] (4,1.5) ellipse (0.166 and 0.5);
\draw (-1,1.5) node {$\varnothing d_1$};
\draw (3.3,1.5) node {$\varnothing d_2$};
\draw[|-,semithick] (0,-0.5) -- (4,-0.5);
\draw[|->,semithick] (4,-0.5) -- (4.5,-0.5);
\draw (0,-1) node {$x=0$};
\draw (4,-1) node {$x=l$};
\end{tikzpicture}
}
\codewithoutput{\LaTeX}
\end{tcblisting}
\end{document}


• Have a look at tcolorbox and its listings. – TeXnician Jun 27 '17 at 17:36
• @TeXnician thank you. It will be a good help. I still do not have much knowledge of the language and I have no idea what to consult. – LCarvalho Jun 27 '17 at 17:46
• You could start with the documentation on CTAN (ctan.org/pkg/tcolorbox) on page 323 and following. – TeXnician Jun 27 '17 at 17:49
• @LCarvalho: See my answer to this question here: tex.stackexchange.com/questions/279068/… -- it uses tcolorbox, listings and code and code output – user31729 Jun 27 '17 at 19:20
• @ChristianHupfer Ok I will see. Grateful. – LCarvalho Jun 27 '17 at 19:22

Through Christian Hupfer´s comment:

\documentclass{article}

\usepackage[most]{tcolorbox}

\begin{document}

\begin{tcolorbox}

\begin{tcblisting}{colback=red!5!white,colframe=red!75!black,title=TRONCO DE CONE}

\begin{tikzpicture}
\draw[dashed,color=gray] (0,0) arc (-90:90:0.5 and 1.5);
\draw[semithick] (0,0) -- (4,1);
\draw[semithick] (0,3) -- (4,2);
\draw[semithick] (0,0) arc (270:90:0.5 and 1.5); \draw[semithick]
(4,1.5) ellipse (0.166 and 0.5);
\draw (-1,1.5) node {$\varnothing d_1$};
\draw (3.3,1.5) node {$\varnothing d_2$};
\draw[|-,semithick] (0,-0.5) -- (4,-0.5);
\draw[|->,semithick] (4,-0.5) -- (4.5,-0.5);
\draw (0,-1) node {$x=0$};
\draw (4,-1) node {$x=l$};
\end{tikzpicture}

\end{tcblisting}

\end{tcolorbox}

\end{document}


• When I try to compile that, I get an error: /tcbdemo.tex:9: Package pgfkeys Error: I do not know the key \'/tcb/texexp\' and I am going to ignore it. Perhaps you misspelled it. – murray Jun 28 '17 at 16:41
• @LCarvalho: Ignoring errors is no good idea: You have taken fragments from the tcolorbox manual and glued it to something that does not really works (and that's what I did not recommend really) – user31729 Jun 28 '17 at 18:45
• @ChristianHupfer I will follow your advice and I will study a solution ... – LCarvalho Jun 28 '17 at 18:57
• @LCarvalho: Just use the options from your tcolorbox environment and replace texexp with this options, then remove the wrapping tcolorbox environment – user31729 Jun 28 '17 at 19:06
• Why are you nesting the listing box in the outer tcolorbox? That will not be breakable, if needed and doesn't look very nice – user31729 Jun 30 '17 at 19:18