Path: news.mathworks.com!newsfeed-00.mathworks.com!newscon02.news.prodigy.net!prodigy.net!news-feed01.roc.ny.frontiernet.net!nntp.frontiernet.net!news02.roc.ny.POSTED!53ab2750!not-for-mail
From: Doug Schwarz <see@sig.for.address.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Publish to latex with syntax highlighting
References: <ef558a9.-1@webcrossing.raydaftYaTP>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
User-Agent: MT-NewsWatcher/3.5.1 (Intel Mac OS X)
Message-ID: <see-A91AED.17290301052007@news.frontiernet.net>
Lines: 66
X-Complaints-To: abuse-news@frontiernet.net
X-Trace: 52616e646f6d49562b9a4c60c190d420504df0dffaf546edc2c17678c7d66fcb07eb324247be7a831be48a32607e96829a6ad44db72d47077b5a22e1eb8d6ca2a3357fc2258e852e83e3606cd8d13261ec74e5db5de711286027d291effc9490bbcb4171b587e55e6eb440156ab2f3d8
X-Abuse-Info: Please be sure to forward ALL headers so that we may process your complaint properly.
NNTP-Posting-Date: Tue, 01 May 2007 21:28:52 UTC
Date: Tue, 01 May 2007 21:28:52 GMT
Xref: news.mathworks.com comp.soft-sys.matlab:406317


In article <ef558a9.-1@webcrossing.raydaftYaTP>,
 Kelly <kakearney@nospamgmail.com> wrote:

> When I publish a document to html, the blocks of code in the final
> document use the colored syntax highlighting corresponding to the
> Matlab editor, and are also surrounded by a light gray box. However,
> when I publish to Latex, the code remains in black and is not offset
> from the rest of the text, making it a little more difficult to
> distinguish descriptive text from the code in the final document.
> 
> Is there a way to add syntax highlighting to the final Latex
> document? There is a small section in the mxdom2latex.xsl file that
> seems to have this aim (lines 162 - 180). However, I don't knw much
> about Latex coding beyond the very basics, so I may be
> misunderstanding it.
> 
> For the record, I'm running R2006b beta for Intel Macs on a MacOS X
> system.
> 
> Thanks,
> Kelly

You might want to try the listings package.  Here's an example:

-------------------- matlab_listings.tex ----------------------------
\documentclass{article}
\usepackage[margin=0.75in]{geometry}
\usepackage{courier}
\usepackage{color}
\usepackage{listings}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}

\begin{document}

\lstset{language=Matlab,
   keywords={break,case,catch,continue,else,elseif,end,for,function,
      global,if,otherwise,persistent,return,switch,try,while},
   basicstyle=\ttfamily,
   keywordstyle=\color{blue},
   commentstyle=\color{red},
   stringstyle=\color{dkgreen},
   numbers=left,
   numberstyle=\tiny\color{gray},
   stepnumber=1,
   numbersep=10pt,
   backgroundcolor=\color{white},
   tabsize=4,
   showspaces=false,
   showstringspaces=false}

\begin{lstlisting}
function y = demo(x) % This is a comment.
   str = 'hello there';
   y = x + 1;
end
\end{lstlisting}

\end{document}
-----------------------------------------------------------------------

-- 
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.