# Listings literate option breaks identifiers

I wanted to raise the _ char in code listings because the T1 font I am using places it too much below the baseline; this causes identifiers like bla_bla look horrible. I am using listings so I thought I could use the literate option to search/replace _ with a raised version. Unfortunately, the search/replace option conflicts with the lexer which will break the identifiers when finding _.

A MWE to illustrate the issue:

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage{libertine}

\usepackage{listings}

\lstset{
columns=[l]flexible,
basicstyle={\sffamily},
morekeywords={to},
}

\begin{document}

\begin{lstlisting}
\end{lstlisting}

\begin{lstlisting}[
literate={
{_}{{\raisebox{.3ex}{\_}}}1
}]
\end{lstlisting}

\end{document}


Is there a way to get this behaviour without disrupting the lexer?

• I don't know the answer to this, but I think it probably lies closer to listings' SelectCharTable and lst@DefSaveDef than to literate. – jub0bs Mar 7 '15 at 19:56
• @Jubobs thanks for looking into this. Answers that do not meddle with listings internals/options but with the fonts themselves are also acceptable. – Bordaigorl Mar 7 '15 at 20:01

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage{libertine}

\usepackage{listings}

\lstset{
columns=[l]flexible,
basicstyle={\sffamily},
morekeywords={to},
}

\begin{document}
\begin{lstlisting}