experiment with a new version of the SageTeX package

23 views
Skip to first unread message

Dan Drake

unread,
Sep 26, 2010, 5:13:59 AM9/26/10
to sage-devel
Hello,

I've been working on a new version of SageTeX and I'd like some
feedback. There are two major changes:

First, the auxilliary files that SageTeX produces now (mostly) include
".sagetex". So you need to run Sage on foo.sagetex.sage. This will
prevent SageTeX from clobbering the user's other Sage files, and makes
it easier to find files that can safely be deleted. (The
foo_doctest.sage file keeps its name, because, IIRC, problems with the
doctesting framework.)

Second, Volker Braun contributed a big patch that implements something
that I've wanted for a long time: an environment that automatically
fills in Sage output. You put in your TeX file:

\begin{sagecommandline}
sage: 1+1
sage: factor(2^(2^5)+1)
\end{sagecommandline}

and the outputs are neatly colored and typeset in your document (imagine
the following is neatly typeset):

sage: 1+1
2
sage: factor(2^(2^5)+1)
641 * 6700417

This needs testing. If you are adventurous, you can do

sage -f http://sagenb.kaist.ac.kr/~drake/sagetex-2.2.5.p1.spkg

to get the new spkg. (The "real" release will likely be version 2.3 and
include proper updates to SPKG.txt and friends.) Look in the example.tex
file and experiment. If you are especially adventurous, check out the
TeX and Sage code for the new environment.

I'm aware of several issues:

* The documentation needs to be updated.

* Any commands you give with no output get put into the _doctest.sage
file with no output, and fail the doctest because it expects nothing.
I'm not sure what to do about this; perhaps not write sagecommandline
stuff into that file?

* Is "sagecommandline" a good name for the environment?

* Should sageexample and sagecommandline be merged? There is certainly
unnecessary code duplication there. My impression is that there
should be one environment, with two modes: a "figure out the answer
for me" mode, and a "here's the answer, make sure Sage gets it
right" mode.

* The new environment creates yet another auxilliary file. Is there a
way around this? Some output can't be typeset because they're
statements, not expressions (or the other way around; I forget). Can
we work around this in a reasonable way?

Please test, report, and comment on anything above. Thanks!

Dan

--
--- Dan Drake
----- http://mathsci.kaist.ac.kr/~drake
-------

signature.asc

Volker Braun

unread,
Sep 26, 2010, 8:15:56 AM9/26/10
to sage-devel
How about foo_sagetex.sage and foo_doctest.sage for consistency.

The new sagecommandline environment needs yet another auxiliary file
because it is based on the listings package and not verbatim. LaTeX
can feed input directly into verbatim macros, but not into listings
code. On the plus side, listings looks better than verbatim, having
the sage output saved into an auxiliary file is more flexible, and it
helps with debugging.

As for the environment names, right now there is:

1) sagesilent: executed in sage, nothing is typeset

2) sageblock: executed in sage, typeset sage commands as verbatim,
skip sage output

3) sageverbatim: not executed in sage, typeset as verbatim.

4) sageexample: doctest-like

5) sagecommandline: see the original email.

I think ideally they would all be combined into a single "sage"
environment, with options that determine whether to typeset the sage
command, the sage output, and whether to doctest. By default, it would
then behave like sagecommandline does now.

\begin{sage}[option]
sage: 1+1
2
\end{sage}

with one or more comma-separated option, say,

* noinput: do not typeset the "sage: 1+1"
* noprompt: do not typeset "sage:" but do typeset "1+1"
* nooutput: do not typeset the sage output
* text: typeset the output as text (listing environment)
* doctest: write sage command and output to foo_doctest.sage

The defaults could then be set globally by something like

\renewcommand{\sagedoctest}{True}

Best wishes,
Volker

Ondrej Certik

unread,
Sep 27, 2010, 12:31:27 AM9/27/10
to sage-...@googlegroups.com
Hi Dan!

On Sun, Sep 26, 2010 at 2:13 AM, Dan Drake <dr...@kaist.edu> wrote:
> Hello,
>
> I've been working on a new version of SageTeX and I'd like some
> feedback. There are two major changes:

