# issue with Verbatim

I have a \n in my code which is not compiling correctly in verbatim environment.

\documentclass[]{article}
\usepackage{fancyvrb}
\usepackage{color}

\begin{document}

\begin{Verbatim}[commandchars = \\\{\}]
"A very very \n long title"     \textcolor{red}{A very very long title}
\end{Verbatim}

\end{document}


I am trying to get ''A very very \n long title''. And the sentence after it in red color

How to fix this.

## 2 Answers

The question is a bit unclear but I think you want

\documentclass[]{article}
\usepackage{fancyvrb}
\usepackage{color}

\begin{document}

\begin{Verbatim}[commandchars = !\{\}]
"A very very \n long title"     !textcolor{red}{A very very long title}
\end{Verbatim}

\end{document}

• Yes, this is exactly what I want. – An student Jan 4 '18 at 15:43

When using commandchars in fancyvrb, the resulting characters are executed/processed as (La)TeX characters rather than being set verbatim. You've set \, { and } to be treated as such. Therefore, any control sequence (starting with a \) will have to be defined.

In your case, \textcolor exists (from color), but \n does not. You can define \n to set \string\n (output similar to \n):

\documentclass{article}

\usepackage{fancyvrb,xcolor}

\newcommand{\n}{\string\n}

\begin{document}

\begin{Verbatim}[commandchars = \\\{\}]
"A very very \n long title"     \textcolor{red}{A very very long title}
\end{Verbatim}

\end{document}