Using "#" in lstlisting environment breaks formating

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

 0
1/12/2010 9:55:12 AM
comp.text.tex 37433 articles. 72 followers.

6 Replies
1495 Views

Similar Articles

[PageSpeed] 49
On Jan 12, 9:55=A0am, Loris Bennett <loris.benn...@fu-berlin.de> wrote:
> 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:
>
> =A0 =A0 =A0 =A0 =A0 \lstset{language=3Dcsh,showstringspaces=3Dfalse,basic=
style=3D\footnotesize}
> =A0 =A0 =A0 =A0 =A0 \begin{lstlisting}
> #!/bin/csh
> if ( $#argv < 2 ) then > =A0echo "usage:$0 name age"
> =A0exit 1
> endif
> =A0 =A0 =A0 =A0 =A0 \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=3Dsh".
>
> I couldn't find anything about having to escape hashes in the
> documentation.
>
> Any ideas?
>
> Thanks,
>
> Loris
> --
> Dr. Loris Bennett
> Computer Centre
> Freie Universit=E4t Berlin
> Berlin, Germany

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

 0
Joseph
1/12/2010 10:04:18 AM
Joseph Wright <joseph.wright@morningstar2.co.uk> writes:

> On Jan 12, 9:55 am, Loris Bennett <loris.benn...@fu-berlin.de> wrote:
>> 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
>
> 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}

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

 0
Loris
1/12/2010 10:58:32 AM
> 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

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

 0
Lars
1/12/2010 11:29:15 AM
maybe test
\begin{lstlisting}[escapechar=ø]
ø#ø!/bin/csh
\end{lstlisting}

 0
leethiumd
1/22/2010 9:13:57 AM
leethiumd <user@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 <oberdiek@uni-freiburg.de>

 1
Heiko
1/22/2010 9:50:21 AM
Heiko Oberdiek <oberdiek@uni-freiburg.de> writes:

