Anzeige:
Ergebnis 1 bis 14 von 14

Thema: code listing

  1. #1
    Registrierter Benutzer
    Registriert seit
    28.09.2007
    Beiträge
    14

    code listing

    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:
    Code:
    ...
    \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

  2. #2
    Registrierter Benutzer
    Registriert seit
    28.09.2007
    Beiträge
    14
    a little error in the code above
    Code:
    \tiny
    \begin{lstlisting}
    %%%% LabTalk script starts on the next line %%%%
    instead of
    Code:
    %%%% LabTalk script starts on the next line %%%%
    \tiny
    \begin{lstlisting}
    Tut mir leid

  3. #3
    Registrierter Benutzer
    Registriert seit
    09.07.2004
    Beiträge
    2.365
    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

  4. #4
    Registrierter Benutzer
    Registriert seit
    09.07.2004
    Beiträge
    2.365
    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

  5. #5
    Registrierter Benutzer
    Registriert seit
    28.09.2007
    Beiträge
    14
    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

  6. #6
    Registrierter Benutzer
    Registriert seit
    28.09.2007
    Beiträge
    14
    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)

  7. #7
    Registrierter Benutzer
    Registriert seit
    09.07.2004
    Beiträge
    2.365
    ... 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
    Geändert von edico (14-10-2007 um 21:18 Uhr)

  8. #8
    Registrierter Benutzer
    Registriert seit
    28.09.2007
    Beiträge
    14
    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!

  9. #9
    Registrierter Benutzer
    Registriert seit
    15.09.2007
    Beiträge
    30
    roescu, can you post an example pdf-page? I'm very interested in how this looks like.

  10. #10
    Registrierter Benutzer
    Registriert seit
    28.09.2007
    Beiträge
    14
    Zitat Zitat von burny Beitrag anzeigen
    roescu, can you post an example pdf-page? I'm very interested in how this looks like.
    Here it is. I hope it helps.

  11. #11
    Registrierter Benutzer
    Registriert seit
    09.07.2004
    Beiträge
    2.365
    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

  12. #12
    Registrierter Benutzer
    Registriert seit
    28.09.2007
    Beiträge
    14
    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

  13. #13
    Registrierter Benutzer Avatar von rais
    Registriert seit
    18.07.2005
    Beiträge
    5.862
    something doesn't seem to fit quite right:
    Zitat Zitat von roescu Beitrag anzeigen
    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:
    Code:
    \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,
    Rainer
    There's nothing a good whack with a hammer won't fix!

  14. #14
    Registrierter Benutzer
    Registriert seit
    28.09.2007
    Beiträge
    14
    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:
    Code:
    \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}

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •