Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to add a language (Scheme) in the lstlisting package.

\section{Scheme}
\lstdefinelanguage{Scheme}
{morekeywords={,lambda, cond, case, display, let, import, quote, quasiquote, unquote,
define, begin, newline, if, list, apply, null?, car, cdr, or, not, and, for-each, 
make-vector, vector-length, vector-ref, vector-set!, eqv?, eq?, equal?, else, set!, 
define-record-type, fields, mutable, immutable, assert, parent, with-exception-handler, }
sensitive=false,
morecomment=[l]{;},
morecomment=[s]{/*}{*/},
morestring=[b]",
}

But, it does when I use a lstlisting it does not recognize the keyword with "!", "?", "-"...

Do you know how can I fix it?

Thank you,

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

Andreas Stuhlmüller (stuhlmueller) in github developed a Scheme syntax highlighting for the LaTeX listings package. Please, see:

https://github.com/stuhlmueller/scheme-listings

Another possibility is to use SLaTeX, available in http://evalwhen.com/slatex/slatxdoc.html

At http://evalwhen.com/slatex/slatxdoc-Z-H-3.html#node_sec_3 there are examples of use of the "?" for word termination.

share|improve this answer
    
Thanks, now it is better. But it still do not recognize the "?" ending words: like null?, list?, eq?, etc etc, also if i add them in the morekeywords list. Any idea? –  user12818 Apr 25 '12 at 15:50
    
Did you try escaping the question marks? e.g. positive\?? –  gmfawcett Apr 16 '13 at 17:14
add comment

If you want ?, !, -, etc. to be allowed in keywords, you need to make them letters, using the listings key called alsoletter, like so

alsoletter=!?-,

I've shamelessly taken the listings language definition for Scheme that is available at the end of the link posted in Papiro's answer, added your keywords to it, and made ?, !, - letters. See below.

enter image description here

\documentclass{article}

\usepackage[T1]{fontenc}
\renewcommand{\ttdefault}{pcr}
\usepackage{xcolor}
\usepackage{textcomp}
\usepackage{listings}

\usepackage{filecontents}
\begin{filecontents*}{ycombinator.ss}
(eqv? 'a 'a)                           ==>  #t
(eqv? 'a 'b)                           ==>  #f
(eqv? 2 2)                             ==>  #t
(eqv? '() '())                         ==>  #t
(eqv? 100000000 100000000)             ==>  #t
(eqv? (cons 1 2) (cons 1 2))           ==>  #f
(eqv? (lambda () 1)
      (lambda () 2))                   ==>  #f
(eqv? #f 'nil)                         ==>  #f
(let ((p (lambda (x) x)))
  (eqv? p p))                          ==>  #t
\end{filecontents*}


\lstdefinelanguage{Scheme}{
  morekeywords=[1]{define, define-syntax, define-macro, lambda,
    define-stream, stream-lambda},
  morekeywords=[2]{begin, call-with-current-continuation, call/cc,
    call-with-input-file, call-with-output-file, case, cond,
    do, else, for-each, if,
    let*, let, let-syntax, letrec, letrec-syntax,
    let-values, let*-values,
    and, or, not, delay, force,
    quasiquote, quote, unquote, unquote-splicing,
    map, fold, syntax, syntax-rules, eval, environment, query,
    display, newline,list, apply, null?, car, cdr, for-each, 
make-vector, vector-length, vector-ref, vector-set!, eqv?, eq?, equal?, set!, 
define-record-type, fields, mutable, immutable, assert, parent, with-exception-handler,
  },
  morekeywords=[3]{import, export},
  alsoletter=?!-,
  alsodigit=\$\%&*+./:<=>@^_~,
  sensitive=false,
  morecomment=[l]{;},
  morecomment=[s]{/*}{*/},
  morestring=[b]",
  basicstyle=\small\ttfamily,
  keywordstyle=\bf\ttfamily\color[rgb]{0,.3,.7},
  commentstyle=\color[rgb]{0.133,0.545,0.133},
  stringstyle={\color[rgb]{0.75,0.49,0.07}},
  upquote=true,
  breaklines=true,
  breakatwhitespace=true,
  literate=*{`}{{`}}{1}
}

\begin{document}
\section{Scheme}
\lstinputlisting[language=Scheme]{ycombinator.ss}
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.