The old Google Groups will be going away soon, but your browser is incompatible with the new version.
display programming source file
 There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic. There was an error processing your request. Please try again. Standard view   View as tree
 15 messages

From:
To:
Cc:
Followup To:
Subject:
 Validation: For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon.

More options Jan 2 2002, 7:37 am
Newsgroups: comp.text.tex
From: "nurbz" <nur...@ematic.com>
Date: Wed, 02 Jan 2002 13:43:17 +0000
Local: Wed, Jan 2 2002 8:43 am
Subject: display programming source file
Hi all,

I am using programming quite a lot in my studies, so I always have to add
some source code in my LaTeX report. But I am just using an awful 'verb'
environment to display them. Is there any package to display easily
source file, such as C/C++, matlab, java, and so on?
Furthermore, is there any package that can colorize automatically C/C++
source file?

Alexis

To post a message you must first join this group.
You do not have the permission required to post.
More options Jan 2 2002, 7:56 am
Newsgroups: comp.text.tex
From: "wald" <arnout.standa...@nospamagr.kuleuven.ac.be>
Date: Wed, 2 Jan 2002 13:55:40 +0100
Local: Wed, Jan 2 2002 7:55 am
Subject: Re: display programming source file
A look at the FAQ wouldn't hurt:

Greetz,
Wald

"nurbz" <nur...@ematic.com> wrote in message

news:pan.2002.01.02.13.43.17.441.1225@ematic.com...

To post a message you must first join this group.
You do not have the permission required to post.
More options Jan 2 2002, 8:40 am
Newsgroups: comp.text.tex
From: Herbert Voss <v...@perce.de>
Date: Wed, 02 Jan 2002 14:38:20 +0100
Local: Wed, Jan 2 2002 8:38 am
Subject: Re: display programming source file

nurbz wrote:
> Hi all,

> I am using programming quite a lot in my studies, so I always have to add
> some source code in my LaTeX report. But I am just using an awful 'verb'
> environment to display them. Is there any package to display easily
> source file, such as C/C++, matlab, java, and so on?
> Furthermore, is there any package that can colorize automatically C/C++
> source file?

have a look at
http://www.lyx.org/help/listings/listings.php3

Herbert

To post a message you must first join this group.
You do not have the permission required to post.
 Discussion subject changed to "so how do you color the source?" by ptk
More options Jan 2 2002, 10:38 am
Newsgroups: comp.text.tex
From: ptk <p...@dont.spam.com>
Date: Wed, 02 Jan 2002 15:38:06 GMT
Local: Wed, Jan 2 2002 10:38 am
Subject: so how do you color the source?

To post a message you must first join this group.
You do not have the permission required to post.
More options Jan 2 2002, 10:38 am
Newsgroups: comp.text.tex
From: ptk <p...@dont.spam.com>
Date: Wed, 02 Jan 2002 15:38:21 GMT
Local: Wed, Jan 2 2002 10:38 am
Subject: so how do you color the source?

nurbz wrote:
> Hi all,

> I am using programming quite a lot in my studies, so I always have to add
> some source code in my LaTeX report. But I am just using an awful 'verb'
> environment to display them. Is there any package to display easily
> source file, such as C/C++, matlab, java, and so on?
> Furthermore, is there any package that can colorize automatically C/C++
> source file?

> Alexis

I apologize for perhaps missing the obvious, but how do you get the listings package to colorize the source code? This same question has appeared numerous times with the same link to the FAQ. It would really be nice to see an example.

To post a message you must first join this group.
You do not have the permission required to post.
More options Jan 2 2002, 1:36 pm
Newsgroups: comp.text.tex
From: jheffe...@smcvt.edu (Jim Hefferon)
Date: 2 Jan 2002 10:36:06 -0800
Local: Wed, Jan 2 2002 1:36 pm
Subject: Re: so how do you color the source?
ptk <p...@dont.spam.com> wrote

> I apologize for perhaps missing the obvious, but how do you get the listings package to colorize the source code? This same question has appeared numerous times with the same link to the FAQ. It would really be nice to see an example.

Here are two .sty files, and sample input that work for me; I think
that
you need to have a recent listings' for this to go.

I have trouble viewing the colored text in GhostScript so I convert

HTH,
Jim

