# Package listings doesn't work [closed]

I'm trying to understand how to use listings.

In the preamble I have:

\usepackage {listings}


Inside my document I wrote:

\begin{lstlisting}
for i:=maxint to 0 do
begin
{ nothing !}
end;
write(’Welcome !’);
\end{lstlisting}


It all doesn't work. I'm wondering why.

MWE :

\documentclass[a4paper,singleside,11pt]{report}
\usepackage{ia_urb_thesis}
\usepackage[italian]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\titolo{xxxxxx... \[5mm] }
\candidato{io}
\relatore{Chiar.mo Prof.~A}
\copertinatesi \dedica{Ai miei genitori}
\indice \indicefigure \indicetabelle \iniziatesto
\include{cap_1}
\include{cap_2}
\appendix
\include{app_a}
\include{biblio}
\ringraziamenti Vorrei ringraziare ...
\end{document}

-

## closed as unclear what you're asking by Jubobs, Jesse, Martin Schröder, Sean Allred, Marco DanielMar 2 '14 at 17:33

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

Welcome to TeX.sx! What do you mean precisely by "it doesn't work"? – egreg Dec 2 '12 at 21:16
First, change write(’Welcome !’); to write('Welcome !'); Second: your package ia_urb_thesis is unknown in s standard installation of a tex distribution. You should better use latin9 instead of latin1. If possible and your editor is able to do it use utf8 instead of latin1. \include is not useful in a MWE, because we do not have the included files so the MWE is not compiling ... – Kurt Dec 2 '12 at 21:35
@Kurt Just out of curiosity, why latin9 in place of latin1? – Brent.Longborough Dec 2 '12 at 21:38
@g9999 : This MWE is neither minimal (many non included external files) nor working (no \begin{document}). – T. Verron Dec 2 '12 at 21:38
@egreg Oh, yes. Of course it's a personal choice, but I myself wouldn't bother -- I'd just go straight to utf-8 – Brent.Longborough Dec 2 '12 at 21:43

I found an external link to ia_urb_thesis. It is a google code project.

It seems there are a lot of things wrong/missing in your example.

Firstly, there is no \begin{document} in your example.

Secondly,

\titolo{<>}
\candidato{<>}
\relatore{<>}
\copertinatesi
\dedica{<>}
\indice
\indicefigure
\indicetabelle
\iniziatesto


must go after \begin{document}.

Thirdly, the \[ in \titolo{xxxxxx... \[5mm] } puts the succeeding code into math environment. You can change it into \\[5mm] for vertical spacing but I doubt that it will do you any good. You should just write \titolo{xxxxxx...} as it is.

The character ’ throws errors around but if you replace it with ' it works fine even with latin1 input. I don't know what you use that encoding for. But generally, you can get by with utf8.

Here is the code. You can use Kurt's modification of the lstlistings environment or use your own fancier one.

Here is the code.

\documentclass[a4paper,singleside,11pt]{report}
\usepackage{ia_urb_thesis}
\usepackage[italian]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{listings}
\lstset{language=Pascal}
\begin{document}
\titolo{xxxxxx}
\candidato{io}
\relatore{Chiar.mo Prof.~A}
\copertinatesi \dedica{Ai miei genitori}
\indice \indicefigure \indicetabelle \iniziatesto
\begin{lstlisting}
for i:=maxint to 0 do
begin
{ nothing !}
end;
write(Welcome !');
\end{lstlisting}
\end{document}


Here is the output.

-

Try the following MWE (in this form it is compilable without errors):

%http://tex.stackexchange.com/questions/85260/package-listings-doesnt-work
\documentclass[a4paper,singleside,11pt]{report}
\usepackage[italian]{babel}
\usepackage[utf8]{inputenc} % utf8
\usepackage[T1]{fontenc}
\usepackage{xcolor}

\usepackage {listings}

%configurating listings:
\lstset{language=Pascal,             % Language in Listing
basicstyle=\normalfont\ttfamily,   % generall style for listing
stringstyle=\rmfamily,             % normal font for strings
showstringspaces=true,             % shows blanks in strings
breaklines=true,                   % allows breaking of lines
frameround=ffff,                   % see manual
frame=lines,                       % see manual
backgroundcolor=\color{yellow},    % just to show
}

\begin{document}
Inside my document I wrote:
\begin{lstlisting}
for i:=maxint to 0 do
begin
{ nothing !}
end;
write('Welcome !');
\end{lstlisting}
\end{document}


I corrected the line with the welcome as mentioned in my comment to get a runable MWE. I also deleted all not nececcary for a MWE to give you a start point. Perhaps your thesis package causes errors ...

Update: I added a part (see macro lstset) to configure listings. Have please a look on the comments I inserted in the MWE. With texdoc listings on the command line you can read the manual (very useful :-). You can use predefined languages (here Pascal), you can define the used fonts for the complete listings (here \ttfamily) and so on. To configure your listing please have a look into the manual.

-
I believe that g9999 is worried about the "normal" appearance of the listing. Perhaps you can add some example for customizing it, for instance to set a language or to change the font. – egreg Dec 2 '12 at 21:50
@egreg: I added lstset` with a short explaniation. – Kurt Dec 2 '12 at 22:37
Thanks a lot ... – g9999 Dec 2 '12 at 22:58
@g9999: You are welcome. BTW: Upvoting is the preferred way here to say "thank you" to users who helped you. Upvote helpful answers and accept the most helpful answer. – Kurt Dec 3 '12 at 2:18