4

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"

3

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

  • "Thank you very much, Master"!!!! That's perfect! – MathTolliob Aug 18 '16 at 11:46
3

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

  • 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 Aug 18 '16 at 11:40
  • @MathTolliob: No, I haven't. I have shown you that it works on Linux and TL 2016, TeXMaker is an 'editor' only -- I don't use such 'editors' – user31729 Aug 18 '16 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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