=====ham_notes.sty=======
%\RequirePackage{dvidrv}
\RequirePackage{color}
%\definecolor{mediumblue}{rgb}{0.00,0.00,0.804}
\definecolor{chocolate}{rgb}{0.82,0.41,0.18} % color 176
\definecolor{pythoncolor}{rgb}{0.82,0.41,0.18}

\definecolor{darkolivegreen}{rgb}{0.333,0.420,0.184} %color 116 (GI
color?)
\definecolor{sqlcolor}{rgb}{0.333,0.420,0.184} %color 116 (GI color?)

\definecolor{sienna}{rgb}{0.627,0.322,0.176} %color 168 (coffee
color?)
\definecolor{javacolor}{rgb}{0.627,0.322,0.176} %color 168

\definecolor{stringcolor}{rgb}{0.25,0.25,0.25}
\definecolor{textcolor}{rgb}{0.25,0.25,0.25}

%\definecolor{indianred3}{rgb}{0.804,0.333,0.333} %color 414
\definecolor{indianred3}{rgb}{0.933,0.388,0.388} %color 413
\definecolor{htmlcolor}{rgb}{0.933,0.388,0.388} %color 413

\definecolor{mediumseagreen}{rgb}{0.477,0.702,0.441} %color 122
\definecolor{shellcolor}{rgb}{0.477,0.702,0.441} %color 122

\definecolor{brown}{rgb}{0.647,0.165,0.165}   % color 178
\definecolor{slateblue4}{rgb}{0.278,0.235,0.545}   % color 279
\definecolor{perlcolor}{rgb}{0.278,0.235,0.545}
%\definecolor{shellcolor}{rgb}{0.0,0.25,0.0}
\definecolor{htmlcolor}{rgb}{0.99,0,0} % red
\definecolor{lightslategrey}{rgb}{0.467,0.533,0.600} %color 52
\definecolor{xmlcolor}{rgb}{0.99,0,0} % red
\definecolor{goldenrod}{rgb}{0.855,0.647,0.125} %color 159
%\definecolor{sqlcolor}{rgb}{0.071,0.416,0.173} % a dark green

\usepackage{listings}

\lstdefinestyle{sql}{language=SQL,
%labelstyle=\tiny,labelstep=5,labelsep=7pt,
keywordstyle=\color{sqlcolor},
ndkeywordstyle=\color{sqlcolor},
identifierstyle=\color{sqlcolor},
stringstyle=\color{sqlcolor}}
\lstdefinestyle{python}{language=Python,
%labelstyle=\tiny,labelstep=5,labelsep=7pt,
keywordstyle=\color{pythoncolor},
ndkeywordstyle=\color{pythoncolor},
identifierstyle=\color{pythoncolor},
stringstyle=\color{pythoncolor}}
\lstdefinestyle{text}{language=,
keywordstyle=\color{textcolor},
ndkeywordstyle=\color{textcolor},
identifierstyle=\color{textcolor},
stringstyle=\color{textcolor}}
\lstdefinestyle{shell}{language=csh,
keywordstyle=\color{shellcolor},
ndkeywordstyle=\color{shellcolor},
identifierstyle=\color{shellcolor},
stringstyle=\color{shellcolor}}
\lstdefinestyle{html}{language=HTML,
keywordstyle=\color{htmlcolor},
ndkeywordstyle=\color{textcolor},
identifierstyle=\color{textcolor},
stringstyle=\color{textcolor},
keywordsinside=<>}
\AtBeginDocument{%
\lstset{%
indent=15pt,
basicstyle=\ttfamily\small,
%keywordstyle=\color{blue},
%ndkeywordstyle=\color{blue},
%identifierstyle=\color{blue},
%stringstyle=\color{blue},
stringspaces=false}}
=====lstlang0.sty====
% lstlang0.sty
% language definitions for the listings package
\lst@definelanguage{text}%
{keywords={},ndkeywords={}}
====lst_test.tex===
\documentclass{book}
\usepackage{color}
\usepackage{ham_notes}
\usepackage{url}
\usepackage{hyperref}

\newcommand{\pg}{PostgreSQL}

