21

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

For example

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

percusse
  • 157,807
guanglei
  • 453

1 Answers1

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{...}.

egreg
  • 1,121,712
JP-Ellis
  • 8,929
  • 2
  • 33
  • 49
  • 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 '16 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 '16 at 06:07