I would like to get the same result I get with \underline in a lstlisting environment.
I was almost sure I got it in this way:
\documentclass{article}
\usepackage{listings}
\usepackage{upquote}
\lstdefinestyle{myStyle}{
language=SQL,
basicstyle=\small\ttfamily,
moredelim=[is][\underbar]{_}{_},
keepspaces=true
}
\begin{document}
\begin{lstlisting}[style=myStyle]
SELECT * FROM usr WHERE _id = 7_
\end{lstlisting}
\end{document}
but when I use the _ delimiter between '' it doesn't work:
\documentclass{article}
\usepackage{listings}
\usepackage{upquote}
\lstdefinestyle{myStyle}{
language=SQL,
basicstyle=\small\ttfamily,
moredelim=[is][\underbar]{_}{_},
keepspaces=true
}
\begin{document}
\begin{lstlisting}[style=myStyle]
SELECT * FROM usr WHERE id ='_7_'
\end{lstlisting}
\end{document}
How can I solve this problem?


7should be underlined? – Oct 06 '15 at 20:14''. For instance, my code doesn't work withvar = '_something_'but it works withvar = _'something'_. However, your answer solves this problem. Thanks :) – Oct 06 '15 at 20:30