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

\lstinline{if (!(last_cond && (last_flags & (O_CREATE | O_EXCL))))}
  • backgroundcolor cannot be set for inline, right? – xport Jan 9 '11 at 22:08
  • @xport: right, no background colors and frames – user2478 Jan 9 '11 at 22:27

Use the verbdef package

\verbdef\demo{if (!(last_cond && (last_flags & (O_CREATE | O_EXCL))))}
  • 2
    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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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