views:

401

answers:

2

Hi,

Is there an easy way to have the complete code in a lstlisting environment underlined? My current solution looks like this, but I'm not really happy with it.

\begin{lstlisting}[mathescape]
   $\ul{if(gt(x1, 0)) then} $
   ...
\end{lstlisting}

Thanks for any tips.

A: 

According to page 5 in the user guide (found here):

\lstset{keywordstyle=\underbar} 
Banang
Thats only working for keywords. But I'm not using any special syntax, so I have no keywords. I want the complete code to be underlined.I tried \lstset{basicstyle=\underbar} , but that's also not working.
Masala
A: 

If you want to underline the entire line (and not only the keywords), the best solution I can come up with is to do something along the lines below:

\usepackage{listings}

\newcommand{\lstul}[1]{\underline{\mbox{\tt #1}}}

\begin{document}

\begin{lstlisting}[mathescape]
  $\lstul{if condition}$
      $\lstul{statement 1}$
  $\lstul{statement 2}$
  ...
\end{lstlisting}


\end{document}
aioobe
That solution is not much different to mine I posted in my question, except I named the command \ul and not \lstul .
Masala
Sure. I wasn't sure what you didn't like with it, so I assumed that it was the italicized math-font that disturbed you, which can be solved with the \mbox.
aioobe
It makes the code look confusing. And you can not include the code from an external file :/
Masala
good points. Another point: Doesn't underlined code look ugly? :) I would much rather read the standard listing-formatting. What language is it that you're type-setting? Is it pseudo code? Could you post the actual listing-content in your question perhaps?
aioobe
Yes, it doesn't look very good, but I have to format it in this style, because it is for a course at university.
Masala
Then I wouldn't bother getting the latex nice either... :-]
aioobe
It's not the question, if the latex code looks nice or not. It's not very comfortable to write a longer piece of code. Is there no way to achieve something similar with basicstyle?
Masala