Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using "#" in lstlisting environment breaks formating

880 views
Skip to first unread message

Loris Bennett

unread,
Jan 12, 2010, 4:55:12 AM1/12/10
to
Hi,

Im am creating a presnetation with the beamer package and want to
disply a shell script via the listings package. However with this code:

\lstset{language=csh,showstringspaces=false,basicstyle=\footnotesize}
\begin{lstlisting}
#!/bin/csh
if ( $#argv < 2 ) then
echo "usage: $0 name age"
exit 1
endif
\end{lstlisting}

the formating following the hash in the second line of the code seems
to be broken. The rest of the line is slanted, including the closing
paren and "then". If I remove the hash everything is formatted
correctly. A similar problem occurs with a sh script for "language=sh".

I couldn't find anything about having to escape hashes in the
documentation.

Any ideas?

Thanks,

Loris
--
Dr. Loris Bennett
Computer Centre
Freie Universität Berlin
Berlin, Germany

Joseph Wright

unread,
Jan 12, 2010, 5:04:18 AM1/12/10
to

Please post a full example. Are you using the "fragile" option for the
relevant frame?
--
Joseph Wright

Loris Bennett

unread,
Jan 12, 2010, 5:58:32 AM1/12/10
to
Joseph Wright <joseph...@morningstar2.co.uk> writes:

Sorry. Here is a full example:

\documentclass[t,smaller,compress]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\usepackage{listings}


\begin{document}

\begin{frame}[fragile]{A Simple Script}

\lstset{language=csh,showstringspaces=false,basicstyle=\footnotesize}
\begin{lstlisting}
#!/bin/csh
if ( $#argv < 2 ) then
echo "usage: $0 name age"
exit 1
endif
\end{lstlisting}

\end{frame}

\end{document}

Lars Madsen

unread,
Jan 12, 2010, 6:29:15 AM1/12/10
to

> Sorry. Here is a full example:
>
> \documentclass[t,smaller,compress]{beamer}
> \usepackage[utf8]{inputenc}
> \usepackage[ngerman]{babel}
>
> \usepackage{listings}
>
>
> \begin{document}
>
> \begin{frame}[fragile]{A Simple Script}
>
> \lstset{language=csh,showstringspaces=false,basicstyle=\footnotesize}
> \begin{lstlisting}
> #!/bin/csh
> if ( $#argv < 2 ) then
> echo "usage: $0 name age"
> exit 1
> endif
> \end{lstlisting}
>
> \end{frame}
>
> \end{document}
>
>

# is registered as a comment char for csh language (see lstlang1.sty)

you could cheat and change the font for comments

commentstyle=\normalfont\footnotesize

or disable the # as a comment char (I don't know how to do that)


--

/daleif (remove RTFSIGNATURE from email address)

LaTeX FAQ: http://www.tex.ac.uk/faq
LaTeX book: http://www.imf.au.dk/system/latex/bog/ (in Danish)
Remember to post minimal examples, see URL below
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=minxampl
http://www.minimalbeispiel.de/mini-en.html

leethiumd

unread,
Jan 22, 2010, 4:13:58 AM1/22/10
to
maybe test
\begin{lstlisting}[escapechar=ø]
ø#ø!/bin/csh
\end{lstlisting}


---
frmsrcurl: http://compgroups.net/comp.text.tex/Using-in-lstlisting-environment-breaks-formating

Heiko Oberdiek

unread,
Jan 22, 2010, 4:50:21 AM1/22/10
to
leethiumd <us...@compgroups.net/> wrote:

> maybe test
> \begin{lstlisting}[escapechar=ø]
> ø#ø!/bin/csh
> \end{lstlisting}

My newsreader and I couldn't find any encoding declaration in your
posting. Probably you are using a Unicode character (>7bit) as
escapechar. However listings doesn't support Unicode.

`#' works with both the default language and language `csh' directly.
If you are escaping, then you are inside TeX, there \# prints a `#'.

\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[escapechar=\%]
#!/bin/csh
%\#%!/bin/csh
\end{lstlisting}
\begin{lstlisting}[language=csh]
#!/bin/csh
\end{lstlisting}
\end{document}

Yours sincerely
Heiko <ober...@uni-freiburg.de>

Philipp Stephani

unread,
Jan 22, 2010, 4:56:49 AM1/22/10
to
Heiko Oberdiek <ober...@uni-freiburg.de> writes:

> leethiumd <us...@compgroups.net/> wrote:
>
>> maybe test

>> \begin{lstlisting}[escapechar=ø]
>> ø#ø!/bin/csh


>> \end{lstlisting}
>
> My newsreader and I couldn't find any encoding declaration in your
> posting. Probably you are using a Unicode character (>7bit) as
> escapechar. However listings doesn't support Unicode.

It is the character "ø" which indeed works fine:

\documentclass{article}

\usepackage[latin1]{inputenc}
\usepackage{listings}

\begin{document}

\begin{lstlisting}[escapechar=ø, language=csh]
ø\#ø!/bin/csh
#abc
\end{lstlisting}

\end{document}

--
Change “LookInSig” to “tcalveu” to answer by mail.

0 new messages