# How to display (inline) LaTeX commands properly?

When writing about LaTeX, I tend to use \verb, which could look like that:

\documentclass{article}
\usepackage{lipsum}

\begin{document}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \verb+\documentclass{article}+
\lipsum[2]
\end{document}


Thus I get the following result:

Is there another way to display LaTeX commands properly in continuous text or atleast some way to prevent \verb from going over the end of the line?

(For longer code I obviously would use something like listings)

-

The listings package provides lots of commands, including the \lstinline[<options>]!code!, and in particular, you can use

\lstinline[breaklines=true]!\documentclass{article}!


A complete MWE follows- you can explore global settings using \lstset in your preamble.

\documentclass{article}
\usepackage{lipsum}
\usepackage{listings}
\lstset{basicstyle=\ttfamily\normalsize}

\begin{document}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \lstinline[breaklines=true]!\documentclass{article}!
\lipsum[2]
\end{document}

-
Great, for I am using this somewhat regularly I put the option breaklines=true in the preamble to \lstset, which works like a charm. – xfoo Dec 29 '12 at 7:34
@ChristianR. glad it works :) – cmhughes Dec 29 '12 at 17:19