5

Is there something fundamentally different about \verb compared to other commands or is it just a design choice?

  • 3
    What if you want a verbatim { :-) The use of pipes is not required by \verb, it's just the most common choice. – Joseph Wright Jul 27 '16 at 16:38
  • 1
    @user2229219: How often do you use | in a document? Oh, not very often, so let's use | for \verb then, because I really don't use it often... – Werner Jul 27 '16 at 16:45
  • 3
    The text between the pipes (or the character of your election) is not, strictly, an argument of \verb. This macro opens what we could call a "verbatim mode", and the first character sets how to close it. – Javier Bezos Jul 27 '16 at 17:16
  • 2
    One thing you should be aware of is that the same character used to mark the start must be used to end it. So if you had \verb{foo}, the } would not end your verb, you would have to have \verb{foo{, which would be very bad for code readability. I think you could do this if you wanted though – Au101 Jul 27 '16 at 17:21
  • 2
    almost everything about \verb is fundamentally different to other commands. – David Carlisle Jul 27 '16 at 19:31
9

It's a design choice, because \verb can't know in advance what characters you might want produced verbatim. So you get to choose the delimiter on the fly each time - for example

\documentclass{article}
\begin{document}
\verb|using a pipe in \verb to get a verbatim $|

You can even use a \$ to begin and end your verbatim string:

\verb$Here's a verbatim pipe in braces: {|}$

\end{document}

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.