\title{KE1AZ's Internet Linux Log}
\author{Jim Hefferon}

\begin{document}
\maketitle

\chapter{Making the Database}

\section{Making the State Database}
this file of state and possession abbreviations that
on the web site of the US Postal Service.
\begin{lstlisting}[style=text]{}
State/Possession                Abbreviation

ALABAMA                         AL
AMERICAN SAMOA                  AS
ARIZONA                         AZ

..

WEST VIRGINIA                   WV
WISCONSIN                       WI
WYOMING                         WY

Military "State"                Abbreviation

Armed Forces Africa             AE
Armed Forces Americas           AA
Armed Forces Europe             AE
Armed Forces Middle East        AE
Armed Forces Pacific            AP
\end{lstlisting}
I edited out the two title lines
(Military~\ldots' and State/Possession~\ldots') along with the blank
lines,
Also,
I don't know anything about the postal codes for the military cases,
but I see that three of them share a designation.
I combined those three.

The \url{create_states.sql} script file
\begin{lstlisting}[style=sql,firstlabel=1]{}
CREATE TABLE state_types (
type  text,
PRIMARY KEY(type)
);

INSERT INTO state_types (type) VALUES ('state');
INSERT INTO state_types (type) VALUES ('possession');
INSERT INTO state_types (type) VALUES ('military');

CREATE TABLE states (
abbrev       CHAR(2) NOT NULL,
name         text NOT NULL,
status       text,
PRIMARY KEY(abbrev),
FOREIGN KEY(status) REFERENCES state_types
);
\end{lstlisting}
run from the command line
\begin{lstlisting}[style=shell]{}
[jim@millstone pg]$psql jim -a -fcreate_states.sql \end{lstlisting} will make the two tables. The \verb!state_types! is how I limit \verb!states.status! to only those three values. Note that I had to create the \verb!state_types! first or else \pg\ objects to referencing them as foreign keys. Next I need to get the data into the database. Then this Python script \begin{lstlisting}[style=python]{} #!/usr/bin/python # read_states.py # Read the list of states and abbreviations # 20-Nov-2001 Jim Hefferon j...@joshua.smcvt.edu import string infile_name="abbr_state.txt" infile=open(infile_name,'r') outfile_name="populate_states.sql" outfile=open(outfile_name,'w') for x in ('state','possession','military'): outfile.write("INSERT INTO state_types (type) VALUES ('%s');\n" % (x,)) while 1: line=infile.readline()[:-1] if not line: break fields=string.split(line) outfile.write("INSERT INTO states (abbrev,name,status) VALUES ('%s','%s','%s');\n" % (fields[-1],string.capwords(string.join(fields[0:-1])),'state')) infile.close() outfile.close() \end{lstlisting} run from the command line \begin{lstlisting}{text} [jim@millstone pg]$ ./read_states.py
\end{lstlisting}
gave me a file of \verb!INSERT! statements.
I've decided to produce the SQL script file.
\begin{lstlisting}[style=sql]{}
INSERT INTO states (abbrev,name,status) VALUES
('AL','Alabama','state');
INSERT INTO states (abbrev,name,status) VALUES
INSERT INTO states (abbrev,name,status) VALUES ('AS','American
Samoa','possession');
...
INSERT INTO states (abbrev,name,status) VALUES
('WY','Wyoming','state');
INSERT INTO states (abbrev,name,status) VALUES ('AE','Armed Forces
Africa, Canada, Europe, And The Middle East','military');
INSERT INTO states (abbrev,name,status) VALUES ('AA','Armed Forces
INSERT INTO states (abbrev,name,status) VALUES ('AP','Armed Forces
Pacific','military');
\end{lstlisting}
Note that, as produced by the script, everything is a state', but I
edited it by hand to change some to possession' or military'.
(I called Washington DC a possession' even though it didn't seem
right,
since it isn't either of the other two.)
\end{document}

To post a message you must first join this group.
You do not have the permission required to post.
More options Jan 2 2002, 6:02 pm
Newsgroups: comp.text.tex
From: ptk <p...@dont.spam.com>
Date: Wed, 02 Jan 2002 23:02:30 GMT
Local: Wed, Jan 2 2002 6:02 pm
Subject: Re: so how do you color the source?

Thanks a bunch - I know this has help everyone much more than the usual
remarks about the FAQ, or even worse the pedantic and sarcastic remarks

To post a message you must first join this group.
You do not have the permission required to post.
More options Jan 2 2002, 6:47 pm
Newsgroups: comp.text.tex
From: r...@pallas.cl.cam.ac.uk (Robin Fairbairns)
Date: 2 Jan 2002 23:47:07 GMT
Local: Wed, Jan 2 2002 6:47 pm
Subject: Re: so how do you color the source?

ptk  <p...@dont.spam.com> wrote:
>Jim Hefferon wrote:
>>[worked-out solution, quoted in full]

>Thanks a bunch - I know this has help everyone much more than the usual
>remarks about the FAQ, or even worse the pedantic and sarcastic remarks

ah.  so the faq is unuseful?  or never solves problems?  which?

do you think i should stop wasting my time?

face it, idiot-who-can't-even-trim-posts, you get told to rtfm if the
question is so trivial that anyone who bothers to read anything should
know it.

you get pointed to someone's faq if it answers the question.

you get pointed to a package if that solves the problem.

you *only* get a worked solution from someone who's done the work (or
knows how) and who believes there's no existing packaged solution.

which (i believe) is the case here.  which is why i didn't point you

if you don't like the way people answer your questions, why bother
--
Robin Fairbairns, Cambridge -- rf10 at cam dot ac dot uk

To post a message you must first join this group.
You do not have the permission required to post.
More options Jan 2 2002, 7:00 pm
Newsgroups: comp.text.tex
From: ptk <p...@dont.spam.com>
Date: Thu, 03 Jan 2002 00:00:37 GMT
Local: Wed, Jan 2 2002 7:00 pm
Subject: Re: so how do you color the source?
No I didn't say your faq was useless & yes I, and I'm sure everyone else
that has asked the question, has looked at your FAQ & is indeed indebted
to you for your unending efforts. However, your FAQ only gave cursory
attention to the issue of source code coloring, as I'm sure you're more
than aware. I have seen numerous posts on this same subject in just the
is so trivial, I and the rest of the lesser individuals are a little
perplexed as to why you didn't answer the question about HOW TO COLORIZE
program source, NOT SIMPLY POINT TO THE LISTING PACKAGE - such is the
confusion of the least.

To post a message you must first join this group.
You do not have the permission required to post.
More options Jan 3 2002, 5:19 am
Newsgroups: comp.text.tex
From: r...@pallas.cl.cam.ac.uk (Robin Fairbairns)
Date: 3 Jan 2002 10:19:15 GMT
Local: Thurs, Jan 3 2002 5:19 am
Subject: Re: so how do you color the source?

ptk  <p...@dont.spam.com> wrote:
>No I didn't say your faq was useless

you merely said answers that suggested looking at the faq were.

>& yes I, and I'm sure everyone else
>that has asked the question, has looked at your FAQ & is indeed indebted
>to you for your unending efforts. However, your FAQ only gave cursory
>attention to the issue of source code coloring, as I'm sure you're more
>than aware. I have seen numerous posts on this same subject in just the

saying i knew of no way to do it, but that a summary of what i _did_
know was in the faq answer.

>is so trivial, I and the rest of the lesser individuals are a little
>perplexed as to why you didn't answer the question about HOW TO COLORIZE
>   program source, NOT SIMPLY POINT TO THE LISTING PACKAGE - such is the
>confusion of the least.

it plainly isn't trivial.  there are admittedly rather few people who
bother to answer questions here, but the number is not entirely
insignificant.  only one of them (possibly after experimentation
following an earlier post) had a working solution: all the others
merely either mis-read your post, or (in my case) realised they didn't

i suppose you quoted the previous post in full because you thought it
was trivial?

plonk.
--
Robin Fairbairns, Cambridge -- rf10 at cam dot ac dot uk

To post a message you must first join this group.
You do not have the permission required to post.
More options Jan 3 2002, 8:30 am
Newsgroups: comp.text.tex
From: ptk <p...@dont.spam.com>
Date: Thu, 03 Jan 2002 13:28:43 GMT
Local: Thurs, Jan 3 2002 8:28 am
Subject: Re: so how do you color the source?

To post a message you must first join this group.
You do not have the permission required to post.
More options Jan 3 2002, 9:19 am
Newsgroups: comp.text.tex
From: David Kastrup <David.Kast...@t-online.de>
Date: 03 Jan 2002 15:17:33 +0100
Local: Thurs, Jan 3 2002 9:17 am
Subject: Re: so how do you color the source?

ptk <p...@dont.spam.com> writes:

Your sarcasm would probably be better appreciated if people saw as
much helpfulness from you on TeXnical matters as from Robin.  I cannot
as even only Robin's unthanked for attempts of helping you in this

--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
Email: David.Kast...@t-online.de

To post a message you must first join this group.
You do not have the permission required to post.
More options Jan 3 2002, 6:33 pm
Newsgroups: comp.text.tex
From: Peter Flynn <pe...@silmaril.ie>
Date: Thu, 03 Jan 2002 23:34:15 +0000
Local: Thurs, Jan 3 2002 6:34 pm
Subject: Re: so how do you color the source?

ptk wrote:
> No I didn't say your faq was useless & yes I, and I'm sure everyone else
> that has asked the question, has looked at your FAQ & is indeed indebted
> to you for your unending efforts. However, your FAQ only gave cursory
> attention to the issue of source code coloring, as I'm sure you're more

Hardly surprising: it deals with FREQUENTLY-asked questions only.

> than aware. I have seen numerous posts on this same subject in just the

"Numerous" within two months is probably not frequently enough, I
suspect (compared with the frequency of other questions).

> is so trivial, I and the rest of the lesser individuals are a little
> perplexed as to why you didn't answer the question about HOW TO COLORIZE
>   program source, NOT SIMPLY POINT TO THE LISTING PACKAGE - such is the
> confusion of the least.

If you would stop for a moment to think about what it is you have asked
you'll realise that source code colorisation is a highly non-trivial
task. In effect it either means implementing an entire C/C++ parser in
LaTeX, or -- for a lower syntactical level -- using regexps like Emacs
does. Neither of these comes even remotely within the remit of LaTeX as
a typesetting package, and although it is probably possible to do the
task (as Jim Hefferon has already posted) I don't think it is high on
anyone's list. Indeed, if you go and read what Knuth says about using
TeX to format his own Pascal code (different language, and in bold and
italic, not colour, but the principles are the same), you might get some
understanding of the difficulty of the task.

If you crack it, especially if you crack it in a generic manner which
can be applied to any programming language, please let us know.

///Peter

To post a message you must first join this group.
You do not have the permission required to post.
More options Jan 4 2002, 2:48 am
Newsgroups: comp.text.tex
From: r...@pallas.cl.cam.ac.uk (Robin Fairbairns)
Date: 4 Jan 2002 07:48:52 GMT
Local: Fri, Jan 4 2002 2:48 am
Subject: Re: so how do you color the source?
Peter Flynn  <pe...@silmaril.ie> wrote:

>ptk wrote:

>> No I didn't say your faq was useless & yes I, and I'm sure everyone else
>> that has asked the question, has looked at your FAQ & is indeed indebted
>> to you for your unending efforts. However, your FAQ only gave cursory
>> attention to the issue of source code coloring, as I'm sure you're more

>Hardly surprising: it deals with FREQUENTLY-asked questions only.

the other requirement is that i know an answer.

being (as i am) a sysadmin, i don't have much call for typesetting
code nowadays (and none of my users has ever asked for help in the
area).  i only do worked examples for c.t.t on a whim, and no such
object has ever troubled me in respect of source code colouring...
--
Robin Fairbairns, Cambridge -- rf10 at cam dot ac dot uk

To post a message you must first join this group.
You do not have the permission required to post.
More options Jan 4 2002, 9:48 am
Newsgroups: comp.text.tex
From: jheffe...@smcvt.edu (Jim Hefferon)
Date: 4 Jan 2002 06:48:09 -0800
Local: Fri, Jan 4 2002 9:48 am
Subject: Re: so how do you color the source?
Peter Flynn <pe...@silmaril.ie> wrote
> ... and although it is probably possible to do the
> task (as Jim Hefferon has already posted) I don't think it is high on
> anyone's list.

Please, Carsten Heinz did the work (based on the verbatim package, of course,
so there is scads of fine work there, too).  He's really done a wonderful job,
within the limits Peter describes.  I just doped out the manual.

Jim