helpListings package for LaTeX - Support: sr #303, listings.sty problems and...

 
 
Show feedback again

You are not allowed to post comments on this tracker with your current authentification level.

sr #303: listings.sty problems and (pseudo?)solutions

Submitted by:  Brooks Moses <brooks>
Submitted on:  Wed Apr 13 05:02:56 2011  
 
Category: NonePriority: 5 - Normal
Severity: 5 - NormalStatus: None
Privacy: PublicAssigned to: None
Open/Closed: OpenOperating System: None

Wed Apr 13 05:02:56 2011, original submission:

Ulrich Breymann wrote, on Sun, 13 Jul 2008 11:27:28 +0200:


Dear Brooks Moses,

years ago I needed al package like listings.sty, but had no
knowledge of it. Therefore I wrote a similiar thing. Today I
prefer listings.sty. My publisher wants now to have Crystal as font for
listigs. As I am a German author, I also use umlaute äöüÄÖÜß.
I encountered several little problems:

1. The asterisk is not in Crystal
2. the C decrement operator -- will appear as an em-dash
3. The C comment /* */ does not have the same space between chars
and does not process latex-commands
4. Umlaute result in thin white lines directly above the Umlaute
(see lstlist1.pdf)

I could correct 1. and 2. by changing listings.sty
\lst@ProcessOther {"2A}{\lst@ttfamily**}
\lst@ProcessOther {"2D}{\lst@ttfamily{-{}}{-}}
(see lstlist2.pdf)
but I consider this not a good method in general.

I add the source as lstlist.tex

My own package solves the problems 1 to 4! But it is not able
- to compute the pagebreak
- to change the character distance
- and a lot of things more,
that is why listings.sty is much better for most cases. But perhaps
it is interesting for you and the listings community to layout properly
also /* */ comments and to avoid white lines with Umlaute, see
lstlistprog.pdf

I added also the source as lstlistprog.tex and also
the stylefile ct.sty.

Because of my limited Latex-programming understanding,
the ct.sty code is not professionally written, in contrast
to listings.sty, which I admit not to understand fully.
Also I have to do adjustments in ct.sty for each font combination.
Please ignore this. But possibly it might contain some ideas
to improve listings.sty w.r.t. point 3 above, as shown in
lstlistprog.pdf.

If a fully layout is not possible (listings.sty relies on \n),
perhaps the line structure in /* */ has to maintained.

Kind regards

Ulrich


\documentclass[10pt]{book}
\usepackage{color}

\usepackage{listings}

\lstset{language=C++,showstringspaces=false,extendedchars=true,basicstyle=\usefont{T1}{fcr}{m}{n}\fontsize{8pt}{10.5pt}\selectfont,backgroundcolor=\color[gray]{0.95},commentstyle=\usefont{T1}{fas}{m}{n}\fontsize{9pt}{9pt}\selectfont,stringstyle=\usefont{T1}{fas}{m}{it}\fontsize{9pt}{10.5pt}\selectfont,basewidth={0.55em,0.45em},texcl=true}

\begin{document}

\begin{lstlisting}
/* C-Comment with \emph{Latex-Command}, which does not work with lstlisting.
The distance between characters is not the same as in the C++ line comment.
Umlaute: ÄÖÜ
*/
// C++-Comment with \emph{Latex-Command} which \emph{does} work here.
int* ptr; // look at asterisk: \tt{*} or \textasteriskcentered ?
int i = 70;
while(i > 64) { // print some ASCII-chars
cout << "char = " << (char) i << endl;
--i; // en-dash or not?
}\end{lstlisting}

\end{document}

Attachment Converted: "d:\programs\eudora\attach\lstlistprog.pdf"
\documentclass[10pt]{book}
\usepackage{ct}
\parindent0em

\begin{document}

\subsubsection*{prog Test}
normal text. normal text. normal text. normal text. normal text. normal text. normal text. normal text. normal text. normal text. normal text. normal text. normal text. normal text. \medskip

\beginprog
/*C-Comment with \emph{Latex-Command}, which does not work with lstlisting.
The distance between characters is not the same as in the C++ line comment.
Umlaute: ÄÖÜ. Layout is LaTex. Here comes a line-break:\\
A formula: $\Sigma_0^N x_i$
*/
// C++-Comment with \emph{Latex-Command} which \emph{does} work here.
int* ptr; // look at asterisk: \tt{*} or \textasteriskcentered ?
int i = 70;
cout << "String with Umlaut ÄÖÜ" << endl;
while(i > 64) { // print some ASCII-chars
cout << "char = " << (char) i << endl; \hfill // hfill works here
--i; // en-dash or not?
}\endprog\medskip

%Here comes the verbatim listing

\end{document}

\def\0{{\tt \char92\relax 0}}
\def\n{{\tt \char92\relax n}}
\def\t{{\tt \char92\relax t}}
\newif\ifBackslash
\Backslashfalse
\def\bs{\tt{\char92\relax}\Backslashtrue}
\usepackage{color}%,longtable}
\usepackage{colortbl}

\newlength{\dieBreite}
\setlength{\dieBreite}{\textwidth}
%\addtolength{\dieBreite}{-2em}
\newlength{\CStarCommentwidth}%
\newdimen\indentCorrection
\newcommand{\ttfont}{\usefont{T1}{fcr}{m}{n}\fontsize{8.5pt}{9pt}\selectfont}%
\newcommand{\kfont}{\usefont{T1}{fas}{m}{n}\fontsize{9pt}{9pt}\selectfont}%
\newcommand{\stringfont}{\usefont{T1}{fas}{m}{it}\fontsize{9pt}{10.5pt}\selectfont}
\newcounter{blankscounter}% for comment indent
\newcounter{parZahl}% to avoid 2 pars in case of 2 CR
\def\myspace{\space\stepcounter{blankscounter}\setcounter{parZahl}{0}}
\def\mypar{\setcounter{blankscounter}{0}\stepcounter{parZahl}%
\ifodd theparZahl\par\else\setcounter{parZahl}{0}\fi}%
\def\myobeyspaces{\catcode`\ =\active}
{\myobeyspaces\global\let =\myspace}
\newif\ifCNewLine
\newif\ifCFirstNewLine
\newif\ifCSecondNewLine
\CSecondNewLinefalse
\newif\ifImCStarComment
\ImCStarCommentfalse
\newif\ifImCppComment
\ImCppCommentfalse
\newif\ifNichtImString
\NichtImStringtrue
%
\def\beginprog{\tabcolsep=0pt\begin{tabular}{>{\columncolor[gray]{0.92}}p{\dieBreite}}%
\setcounter{blankscounter}{0}\frenchspacing\CFirstNewLinefalse\beginprogprog}
\def\endprog{\endgroup\end{tabular}}

\def\beginprogprog{\begingroup
\parindent=0pt\CZeichen}

\def\Cdospecials{\do\{\do\}\do\$\do\&%
\do\#\do\^\do\_\do\%\do\~\do\"\do\'}

\def\Cmakeother#1{\catcode`#1=12\relax}

\begingroup \catcode`\-=\active
\gdef\CDefineActiveMinus{%
\catcode`\-=\active
\def-{\string-\relax}}
\endgroup
\begingroup \catcode`\/=\active
\gdef\CDefineActiveSlash{%
\catcode`\/=\active
\def/##1{\ifx/##1\ifNichtImString\CppComment\else\string/\string/\fi
\else\ifx##1\ifNichtImString\CStarComment\else\string/\string\fi
\else\string/##1\fi\fi}}
\endgroup

\begingroup \catcode`\<=\active
\gdef\CDefineActiveLess{%
\catcode`\<=\active
\def<{\string<\relax}}
\endgroup
\begingroup \catcode`\>=\active
\gdef\CDefineActiveGreater{%
\catcode`\>=\active
\def>{\string>\relax}}
\endgroup
\begingroup \catcode`\"=\active
\gdef\CDefineActiveQuot{%
\catcode`\"=\active%
\def"{{\ttfont\char34}\ifBackslash\Backslashfalse%
\else\ifNichtImString\NichtImStringfalse\stringfont%
\else\NichtImStringtrue\ttfont\fi\fi}}%
\endgroup
\def\CZeichen{\ttfont
\let\do=\Cmakeother \Cdospecials
\def\par{\setcounter{blankscounter}{0}\ifvmode\else%
\ifCSecondNewLine\newline\hbox{}%
\fi\fi%
\ifCFirstNewLine\CSecondNewLinetrue\fi%
\CFirstNewLinetrue
}%
\obeylines
\myobeyspaces
\CDefineActiveSlash\CDefineActiveLess%
\CDefineActiveMinus\CDefineActiveGreater\CDefineActiveQuot%
% the next empty line is necessary

\ifCNewLine \CNewLinefalse\par\fi}

