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
Please post a full example. Are you using the "fragile" option for the
relevant frame?
--
Joseph Wright
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
---
frmsrcurl: http://compgroups.net/comp.text.tex/Using-in-lstlisting-environment-breaks-formating
> 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>
> 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.