> leethiumd <user@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.
`
 2
Philipp
1/22/2010 9:56:49 AM
Similar Artilces:

Using "#" in lstlisting environment breaks formating
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 c...

How to use 'verbatim' environment when construct a new environment
Hi, all I want to create a new environment called 'code' whose content is smaller than normal text, and is verbatim. Intuitively, I can do following: \begin{small} \begin{verbatim} code code code... \end{verbatim} \end{small} I want to make these two environment into one by writing: \newenvironment{code}% {\begin{small}\begin{verbatim} }% {\end{verbatim}\end{small}} But it seems LaTeX can not do such encapsulation. When use \begin{code} and \end{code}, LaTeX reports 'verbatim' environment encounters file end. Anyone knows how to constructs such '...

Re: Using formatted variable (format values) as class/group #2
On Tue, 24 Jan 2006 00:30:18 -0800, GuidoT <cymraeg_erict@HOTMAIL.COM> wrote: >Hi, > >Unfortunately the code as written doesn't work, it doesn't summarise >the data, ok it does, it just outputs the summay for each of the >records. Can you be precise; does it or doesn't it? I'm not sure what you mean when you say it doesn't summarize. Does the code not group by week? >Well, that's what I tried first, adding a "calculated" to the >group by. This gave what I thought was the correct, summarised >results. But Dubravko mentioned ef...

Re: Using formatted variable (format values) as class/group #4
Why not use PROC SUMMARY? It's tuned for performance. Try proc summary data=test nway; class datum; output out=result(drop=_type_ rename=(datum=datum_c _freq_=n) ); run; On Mon, 23 Jan 2006 23:07:43 -0800, Dubro <dubro@DOLIC.DE> wrote: >Dear Group, > >I have a date variable which is formatted to give the week values >(weekv5.). Now I want to count another variable by this one. Is there a >more efficient way than the one given in the following example? > >data test; > infile datalines; > input datum date9. user $; > for... Re: Use format file to format large number of variables #3 oh, yeah, been there, done that wrote a tool: http://www.sascommunity.org/wiki/Image:Writattr.sas Here is an example of the output: http://www.sascommunity.org/wiki/Image:Demo_c-attrib.sas Ron Fehd the module/routine/subroutine maven CDC Atlanta GA USA RJF2 at cdc dot gov > -----Original Message----- > From: owner-sas-l@listserv.uga.edu > [mailto:owner-sas-l@listserv.uga.edu] On Behalf Of Herbert Morley A > Sent: Monday, December 29, 2008 1:33 PM > To: 'SAS Listserv' > Subject: Use format file to format large number of variables > > I have two datasets th... Re: Use format file to format large number of variables #2 Thanks to everyone's suggestions. Turned out problem was when the dataset = was created, a few variables were referred to a format that was numeric, wh= en the defined format was character. I had to define a new numeric format f= or those few variables and use it for them. The rest did fine (I already ha= d defiined fmtsearch- but that turned out not to be the problem). Best wishes Morley Herbert ... Re: Using formatted variable (format values) as class/group #3 On Tue, 24 Jan 2006 02:51:28 -0800, GuidoT <cymraeg_erict@HOTMAIL.COM> wrote: >Hi s, > >Sorry, it was my confusion about what the WEEKV format does. WEEKV is >a SAS 9 format. It gives a 1 to 1 match for input date and output week >string (Week and day number). I'm running SAS 8.2 and I had >(incorrectly) assumed that WEEKV was a private format that resulted in >a week number - So 7 days go to one output string. With this >assumption, the SQL without the CALCULATED gives a summary by week for >each of the input records. WIth CALCULATED (or 1) it produc... Re: Which format to use? #4 I did forget to post the picture. I see that PUT with 2 decimal places fixed your program. proc format; picture z0d(round) other = '999999999' (mult=1e2) ; run; On 11/11/08, karma <dorjetarap@googlemail.com> wrote: > On 11 Nov, 12:49, iebup...@GMAIL.COM ("./ ADD NAME=Data _null_,") > wrote: > > I think the OP wanted two decimal places, but I don't think your > > method is doing that. Using Howard's suggestion this PICTURE seems to > > work using your example data. > > > > 1261 data _null_; > > 1... Re: Which format to use? #3 I think the OP wanted two decimal places, but I don't think your method is doing that. Using Howard's suggestion this PICTURE seems to work using your example data. 1261 data _null_; 1262 input x @@; 1263 y = put(input(x,commax12.),z9.); 1264 z = x; 1265 put 'NOTE: Results ' @; 1266 put (_all_)(/= 'NOTE- '); 1267 format z z0d.; 1268 cards; NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 1263:18 NOTE: Results x=123.44 y=000012344 z=000012344 NOTE: Results ... Re: Which format to use? #2 On Fri, 7 Nov 2008 21:00:45 -1000, Joanne Mor <jmor@HAWAII.EDU> wrote: >SAS-L gurus, > >I am converting a file containing cost data in the w.d format to a flat file to send to a vendor. Their required format has an implied decimal (e.g., 163.99 = 000016399). Does SAS have a format or do I need to create my own? > >TIA. I believe you will have to develop a picture format to do this. > On Fri, 7 Nov 2008 21:00:45 -1000, Joanne Mor <j...@HAWAII.EDU> wrote: > >SAS-L gurus, > > >I am converting a file containing cost data in the w.d format to a flat &... formatting in equation environment #2 Hello Can anybody tell me how to customize the equation environment? I would like to change the left, right, top and bottom margins for the equations, and also the line gap between equations. Thankyou Shreyas. shreyas7@hotmail.com (shreyas) writes: > Can anybody tell me how to customize the equation environment? > I would like to change the left, right, top and bottom margins for the > equations, and also the line gap between equations. The top and bottom margins are \abovedisplayskip, \abovedisplayshortskip, \belowdisplayskip, and \belowdisplayshortskip, where the "short&q... Problem using 'break' Hi, For some reason MALTLAB wont let me use 'break' to get out of a 'for' loop, below is the snippet of code which I keep getting the following error... "Expression or statement is incomplete or incorrect." - refering to the line with the 'break' statement for i=1:image_dim if (stack_coord(1,i)<image_dim) if stack(stack_coord(1,i),stack_coord(2,i),stack_coord(3,i))==255 pix_count(div_count)=pix_count(div_count)+1; else break end end end Shouldnt this code pop me out of the &... Re: using format in SQL #3 Baogong: Your program is working up to a point. I wonder about that. I would have thought that 'format$race.' would generate a syntax error. The difficulty that you are encountering comes about because the GROUP BY column variable really does have six states (els_race in (0,1,2,3,4,6)). SAS SQL forms six bins for the six groups and adds one to the appropriate bin total as it processes each row of data in recip_id_info. SAS SQL does not form groups of formatted values. You did not ask it to do that. I would be surprised to learn that the SAS SQL compiler is substituting formatted valu...

Re: using format in SQL #4
Hi, Sigurd: Thank you for the detail explianation, your code works very well. Also, thank all others for the response. baogong On 1/16/06, Sigurd Hermansen <HERMANS1@westat.com> wrote: > > Baogong: > Your program is working up to a point. I wonder about that. I would have > thought that 'format $race.' would generate a syntax error. > > The difficulty that you are encountering comes about because the GROUP > BY column variable really does have six states (els_race in > (0,1,2,3,4,6)). SAS SQL forms six bins for the six groups and adds one > to the ... Re: help using formats #4 On Thu, 31 Aug 2006 18:02:52 -0700, Meg <napu1975@HOTMAIL.COM> wrote: >okay here is exactly what I have. I have Clinic, which is numeric >three digit variable (ie 101=ER, 350=Geriatric care)... > >below is a formated freq of the clinics (shortened). I want to do >something like this >if >clinic in ('Geriatric Medicine','Prime/med', etc) then care='Primary >care'; Notice that you capitalized the first letter in "Medicine", whereas in the list below it is not capitalized. Consequently, you will not get the match you expect. Peop... Re: using format in SQL #2 Try the following and the output is at the end: data recip_id_info; input els_race$ @@ ; cards; 1 2 1 1 2 2 3 4 6 2 1 2 1 0 ; ; proc format; value $race '1'='White' '2'='Black' other='Others'; proc sql; select race, count(race) as RaceCount from (select put(els_race,$race.) as race, A.* from recip_id_info A) group by race; quit; ***** Output ***** The SAS System 18:10 Monday, January 16, 2006 1 race RaceCount ...

Re: help using formats #3
Meg , Let me get this striaght, you have a numeric variable which already has a format associated with it. Howeevr, you dont like the groups of theis format because it doesnt roll the variable values up to a high enough abstraction for you. So you want SAS to magically read your mind as to what formatted value goes to what abstracted group. NPot gonna happen, you have to tell SAS one way or the other what groups you want. Well simplest thing is create another format that uses the unformatted values of the variable and simply use that one instead. While a variable may very well have a on...

Re: Using Clipboard with my own format #2
What I don't understand is how the GetData give back the data in clipboard, so I thought only in declaring a variable and allocating memory so as the GetData method would call my GetDataHere in order to give back the data to the struct that I only allocated. If I had to pass each value of the float *clipboard it wouldn't work, because I would be doing something like this : for (int i = 0; i < size; i++) clipboard[i] = m_clipboard.m_samples[i]; But my m_clipboard would be empty (just declare a clipContainer data(clipSize, clp, true) in order to fill the...

Re: help using formats #2
Meg , Okay, lets back up and ask the all important question that should have been asked from the get go: What are you trying to do? Toby Dunn When everything is coming at you all at once, your in the wrong lane. A truly happy person is someone who can smile and enjoy the scenery on a detour. From: Meg <napu1975@HOTMAIL.COM> Reply-To: Meg <napu1975@HOTMAIL.COM> To: SAS-L@LISTSERV.UGA.EDU Subject: Re: help using formats Date: Thu, 31 Aug 2006 11:39:55 -0700 Thanks...maybe I should be more specific. I don't need to change it into a character variable, i just want t...

Re: define a format using a macro #3
On Thu, 17 Jul 2008 15:32:26 -0700, maverick2 <phekuchand@GMAIL.COM> wrote: >I have a huge dataset with a variable "date" ranging from 1990 to >present in the date20. format. It looks like you have datetimes, not dates. They are not interchangeable, though conversion back and forth is possible. >For any particular range of dates, i need to define a new variable >"period". >eg. >if '01JAN2007:0:0'DT<=date<='31JAN2007:0:0'DT then period='01:JAN07'; >else if '01FEB2007:0:0'DT<=date<='28FEB2007:0:0...

Re: formatting titles when using bodytitle #4
Deb, From what you said here, this could be what you are looking for: ods rtf file="c:\temp\junk.rtf"; proc report data=sashelp.class nowd; column name age sex weight height; define name / display; compute before _page_ / style=[backgroup=red]; line "This is the your tile"; endcomp; title; run; ods rtf close; Ya On Tue, 11 Apr 2006 15:50:10 -0500, Deborah Wentworth <debby@CCBR.UMN.EDU> wrote: >On Tue, 11 Apr 2006, Terjeson, Mark (IM&R) wrote: > >Mark and Ya - > >Thanks for your comments. I can't replicate your example, Ya - I don't &...

Re: formatting titles when using bodytitle #2
Hi Deb, When creating an RTF and needing special font handling in different locales such as titles or footnotes or even in cell values or other text strings around the page, the inline style escape character coupled with RTF syntax can provide some custom tweaking midstream in text strings. Here are some samples: %let quote=%str(%');*'; %let amp=%nrstr(&); * set all or part of a text string to bold ; data mydata; merge aaa (in=a) bbb (in=b); by blah; if blahblah then pass='^S={font_weight=bold}No^S={}'; else pass='Yes'; ...

Re: formats and using multiple libraries #2
Kristie, You may need: options FMTSEARCH (dat_02 dat_03 dat_04) ; Kind Regards, _________________________________ Venky Chakravarthy E-mail: swovcc_AT_hotmail_DOT_com -----Original Message----- From: Kristie Beth [mailto:kristie_35_89@YAHOO.COM] Sent: Tuesday, September 09, 2003 6:14 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: formats and using multiple libraries Whoops, I am sorry, I forgot to put my paths in quotes, they have quotes in the program. My program that I am using works fine except to access the format library that is in each data folder. Does anyone know why? Or how to fix...

Using GDG's in an CICS environment.
Respected gentlemen, Can any one of you please tell me whether is it possible to use GDG's (Generation Data Groups) in CICS ? If yes how ? Thanx in advance, Ace. -- Posted via http://dbforums.com On Wed, 27 Aug 2003 11:25:37 -0400 Ace11 <member25371@dbforums.com> wrote: :>Can any one of you please tell me whether is it possible to use GDG's :>(Generation Data Groups) in CICS ? If yes how ? Yes. What do you want to do with them? CICS system programmers do not take kindly to CICS programmers who use QSAM to access files. -- Binyamin Dissen <bdissen@disse...

Re: formatting titles when using bodytitle #5
On Tue, 11 Apr 2006, Ya Huang wrote: Ya, thanks again. I think maybe you're right. I've been using proc print, and I don't know proc report very well, but with your snippet of code I may be able to figure out how to do it in proc report. What I need is to create a line that spans column headers and is centered about them - that looks like what you're demonstrating for me. Thanks very much for the help! I'll give this a try. Deb > Date: Tue, 11 Apr 2006 17:01:24 -0400 > From: Ya Huang <ya.huang@amylin.com> > To: SAS-L@listserv.uga.edu, Deb Wentworth &l...