# Inline python code in latex

I am trying to add some inline python code into my report with color in an box like following:

As you can see "matrix text is red coloured embedded in a box" I can add inline colour code using the following method:

CVXOPT extends the built-in Python objects with two matrix objects: a {\color{red}\texttt{matrix}} object for dense


Which produces the following output:

It is almost perfect except a box around the code. How I can have a box around the code?

• Hi, ya it is close to my requirement. Thank you. – Mohammad Saifullah Feb 7 '16 at 17:17

You can simply put it inside an \fbox{...}:

\documentclass[border=5pt]{standalone}
\usepackage{xcolor}

\newcommand{\pyobject}[1]{\fbox{\color{red}{\texttt{#1}}}}

\begin{document}

CVXOPT extends the built-in Python objects with two matrix objects: a \pyobject{matrix} object for dense

\end{document}


Or, if you want rounded corners, use \ovalbox{...} from the fancybox package:

\documentclass[border=5pt]{standalone}
\usepackage{xcolor,fancybox}

\newcommand{\pyobject}[1]{\ovalbox{\color{red}{\texttt{#1}}}}

\begin{document}

CVXOPT extends the built-in Python objects with two matrix objects: a \pyobject{matrix} object for dense

\end{document}