TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Also I read: When should one use \verb!! and when \texttt{}

My issue at hand is that I would like to write a little more than just "small pieces" (wording in linked question) of program code, but without having to escape all the special characters. On the other hand, \verb does not have {}-style delimiters, besides being said to have issues with moving arguments.

Is there something I can do such that (sample text follows)

"As a user, do \texttt{if (!(last\_cond \&\& (last\_flags \& (O\_CREATE | O\_EXCL))))}, but as root, do \texttt{if (!(last\_cond \&\& (last\_flags \& (O\_RDONLY))))} until..."

can be written as

"As a user, do \texttt{if (!(last_cond && (last_flags & (O_CREATE | O_EXCL))))}, but as root, do \texttt{if (!(last_cond && (last_flags & (O_RDONLY))))} until..."

edit: Defining a new command as in \verbdef and having to write "As a user, do \verbdef\demo1{\texttt{if (!(last_cond && (last_flags & (O_CREATE | O_EXCL))))}}\demo1, but as root, do \verbdef\demo2{\texttt{if (!(last_cond && (last_flags & (O_RDONLY))))}}\demo2 until..." does read strangely (in the tex source file).

share|improve this question
up vote 6 down vote accepted
\lstinline{if (!(last_cond && (last_flags & (O_CREATE | O_EXCL))))}
share|improve this answer
lstinline it is. Thanks! – user2859 Jan 9 '11 at 21:52
backgroundcolor cannot be set for inline, right? – xport Jan 9 '11 at 22:08
@xport: right, no background colors and frames – Herbert Jan 9 '11 at 22:27

Use the verbdef package

\verbdef\demo{if (!(last_cond && (last_flags & (O_CREATE | O_EXCL))))}
share|improve this answer
It does seem strange to define a new macro for every new string that one wants to be output. – user2859 Jan 9 '11 at 21:39
@user2859 Use the listings package for large blocks of code! What is it exactly you are after? Your question is not very clear. – Yiannis Lazarides Jan 9 '11 at 21:43

Your Answer


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.