PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : code listing



roescu
11-10-2007, 02:55
I have line code for Origin (LabTalk script) and I want to create guidelines to make it easy for other users. For his I have tried to put in LaTeX something like this:

...
\usepackage{listings}
\lstset{morecomment=[l][\color{blue}]{//}} %%**** here I have declared that the anything following // is a coment for LabTalk
%%%% LabTalk script starts on the next line %%%%
\tiny
\begin{lstlisting}
//Height = A*sqrt(2/pi)/W;
%W=%H; // save name of results (active) wks
win -t D; // create new wks to store the values
win -r %H HEIGHTS; // rename the new created (active) window with the new name HEIGHTS
npeaks=6; // declare how many peaks you have fitted...... USER INPUT HERE
work -a npeaks;
%%%% LabTalk script ending %%%%%
\end{lstlisting}
.....

It is working like this but it seems confusing for the reader.
It would be great to have the comments separated from the actual code, both of them in their own "column". Does anybody have an idea how to do this?

Thank you and sorry for writing in english.

It

roescu
11-10-2007, 03:00
a little error in the code above


\tiny
\begin{lstlisting}
%%%% LabTalk script starts on the next line %%%%

instead of


%%%% LabTalk script starts on the next line %%%%
\tiny
\begin{lstlisting}

Tut mir leid

edico
11-10-2007, 11:49
I hope I'll get it right. So what about minipages side by side. Put your 'morecomment' into a separate minipage wheras the original code comments are put with TAB.
In a way like this ...
....
\begin{minipage}[t]{.4\linewidth}
\begin{lstlisting}
% W=%H;
win -t D;
win -r % H HEIGHTS;
npeaks=6;
% with the new name HEIGHTS|
work -a npeaks;
\end{lstlisting}
\end{minipage}
\qquad%
\begin{minipage}[t]{.3\linewidth}
\verb|//Height = A*sqrt(2/pi)/W;|
\verb|// save name of results (active) wks|
\verb|// create new wks to store the values|
\verb|// rename the new created (active) window|
\vskip\baselineskip
\verb|// declare how many peaks you have fitted...... USER INPUT HERE|
\end{minipage}
...

edico

edico
11-10-2007, 12:03
Well this is much more easier. Just copy the code and the comments capsulated with listings into a separate minipage and delete the comment and/or code in one of them. This should work for you.

\documentclass[a4paper,landscape]{book}
\usepackage[a4paper,landscape]{geometry}
\usepackage{xcolor}
\usepackage{dingbat,amsfonts,showframe}
\usepackage{listings}

\begin{document}

\lstset{%
language={[LaTeX]TeX},
commentstyle=\color{green!50!black!100},
morecomment=[l][\color{blue}]{//},
basicstyle=\ttfamily,
breakautoindent = true,
breakindent = 10em,
breaklines = true,
postbreak = \space,
prebreak = \raisebox{-.8ex}[0ex][0ex]{\ensuremath{\lrcorner}},
keepspaces = true,
}

\small%\tiny
\begin{minipage}[t]{.4\linewidth}
\begin{lstlisting}

% W=%H;

win -t D;
win -r % H HEIGHTS;

% with the new name HEIGHTS
npeaks=6;
work -a npeaks;
\end{lstlisting}
\end{minipage}
\qquad%
\begin{minipage}[t]{.5\linewidth}
\begin{lstlisting}
//Height = A*sqrt(2/pi)/W;

// save name of results (active) wks
// create new wks to store the values

// rename the new created (active) window

// declare how many peaks you have fitted...... USER INPUT HERE

\end{lstlisting}
\end{minipage}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "zest"
%%% End:


edico

roescu
11-10-2007, 12:50
I am impressed!
I have to work a little bit with it to get used and maybe I will have some more comments.
but for the moment it seems exaclty what I needed.

thank you

roescu
13-10-2007, 18:45
there is a problem of incompatibility between packages {listings} and {lmodern}. This will give errors in correctly displaying some characters when I type in the code I want to list.
Is it possible to overcome this draw-back?
Maybe a command to change the font family after \begin{lstlisting}?
I dont know how to do it as the \begin{lstlisting} is inside another *.tex file which I am loading from the master document with \input {coding.tex}.
(this coding.tex file contains also normal text besides code included in two minipages side by side as Edico suggested above)

edico
14-10-2007, 22:04
... and what happen's when you change the basicstyle e.g.

basicstyle=\fontfamily{pcr}\fontseries{m}\selectfo nt{} [1]

(or any other font, luximono should fit to lmodern - but caution! I dont't fell certain)


edico
[1] caution! undesirable space

roescu
16-10-2007, 00:53
this is it. It is working like this. I don't understand exactly how is working but it is.
Thank you again for so much help!

burny
16-10-2007, 08:17
roescu, can you post an example pdf-page? I'm very interested in how this looks like.

roescu
16-10-2007, 11:35
roescu, can you post an example pdf-page? I'm very interested in how this looks like.

Here it is. I hope it helps.

edico
17-10-2007, 10:09
I don't understand exactly how is working but it is.
I don't too ;-)
But let me try as non-professional, and tell you the story (of the birds and the bees) as I understand:
[1] I suppose that you're loading lmodern package.
[2] With (La)TeX you need serife, no serife, and typewriter fonts for display.
[3] lmodern does not bring along a typewriter font!
[4] listings needs typewriter font.
=> ergo: you couldn't display your listings

q.e.d. ;-)

edico

roescu
17-10-2007, 10:41
This sounds reasonable.
I didn't know exactly what fonts are loaded or needed by the packages (I guess I dont know too many things about LaTeX). Luckily there are forums and good people :)

Vielen Dank, Edico

roescu

rais
17-10-2007, 16:06
something doesn't seem to fit quite right:

there is a problem of incompatibility between packages {listings} and {lmodern}. This will give errors in correctly displaying some characters when I type in the code I want to list.

If these characters are shown correctly just by not loading lmodern, and the lmodern package supposedly doesn't bring it's own typewriter font along---why should the listing even show a difference?
Or did you try this with a different package?
And which characters are you talking about?

BTW:


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\begin{document}
{\ttfamily just put some text here}
\end{document}

shows a LMTypewriter font (cs-lmtt) in the document's properties.;)
Perhaps you're just missing a \usepackage[T1]{fontenc}?
Regards,

roescu
18-10-2007, 17:12
The characters not correctly displayed were underscore, %, minus, quoatation mark (maybe some other but these I remember at this moment)
The solution of Rais is working as well. Thank you.

the tested code was:

\documentclass[a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{listings}

\usepackage[english]{babel}
\usepackage{graphicx,xcolor}
\usepackage[inner=3.5cm, outer=4.5cm, top=3.5cm, bottom=3.5cm,a4paper]{geometry}
\usepackage{graphicx,xcolor}
\usepackage{ushort}
\usepackage{units}


\begin{document}
\ttfamily

\scriptsize
\begin{minipage}[t]{.4\linewidth}
\begin{lstlisting}
mfreset;
mffn Gauss;
mfrep 5;
nlsf.constr$="A_1>0;w_1=0.2";
nlsf.constraints=1;
mfseq %w;
//mfseq2 Data1;
\end{lstlisting}
\end{minipage}
\quad
\begin{minipage}[t]{.6\linewidth}
\begin{lstlisting}
// resets the Advanced Fitter
// select Gaussian fitting function
// total 6 peaks //* USER INPUT HERE
// imposed constraints //* USER INPUT HERE
// activate constraints //* USER INPUT HERE
// fit mode 1 - initialization worksheet %W
// fit mode 2 - initialization worksheet %W
// one can use "mfseq NAME" to load a worksheet NAME instead of %w
\end{lstlisting}
\end{minipage}
\normalsize
\end{document}