Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

Output

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)

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

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

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

screenshot

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}
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.