# Highlight text in verbatim environment [duplicate]

I want to highlight a certain element in this matrix from matlab output. How can I do this in the verbatim environment?

\begin{verbatim}

P =

1.0000    0.7000         0         0         0
0         0    0.5000         0         0
0    0.3000         0    0.6500         0
0         0    0.5000         0         0
0         0         0    0.3500    1.0000
\end{verbatim}


## marked as duplicate by Werner, barbara beeton, Svend Tveskæg, user13907, user2478 Sep 20 '15 at 20:38

The standard verbatim environment is too basic. You could use instead the listings package and its escapeinside feature to escape to LaTeX for the highlighting:

\documentclass[11pt]{article}
\usepackage{listings}
\usepackage{xcolor}

\lstset{
basicstyle=\ttfamily,
escapeinside=||
}

\begin{document}

\begin{lstlisting}
P =

|\textcolor{cyan}{1.0000}|    0.7000         0         0         0
0         0    0.5000         0         0
0    0.3000         0    |\colorbox{magenta!30}{0.6500}|         0
0         0    0.5000         0         0
0         0         0    0.3500     |\textcolor{orange}{1.0000}|
\end{lstlisting}

\end{document}