Smalltalk syntax highlighting for Latex

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Smalltalk syntax highlighting for Latex

Mariano Martinez Peck
Hi guys. I know that: a) for papers we usually write code in black and white and b) even when we may want colors like books or thesis, we still may not want to add colors.
Anyway, for my thesis, I do want to make the code a little bit nicer and so I did some Smalltalk syntax highlighting with listings package. Not sure if this would be helpful for someone else, but just in case, I paste at the end the code.
Basically, I can detect (and therefore, choose a color/style): globals/classes (start with uppercase), keywords, comments, strings, symbols and numbers.
I also attach an screenshot.

Cheers

btw, thanks to Lukas and Luc for their help.



% Source Code
\usepackage{color}
\usepackage{textcomp}
\usepackage{listings}
% \usepackage{needspace}
% \usepackage{ulem}

\definecolor{source}{gray}{0.95}

% my comment style
\newcommand{\myCommentStyle}[1]{{\footnotesize\ttfamily\itshape\color{gray!100!white} #1}}

% my string style
\newcommand{\myStringStyle}[1]{{\footnotesize\ttfamily\color{violet!100!black} #1}}

% my symbol style
\newcommand{\mySymbolStyle}[1]{{\footnotesize\ttfamily\color{violet!100!black} #1}}

% my keyword style
\newcommand{\myKeywordStyle}[1]{{\footnotesize\ttfamily\color{green!70!black} #1}}

% my global style
\newcommand{\myGlobalStyle}[1]{{\footnotesize\ttfamily\color{blue!100!black} #1}}

% my number style
\newcommand{\myNumberStyle}[1]{{\footnotesize\ttfamily\color{brown!100!black} #1}}

\lstset{
    language={},
    % characters
    tabsize=3,
    escapechar={!},
    keepspaces=true,
    breaklines=true,
    alsoletter={\#},
    breakautoindent=true,
    columns=fullflexible,
    showstringspaces=false,
    % background
    frame=single,
    aboveskip=1em, % automatic space before
         framerule=0pt,
    basicstyle=\footnotesize\ttfamily\color{black},
    keywordstyle=\myKeywordStyle,% keyword style
    commentstyle=\myCommentStyle,% comment style
    frame=single,%
    backgroundcolor=\color{source},
    % numbering
    numbersep=5pt,
    numberstyle=\myNumberStyle,
    numberfirstline=true,
    % caption
    captionpos=b,
    % formatting (html)
    moredelim=[is][\textbf]{<b>}{</b>},
    moredelim=[is][\textit]{<i>}{</i>},
    moredelim=[is][\uline]{<u>}{</u>},
    moredelim=[is][\color{red}\uwave]{<wave>}{</wave>},
    moredelim=[is][\color{red}\sout]{<del>}{</del>},
    moredelim=[is][\color{blue}\uline]{<ins>}{</ins>},
    % smalltalk stuff
    morecomment=[s][\myCommentStyle]{"}{"},
%    morecomment=[s][\myvs]{|}{|}, 
    morestring=[b][\myStringStyle]',
    moredelim=[is][]{<sel>}{</sel>},
    moredelim=[is][]{<rcv>}{</rcv>},
    moredelim=[is][\itshape]{<symb>}{</symb>},
    moredelim=[is][\scshape]{<class>}{</class>},
    morekeywords={true,false,nil,self,super,thisContext},
    identifierstyle=\idstyle,
    }
   

\makeatletter
\newcommand*\idstyle[1]{%
         \expandafter\id@style\the\lst@token{#1}\relax%
 }
 \def\id@style#1#2\relax{%
           \ifnum\pdfstrcmp{#1}{\#}=0%
                % this is a symbol
                \mySymbolStyle{\the\lst@token}%
            \else%
              \edef\tempa{\uccode`#1}%
              \edef\tempb{`#1}%
              \ifnum\tempa=\tempb%
              % this is a global
              \myGlobalStyle{\the\lst@token}%
              \else%
                  \the\lst@token%
             \fi%
            \fi%
 }
 \makeatother


\lstset{literate=%
    *{0}{{{\myNumberStyle{0}}}}1
    {1}{{{\myNumberStyle{1}}}}1
    {2}{{{\myNumberStyle{2}}}}1
    {3}{{{\myNumberStyle{3}}}}1
    {4}{{{\myNumberStyle{4}}}}1
    {5}{{{\myNumberStyle{5}}}}1
    {6}{{{\myNumberStyle{6}}}}1
    {7}{{{\myNumberStyle{7}}}}1
    {8}{{{\myNumberStyle{8}}}}1
    {9}{{{\myNumberStyle{9}}}}1
 }
 
   
%\newcommand{\ct}{\lstinline[backgroundcolor=\color{white}]}
\newcommand{\needlines}[1]{\Needspace{#1\baselineskip}}
\newcommand{\lct}{\texttt}


\lstnewenvironment{code}{%
    \lstset{%
        % frame=lines,
        frame=single,
        framerule=0pt,
        mathescape=false
    }
}{}
   
   
\newenvironment{codeNonSmalltalk}
    {\begin{alltt}\sffamily}
    {\end{alltt}\normalsize}





--
Mariano
http://marianopeck.wordpress.com


_______________________________________________
Sbe-discussion mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/sbe-discussion

Screen shot 2012-06-15 at 10.35.43 AM.png (105K) Download Attachment