TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to create a new environment to provide some LaTeX code (or from other languages)

So far, I tried the following code

\usepackage{bclogo}
\newenvironment{code}
{   \begin{bclogo}
        [couleur = black!10, couleurBord = black!50,
        arrondi = 0.1, logo = \bccrayon]
        {Code \LaTeX :}

        \bigskip

        \begin{verbatim}
}
{       \end{verbatim}
    \end{bclogo}
}

But, this creates an error during the compilation...

! File ended while scanning use of \next. \par <*> essai3.tex

I suspect you have forgotten a '}', causing me to read past where you wanted me to stop. I'll try to recover; but if the error is serious, you'd better type E' orX' now and fix your file.

! Emergency stop. <*> essai3.tex

*** (job aborted, no legal \end found)

Here is how much of TeX's memory you used:

...

! ==> Fatal error occurred, no output PDF file produced!

If someone have an idea to get through this error, I would sincerely say "Thank you very much, Master"

share|improve this question
1  
Please have a look on tcolorbox and its tcblisting feature which provides nice boxes too combined with listings. – Christian Hupfer 2 hours ago

You can use fancyvrb:

\documentclass{article}

\usepackage{fancyvrb}

\usepackage[tikz]{bclogo}
\newenvironment{code}
{\VerbatimEnvironment
  \begin{bclogo}[couleur = black!10, couleurBord = black!50,
  arrondi = 0.1, logo = \bccrayon]
  {Code \LaTeX :}\par\nobreak\bigskip
  \begin{Verbatim}}
{\end{Verbatim}\end{bclogo}}

\begin{document}
\begin{code}
\documentclass{article}
\begin{document}
Hello
\end{document}
\end{code}
\end{document}

enter image description here

share|improve this answer
    
"Thank you very much, Master"!!!! That's perfect! – MathTolliob 1 hour ago

Nesting verbatim inside macros is not possible, but it is possible inside environments using the starter and 'end' - commands of the verbatim environment, i.e. \verbatim and \endverbatim.

At the end of my code answer I provide also a way with tcolorbox showing LaTeX code and its compilation:

\documentclass{article}

\usepackage{verbatim}

\usepackage[most]{tcolorbox}
\usepackage[tikz]{bclogo}
\newenvironment{code}
{%   
  \bclogo[couleur = black!10, couleurBord = black!50,
  arrondi = 0.1, logo = \bccrayon]
  {Code \LaTeX :}
  \bigskip
  \verbatim
}
{ 
  \endverbatim
  \endbclogo
}

\begin{document}
\begin{code}
\documentclass{article}
\usepackage[most]{tcolorbox}
\begin{document}
\begin{tcblisting}{listing only}

\end{tcblisting}

\end{document}
\end{code}

And a \verb!tcolorbox! version:

\begin{tcblisting}{colback={white!40!yellow}}
\LaTeXe\ is nice!
\end{tcblisting}

\end{document}


\end{document}

enter image description here

share|improve this answer
    
Thanks you very much for your rapid answer!! I had tried it before, and I still have the same error... I'm working with TexMaker on Mac Os X, and the coloration begins to be all red after my old "\begin{verbatim}" or the new "\verbatim", till the end of the file. Any idea? – MathTolliob 1 hour ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.