In LATEX, writing the\_long\_underscore yields the_long_underscore, which looks too long when appearing in source code listings. (Here in KATEX it looks not that long.) One solution is using the underscore from a monospaced font instead.
Of course, Knuth’s plain TEX does not have that issue. The underscore
is properly sized. Why? Because TEX does not load a real glyph
for \_. It is defined as \leavevmode \kern .06em \vbox {\hrule width.3em}, i.e., a horizontal line!
We can recover that good old definition in LATEX:
\renewcommand{\textunderscore} {\leavevmode \kern .06em \vbox {\hrule width.3em}}
It seems that \_ is implemented using
\textunderscore, so we do not need to redefine the
former. It also seems that LATEX does include the good old definition,
but somehow overrides it.