I would like to set the \verb{} font so to correspond to the current family and size of my document. That is, the output must be indistinguishable by the rest of the text body whatever style is set as default.

  • 2
    What do you need \verb for, then?
    – egreg
    Commented Sep 19, 2013 at 9:06
  • Good question. I need to cheat on my text editor. See here.
    – Francesco
    Commented Sep 19, 2013 at 10:13

1 Answer 1


With the default font encoding OT1 you cannot switch the typewriter font to a normal text font, because of encoding issues (burden of compatiblity). The encoding issues are resolved in font encoding T1, for example. Then the font for \ttfamily can be changed to use the roman font instead, e.g.:

\usepackage[T1]{fontenc}% NOT OT1!
\usepackage{lmodern}% Latin Modern fonts,
  % a modern variant of Computer Modern fonts

  Hello \texttt{World}! \verb|\relax %$&#|


If you need to inherit the font settings from the context, then \verbatim@font can be redefined to do nothing. It is used for \verb and environment verbatim:


\usepackage[T1]{fontenc}% NOT OT1


  Hello \texttt{World}! \verb|\relax %$&#|

  {\sffamily Hello \texttt{World}! \verb|\relax %$&#|}

  {\itshape Hello \texttt{World}! \verb|\relax %$&#|}

  {\bfseries Hello \texttt{World}! \verb|\relax %$&#|}


You must log in to answer this question.

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