1

I have a setup that works OK as is. I needed to make this code as an environment so less typing. When I do that I get an error.

Here is the original setup

\documentclass[12pt,titlepage]{article}
\usepackage{fancybox,fancyvrb,xcolor}
\usepackage[listings,skins,breakable,xparse]{tcolorbox}

\begin{document} 

\begin{tcolorbox}[rounded corners,boxrule=.1pt,colframe=red!75!black,boxsep=2pt]%
\begin{Verbatim}
 some code here
\end{Verbatim}
\end{tcolorbox}
\end{document}

The above compile with no error. Now I did the following

\documentclass[12pt,titlepage]{article}
\usepackage{fancybox,fancyvrb,xcolor}
\usepackage[listings,skins,breakable,xparse]{tcolorbox}

\newenvironment{TEXTinline}%
{%
 \begin{tcolorbox}[rounded corners,boxrule=.1pt,colframe=red!75!black,boxsep=2pt]%
 \begin{Verbatim}
}%
{%
 \end{Verbatim}
 \end{tcolorbox}%
}%
\begin{document} 
    
\begin{TEXTinline}
some code here
\end{TEXTinline}
\end{document}

And now lualatex main.tex gives

(/usr/local/texlive/2022/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg)))
Runaway argument?
! File ended while scanning use of \FancyVerbGetLine.
<inserted text> 
\par 
<*> main.tex

I think this is related to Verbatim only. So I tried to define Verbatim environment calling in X400, but that also did not work

\documentclass[12pt,titlepage]{article}

\usepackage{fancybox,fancyvrb,xcolor}
\usepackage[listings,skins,breakable,xparse]{tcolorbox}

\DefineVerbatimEnvironment{X400}{Verbatim}{frame=single,framerule=0.8pt,framesep=2mm}

\newenvironment{TEXTinline}%
{%
 \begin{tcolorbox}[rounded corners,boxrule=.1pt,colframe=red!75!black,boxsep=2pt]%
 \begin{X400}
}%
{%
 \end{X400}
 \end{tcolorbox}%
}%
\fi 
\begin{document} 


\begin{TEXTinline}
some code here
\end{TEXTinline}

\end{document}

Same error.

I sort of remember such an issue using Verbatim inside new environment, because Verbatim wants to be in place only? but now do not and can't find a resolution to this.

Is it possible to define the above new environment and have Verbatim environment inside it?

TL 2023

1
  • 2
    in general you can not nest verbatim, as inside verbatim commands are disabled so your \end{TEXTinline} is just a string and does not end any environment. But tcolorbox provides facilities for defining boxed verbatim environments, check its manual Sep 1, 2023 at 15:34

1 Answer 1

1

You need to add \VerbatimEnvironment. Not really well documented…

\documentclass[12pt,titlepage]{article}
\usepackage{fancybox,fancyvrb,xcolor}
\usepackage[listings,skins,breakable,xparse]{tcolorbox}

\newenvironment{TEXTinline}{%
  \VerbatimEnvironment
  \begin{tcolorbox}[rounded corners,boxrule=.1pt,colframe=red!75!black,boxsep=2pt]%
  \begin{Verbatim}%
}{%
  \end{Verbatim}%
  \end{tcolorbox}%
}

\begin{document}

\begin{TEXTinline}
some code here
\end{TEXTinline}

\end{document}

enter image description here

2
  • Thanks. Would you happen to know of similar trick that will work for \begin{verbatim} and not just \begin{Verbatim} ? sometimes I prefer verbatim over Verbatim for tex4ht issue. But \VerbatimEnvironment does not work with verbatim only Verbatim. Thanks.
    – Nasser
    Sep 1, 2023 at 17:46
  • 1
    @Nasser You can do \RecustomVerbatimEnvironment{verbatim}{Verbatim}{}, so verbatim is the same as Verbatim.
    – egreg
    Sep 1, 2023 at 19:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .