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.

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
add comment

2 Answers 2

up vote 5 down vote accepted
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\lstset{basicstyle=\ttfamily\small}
\begin{document}
foo
\lstinline{if (!(last_cond && (last_flags & (O_CREATE | O_EXCL))))}
bar
\end{document}
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
add comment

Use the verbdef package

\documentclass{article}
\usepackage{verbdef}
\begin{document}
\verbdef\demo{if (!(last_cond && (last_flags & (O_CREATE | O_EXCL))))}
\demo
\end{document}
share|improve this answer
1  
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
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.