[...]


>
> Please test, report, and comment on anything above. Thanks!


Are there any plans to integrate this with sphinx? Here is an example
(go to the very end of the page):

http://theoretical-physics.net/dev/src/math/feynman-parameters.html#example-2

currently I need to copy & paste the (latexed) output from sympy by
hand into the sphinx document. So I was thinking to create something
like sagetex, but for sphinx.


What are your usage scenarios with sagetex? Do you use it to write
articles and keep the formulas in some form, that can be manipulated?

Ondrej

Dan Drake

unread,
Sep 27, 2010, 12:44:23 AM9/27/10
to sage-...@googlegroups.com
On Sun, 26 Sep 2010 at 05:15AM -0700, Volker Braun wrote:
> How about foo_sagetex.sage and foo_doctest.sage for consistency.

That's a thought. I'm much more accustomed to using dots as separators,
though.

> The new sagecommandline environment needs yet another auxiliary file
> because it is based on the listings package and not verbatim. LaTeX
> can feed input directly into verbatim macros, but not into listings
> code. On the plus side, listings looks better than verbatim, having
> the sage output saved into an auxiliary file is more flexible, and it
> helps with debugging.

I asked if there was another way to do it mostly out of curiosity, not
to suggest that your patch wasn't a good one. On the contrary, your
contribution is really great -- it's something I've wanted for a long
time now.

> As for the environment names, right now there is:

[...]


> I think ideally they would all be combined into a single "sage"
> environment, with options that determine whether to typeset the sage
> command, the sage output, and whether to doctest. By default, it would
> then behave like sagecommandline does now.

After I wrote my message, I realized that yes, all the "sage*"
environments could perhaps be unified. Your idea of one environment that
takes options is a good one.

signature.asc

Dan Drake

unread,
Sep 27, 2010, 1:26:24 AM9/27/10
to sage-...@googlegroups.com
On Sun, 26 Sep 2010 at 09:31PM -0700, Ondrej Certik wrote:
> Are there any plans to integrate this with sphinx? Here is an example
> (go to the very end of the page):
>
> http://theoretical-physics.net/dev/src/math/feynman-parameters.html#example-2
>
> currently I need to copy & paste the (latexed) output from sympy by
> hand into the sphinx document. So I was thinking to create something
> like sagetex, but for sphinx.

I've never thought of anything "SageTeX-like" for Sphinx, since I've
never written anything other than Sage docstrings using it.

To get something analogous working for Sphinx, you'd need something in
the Sphinx build process that would call Sage, or write something to a
file that could be processed with Sage. One of the key ideas in SageTeX
is that you can use the usual TeX \newlabel{} and \ref{} to pull in
stuff from an external file. Is there a corresponding mechanism in
Sphinx?

> What are your usage scenarios with sagetex? Do you use it to write
> articles and keep the formulas in some form, that can be manipulated?

A bit. Actually, what I use it most for is doing tables and TikZ plots
for me -- see sections 4 and 6 in the example file [1].

Dan


References:
[1] https://bitbucket.org/ddrake/sagetex/downloads/example.pdf

signature.asc

Ondrej Certik

unread,
Sep 27, 2010, 2:42:54 AM9/27/10
to sage-...@googlegroups.com
On Sun, Sep 26, 2010 at 10:26 PM, Dan Drake <dr...@kaist.edu> wrote:
> On Sun, 26 Sep 2010 at 09:31PM -0700, Ondrej Certik wrote:
>> Are there any plans to integrate this with sphinx? Here is an example
>> (go to the very end of the page):
>>
>> http://theoretical-physics.net/dev/src/math/feynman-parameters.html#example-2
>>
>> currently I need to copy & paste the (latexed) output from sympy by
>> hand into the sphinx document. So I was thinking to create something
>> like sagetex, but for sphinx.
>
> I've never thought of anything "SageTeX-like" for Sphinx, since I've
> never written anything other than Sage docstrings using it.
>
> To get something analogous working for Sphinx, you'd need something in
> the Sphinx build process that would call Sage, or write something to a
> file that could be processed with Sage. One of the key ideas in SageTeX
> is that you can use the usual TeX \newlabel{} and \ref{} to pull in
> stuff from an external file. Is there a corresponding mechanism in
> Sphinx?

Yes, it is. You write a simple plugin (in Python) that gets called by
sphinx when you write something like:

Some paragraph, bla bla, and some equation:

.. sage:

sin(x).diff(x)


and you do whatever you want.

>
>> What are your usage scenarios with sagetex? Do you use it to write
>> articles and keep the formulas in some form, that can be manipulated?
>
> A bit. Actually, what I use it most for is doing tables and TikZ plots
> for me -- see sections 4 and 6 in the example file [1].

I see. My goal is to go one step further and have something, so that I
can enter formulas (at least some simpler ones at the beginning) using
sympy (or Sage in your case, that doesn't really matter), and just
keep it in that form, and it would somehow automatically be converted
to latex. And in the html output, I can imagine a link, that would
allow me to modify such formula (using some web interface to sympy /
Sage). Also so that I can only create some calculation and simply tell
it (somehow) that these and those results should endup in the
document, without having to copy & paste or worry about anything.

And of course to autogenerate some tables, as you do too.

Ondrej

Jason Grout

unread,
Sep 27, 2010, 6:30:40 AM9/27/10
to sage-...@googlegroups.com
On 9/26/10 11:44 PM, Dan Drake wrote:
> On Sun, 26 Sep 2010 at 05:15AM -0700, Volker Braun wrote:
>> How about foo_sagetex.sage and foo_doctest.sage for consistency.
>
> That's a thought. I'm much more accustomed to using dots as separators,
> though.

I suppose that the "latex" way of handling things would be to just have
sagetex as the extension, right?

i.e., foo.sagetex

Jason

Andrey Novoseltsev

unread,
Nov 11, 2010, 12:29:32 PM11/11/10
to sage-devel
I was playing with sageexample environment, didn't quite like what I
was getting (compared to what I planned), and while I was figuring out
a way to suggest a new environment, I found out that Volker has
already timely produced sagecommandline, which made me very happy.

However, after seeing what sageexample does, I want to propose yet
another version, behaving like a "session in Sage notebook." Say, I
write something like this:

\begin{sagenotebook}
1 + 1
3^2

x^2

print x^2

show(x^2)
\end{sagenotebook}

with empty lines indicating cell boundaries (perhaps there is a better
way to indicate them), and it produces

-----------
| 1 + 1
| 3^2
-----------
9
-----------
| x^2
-----------
x^2 (typeset as inline, flushed to the left, no extra vertical space
before/after)
-----------
| print x^2
-----------
x^2 (as text, no typesetting)
-----------
| show(x^2)
-----------
x^2 (typeset as displayed, centered, some extra vertical space)

i.e. input is typeset as code in framed boxes of "pagewidth minus
indents" width and the output is typeset like in the notebook with
"typeset" checkbox on. Or better yet, choose the default output style
using some option, but still allowing one to explicitly use print/view/
show to get text/inline/displayed. I don't know how difficult it is to
implement, but I think it would be awesome for giving Sage examples in
papers and books!

Thank you,
Andrey

jyr

unread,
Nov 14, 2010, 3:56:02 PM11/14/10
to sage-devel
Hi,

First of all let me say that I am currently writing a math text book
where I am using a lot of sagetex and I think it is a great package!

Having said that as a "user" I am a bit concerned that the syntax of
sagetex is going to change if I want to publish the latex sources or
describe examples in a book as this would lead to frustration with
outdated code examples (books do not tend to be as often updated as
software unfortunately :-). I would think that other people writing
books may have similar issues.
Could I therefore suggest to either change the syntax really soon or
not at all, I personally do not care how I am accessing sagetex
functionality and it is at best irrelevant syntactic sugar to the
user.

regards

Jens
>  signature.asc
> < 1KViewDownload
Reply all
Reply to author
Forward
0 new messages