I am wondering the diffference between \verb
and \tt
.
For example
\verb|difference|
appears the same with \tt{difference}
fontstypewriterverbatim
I am wondering the diffference between \verb
and \tt
.
For example
\verb|difference|
appears the same with \tt{difference}
Best Answer
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:
which produces:
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
,\ttshape
; and\textbf{...}
,\texttt{...}
.