3

The following gives me strange raised dots instead of underscores inside the alltt environment:

\documentclass{article}
\usepackage{alltt}
\usepackage{underscore}
\begin{document}

\textsf{This_is_fine}

\begin{alltt}
\textsf{This_is_not}
\end{alltt}

\end{document}

Is there any way around this? If I use \textrm instead of \textsf the problem is the same. However, \texttt works.

1
  • \usepackage[T1]{fontenc}
    – egreg
    Jan 20 '14 at 8:28
4

The package underscore works by making _ an active character, but this setting is overridden in the alltt package, which instead sets _ to a printable character.

Solution 1

Reinstate the activeness of _ in alltt

\documentclass{article}
\usepackage{alltt}
\usepackage{underscore}
\usepackage{etoolbox}
\appto\alltt{\catcode`\_=\active}
\begin{document}
\textsf{This_is_fine}

\begin{alltt}
\textsf{This_is_not}
\end{alltt}

\end{document}

Solution 2

Load the fontenc package, so that the printable underscore prints something good.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{alltt}
\usepackage{underscore}
\begin{document}
\textsf{This_is_fine}

\begin{alltt}
\textsf{This_is_not}
\end{alltt}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.