\begingroup \obeylines%
\gdef\CDefineActiveNewline#1{\let^^M=#1\relax}%
\endgroup

\def\CppComment{//\endgroup
\begingroup\kfont
\CFirstNewLinetrue\CNewLinetrue
\obeylines\CDefineActiveNewline\CZeichen}

\def\CStarComment{/* \endgroup\CStarCommentLine}

\long\def\CStarCommentLine#1*/{%
\begingroup
\CFirstNewLinetrue%
{\settowidth{\CStarCommentwidth}{{\ttfont{x}}}%
\indentCorrection=\CStarCommentwidth%
\multiply\indentCorrection by\theblankscounter%
\setlength{\CStarCommentwidth}{\textwidth}%
\addtolength{\CStarCommentwidth}{-\indentCorrection}%
\addtolength{\CStarCommentwidth}{-1.5em}%
\begin{minipage}[t]{\CStarCommentwidth}\kfont
#1\\\hspace{-1em}{\ttfont /}%
\end{minipage}%
}%
\endgroup
\CNewLinefalse
\beginprogprog
\newline\hbox{}}
\endinput
%%
%% End of file c.sty

Brooks Moses <brooks>
Project Administrator

 

Attached Files
file #96:  lstlist1.pdf added by brooks (48kB - application/pdf)
file #97:  lstlist2.pdf added by brooks (47kB - application/pdf)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by brooks (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    2 latest changes follow.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed Apr 13 05:02:57 2011brooksAttached File-=>Added lstlist1.pdf, #96
      Attached File-=>Added lstlist2.pdf, #97
    Show feedback again

    Back to the top


    Powered by Savane 3.1-cleanup+gray