21

I am wondering the diffference between \verb and \tt.

For example

\verb|difference| appears the same with \tt{difference}

2

1 Answer 1

29

The difference is that \verb is an inline verbatim environment so that everything inside it is taken literally, even what would otherwise be considered a command. This also happens to use a monospace font because it is usually used to insert code snippets (so that special characters don't pose any issue).

On the other hand, \tt (and you really should be using \texttt{...}) simply switches the font to monospace font, but LaTeX commands remain as usual.

To illustrate the difference, consider these two:

\verb|\emph{hello} world|

\texttt{\emph{hello} world}

which produces:

output


As a last remark, you shouldn't use \tt and other related commands such as \bf and \it because they are clumsy to use and don't play well together. This is demonstrated well here. To take their place, we have two sets of commands: \bfseries, \ttfamily; and \textbf{...}, \texttt{...}.

2
  • 1
    It would be probably useful for the OP to see the difference between \emph{\tt hello} and \emph{\texttt{hello}}. Only the second one produces emphasized typewriter style, the first only produces typewriter style without emphasis.
    – Bakuriu
    Apr 12, 2016 at 18:43
  • 2
    @guanglei: … and in any case, even in the old days it was {\tt hello} and not \tt{hello}. With the latter syntax the effects of \tt are not limited to the word hello.
    – GuM
    Apr 13, 2016 at 6:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .