Hi Nicolas, On Tue, 17 Nov 2009 at 11:32PM +0100, Nicolas M. Thiery wrote: > I have a feature request: an environment where I could use the same > syntax as in usual doctests (without the sage results): > > \begin{sageexample} > sage: 1 + 1 > sage: def f(x): > ... x^2 > sage: f(3) > \end{sageexample} > > And have it typeset with the sage commands in texttt, interspersed > with the Sage outputs, in (display) math mode: > > sage: 1 + 1 > 2 > > sage: def f(x): > ... x^2 > sage: f(3) > 9
I've been thinking about that. I've wanted it too. > Here is my current partial implementation: > > \newenvironment{sageexample}{% > \def\verba...@processline{\hspace{\sagetexindent}sage: > \the\verba...@line\[\sage{\the\verbatim@line}\]}% > \verbatim}% > {\endverbatim} > > It does not handle the sage: / ... line prefixes. Those should > probably be passed down to sage + sagetex.py and handled there, > reusing the doctest infrastructure. Right now, when you typset the document, you get a Sage script written to the current directory. LaTeX pretty much writes the lines straight to the script, and it's hard to strip things off the line. In Python, I could so something like the_verbatim_line.replace('sage: ', '', 1) but LaTeX does not make string handling easy. Using the doctest infrastructure is a good idea and might be useful. > Oh, and by the way, another dream feature would be a > \sageinert{diff(sin(x),x)} which would typeset an inert version of the > given formula, without evaluating it. A typical use case would be to > get nicely typeset equations like: > > \sageinert{diff(sin(x),x)} = \sage{diff(sin(x),x)} > > But I don't know how feasible or even meaningful this would currently > be. For the record, MuPAD had such a mechanism which was used for > typesetting formulas in the documentation. So you would like your example to produce the same output as \frac{d}{dx} \sin(x) = \cos(x) ? Hmm, that might hard. I'm not sure how to do that. Right now, when you do \sage{diff(sin(x), x)}, it runs something like latex(diff(sin(x), x)) and I don't know how to tell latex() to not fully evaluate the diff(). Dan -- --- Dan Drake ----- http://mathsci.kaist.ac.kr/~drake -------
signature.asc
Description: Digital signature