display programming source file
flag
Messages 1 - 10 of 15 - Collapse all
/groups/adfetch?adid=9egcPw4AAACnqUOqmbYbIrrBxreAu9r7
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
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. Listen and type the numbers you hear
 
1.  nurbz  
View profile  
 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?

Thanks in advance
Alexis


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
2.  wald  
View profile  
 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:

http://www.tex.ac.uk/cgi-bin/texfaq2html?keyword=&question=123

Greetz,
Wald

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

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
3.  Herbert Voss  
View profile  
 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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "so how do you color the source?" by ptk
4.  ptk  
View profile  
 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?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
5.  ptk  
View profile  
 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?

> Thanks in advance
> 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.

thanks in advance


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
6.  Jim Hefferon  
View profile  
 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
to PDF instead.

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}
\lstloadlanguages{Python,SQL,csh,HTML}

\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}
\href{http://www.google.com}{Google} found
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
ALASKA                          AK
AMERICAN SAMOA                  AS
ARIZONA                         AZ

 ..

WEST VIRGINIA                   WV
WISCONSIN                       WI
WYOMING                         WY

Military "State"                Abbreviation

Armed Forces Africa             AE
Armed Forces Americas           AA
(except Canada)
Armed Forces Canada             AE
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,
and adjusted the `except Canada' line.
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
('AK','Alaska','state');
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
Americas (except Canada)','military');
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}


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
7.  ptk  
View profile  
 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
about RTFM.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
8.  Robin Fairbairns  
View profile  
 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
>about RTFM.

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
to my answer about listing packages, or to a different package.

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
9.  ptk  
View profile  
 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
past two months - some even answered by your self. If indeed the 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.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
10.  Robin Fairbairns  
View profile  
 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
>past two months - some even answered by your self.

i am aware of answering one question about source code colouring
saying i knew of no way to do it, but that a summary of what i _did_
know was in the faq answer.

>If indeed the 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
have an answer.

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2013 Google