Hi Dan, I found a solution using listings indeed. I set up my own "sagecode" environment by adding to my preamble the following
\usepackage{listings} % Used for code listing \usepackage{textcomp} % Used for syntax highlighting. \usepackage{setspace} % Used for changing linespace % This gives syntax highlighting in the sagecode environment \definecolor{gray}{gray}{0.3} \definecolor{key}{rgb}{0,0.5,0} \lstnewenvironment{sagecode}[1][] { \lstset { language=python, basicstyle=\ttfamily\small\setstretch{0.8}, stringstyle=\color{red}, showstringspaces=false, alsoletter={1234567890}, otherkeywords={\ , \}, \{}, keywordstyle=\color{blue}, emph={access,and,break,class,continue,def,del,elif ,else,% except,exec,finally,for,from,global,if,import,in,is,% lambda,not,or,pass,print,raise,return,try,while,cached_method}, emphstyle=\color{black}\bfseries, emph={[2]True, False, None, self}, emphstyle=[2]\color{key}, emph={[3]from, import, as}, emphstyle=[3]\color{blue}, upquote=true, morecomment=[s]{"""}{"""}, commentstyle=\color{gray}\slshape, emph={[4]1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, emphstyle=[4]\color{blue}, literate=*{:}{{\textcolor{blue}:}}{1}% {=}{{\textcolor{blue}=}}{1}% {-}{{\textcolor{blue}-}}{1}% {+}{{\textcolor{blue}+}}{1}% {*}{{\textcolor{blue}*}}{1}% {!}{{\textcolor{blue}!}}{1}% {(}{{\textcolor{blue}(}}{1}% {)}{{\textcolor{blue})}}{1}% {[}{{\textcolor{blue}[}}{1}% {]}{{\textcolor{blue}]}}{1}% {<}{{\textcolor{blue}<}}{1}% {>}{{\textcolor{blue}>}}{1}% {@}{{\textcolor{blue}@}}{1},% rulesepcolor=\color{blue}, % numbers=right, % For adding line numbers % numberstyle=\footnotesize, % Line numbers size % stepnumber=1, % Line numbers step % breaklines=true, #1 } }{} Then I use \begin{sagecode} ...whatever... \end{sagecode} and works beautifully, apart from one funny quirk. If I try to add line breaking to the environment (by uncommenting the line "breakline=true") then the closing parenthesis ")" stop getting colorized in blue (?) I have no idea why this happens, but for now this suits my needs (with the added advantage of not having to install pygments in a place where my latex can find it). If you think than any of this code or any variation would make an useful addition to sagetex, feel free to rip it off! Cheers, Javier On Oct 26, 1:21 pm, Dan Drake <dr...@kaist.edu> wrote: > On Wed, 26 Oct 2011 at 02:03AM -0700, javier wrote: > > Basically what I want is to add "syntax highlight" to the code > > listing. I thought that worked out of the box with sagecommandline but > > now I realize it is only the sage prompt that gets colorized, so I > > will probably make my own environment based on minted for code > > listing. > > In that case, take a look at the lstlistings stuff in SageTeX for the > sagecommandline environment. There's some nice stuff there based on the > Python syntax highlighting. (Or just use the "listings" package and set > the syntax to Python.) > > Dan > > -- > --- Dan Drake > ----- http://mathsci.kaist.ac.kr/~drake > ------- > > signature.asc > < 1KViewDownload -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org