Hi Javier,

One of the main points of sagecommandline is to create examples with
*automatic* output, similar to doctests in modules. This is also the
reason why stuff without "sage:" or "..." in the beginning does not
show up: it is interpreted as output that should NOT be inserted into
the final result, but rather compared with the output of the above
code if you run doctests. It does use custom-tuned lstlistings inside
and it is not made extremely colorful on purpose, as I understand it.
This can be changed quite easily (although you need to know
lstlistings parameters as in your code). For example, the file here
http://hdl.handle.net/10048/2142 (don't mean to be unmodest, but
that's the example I know best ;-)) uses sagecommandline intensively
and contains in the preambule

% SageTeX tuning
\usepackage[dvipsnames]{xcolor}
\usepackage[scaled]{luximono}
\usepackage{sagetex}
\lstdefinestyle{SageTEXAdjustment}{numbers=none, xleftmargin=1ex,
xrightmargin=1ex, framesep=1ex, frame=rl, breakatwhitespace=True,
basicstyle={\ttfamily\small}, backgroundcolor=\color{Goldenrod!25},
framerule=0pt}
\lstdefinestyle{SageInput}{style=DefaultSageInput,
style=SageTEXAdjustment}
\lstdefinestyle{SageOutput}{style=DefaultSageOutput,
style=SageTEXAdjustment, basicstyle={\ttfamily\small\bfseries}}
\lstset{style=SageInput}
\newcommand{\sagecommand}[1]{\lstinline!#1!}

Code coloring is still quite conservative, but for example
sagecommandline allows you to make input plain and output bold - I
don't think it is easy to achieve with lstlistings directly
(sagecommandline sets up different environments for each line - who
would do that by hand?!). Of course, it only matters if you actually
have output in your examples.

Best regards,
Andrey

On Oct 26, 9:06 am, javier <vengor...@gmail.com> wrote:
> 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

Reply via email to