2

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).

user2859
  • 217

2 Answers2

6
\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}
2

Use the verbdef package

\documentclass{article}
\usepackage{verbdef}
\begin{document}
\verbdef\demo{if (!(last_cond && (last_flags & (O_CREATE | O_EXCL))))}
\demo
\end{document}
yannisl
  • 117,160
  • 3
    It does seem strange to define a new macro for every new string that one wants to be output. – user2859 Jan 09 '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. – yannisl Jan 09 '11 at 21:43