Conversion of Latex documents to Sage worksheets

5 views
Skip to first unread message

Rob Beezer

unread,
Jan 28, 2010, 12:16:36 AM1/28/10
to sage-devel
On several occasions I've posted the results of my experiments
converting latex documents into Sage worksheets, and as a result have
had a few requests for the relevant scripts and configuration files.
I've now written some minimal instructions, a minimal example and a
template latex file, and put everything up at

http://trac.sagemath.org/sage_trac/ticket/8105

Its not for the faint of heart. It should all work, but some assembly
is required. You need TeX for starters, and then you need a
relatively current installation of tex4ht (which probably means that
simply grabbing your distribution's package will *not* work), but I
have included fairly detailed instructions for installing it
yourself. Don't look inside the included Python script, just run
it. ;-)

I plan to make all of this as easy and streamlined as possible through
some combination of spkg's, notebook patches, TeX style files and
tex4ht configurations. Everything but writing your content for you.
Use the ticket for suggestions or comments, and add yourself to the cc
if you want to apprised of updates.

Rob

Rob Beezer

unread,
Jan 30, 2010, 11:51:50 PM1/30/10
to sage-devel
I've built a wiki page with some examples, code, experiments etc
related to this project:

http://wiki.sagemath.org/devel/LatexToWorksheet

Also, Dana Ernst and Dan Drake report getting the minimal test example
working with stock installations of tex4ht (mactex, TeXLive 2009,
respectively), so the barrier to entry may not be so great.
Contributions of nontrivial examples to the wiki page are encouraged.

Thanks,
Rob

Rob Beezer

unread,
Feb 7, 2010, 9:15:26 PM2/7/10
to sage-devel, sage-n...@googlegroups.com
Lots of progress this week. Assuming you can get your Latex through
the tex4ht processor successfully then the script I have written will
quite faithfully convert the output to a Sage worksheet in sws
format. Included graphics pass through to the worksheet and if you
write tikz/pgf graphics in your latex source then they pass through to
the worksheet as SVG graphics. Limited support for combinatorial
graphs in tkz-graph format. This should all be usable now, but the
interface to tex (two commands at the moment) could change, though it
should be easy to adapt to any changes.

Experimentally I can process large documents (ie with multiple
sections, subsections) into a tarball that can be installed in your
notebook as a collection of linked worksheets, at the price of having
to install it as pristine new user (in order to control the worksheet
numbering and linking). My 900-page linear algebra text becomes
around 100 linked worksheets, comprising 700K as a tarball. This is
posted as an example on the project wiki page, though it takes some
care to install properly.

Thought-du-jour is to have authors handle the tex4ht conversion
themselves, with a post-processing hook used to create a tarball.
Tarball gets posted at author's site or a Sage site. Routines in the
notebook support pulling across the tarball, processing the contents
into worksheets, and they get installed in the user's notebook. A
recent post here [1] asked about distributing a reference manual for
an optional package. Though this was not the idea discussed there,
something similar with ReST format files might work along similar
lines to extend the library of reference materials available to users
in the notebook.

Rob

Wiki Page w/ Examples: http://wiki.sagemath.org/devel/LatexToWorksheet

Script, readme, support files: http://bitbucket.org/rbeezer/tex2sws/

[1] http://groups.google.com/group/sage-devel/browse_thread/thread/f3ef8b5fa107b73f

Rob Beezer

unread,
Feb 21, 2010, 3:49:28 AM2/21/10
to sage-devel
I think the conversion of LaTeX to single worksheets is ready for
testing. You'll need tex, tex4ht and sagetex at a minimum, with sage
installed locally. Most of what you need to know is at the wiki page:

http://wiki.sagemath.org/devel/LatexToWorksheet

Download the "Approximating Polynomial Worksheet" example into a
notebook if you just want to get a feel for what this is all about.
(COPY the following link into the worksheet upload URL field.)
http://bit.ly/diWLVA

If you are able to test, I'd love to hear about successes and
failures, especially relative to heavy use of unicode characters.
Thanks, Rob

~~~~~~~~~~~~~~~~~~~

Recent Progress:

* I think unicode (UTF-8) characters are being handled properly. In
other words, if you can get tex4ht to handle your characters properly,
then I think they will survive the trip to your worksheet and
browser. Robert Marik is largely responsible for this. Maybe those
who write with a variety of accented characters will find this useful.

* LaTeX files created with sagetex seem to be digestible, and are a
natural for this conversion.

* Better decisions about what mathematics to leave for jsMath and what
to convert, thanks to code from Robert Marik.

* tikz graphics and "\includegraphics{}" both get translated
properly. tikz graphics get rendered as SVG, other file formats which
are "included" are converted to PNG automatically by tex4ht.

* Experimental code lets the conversion run as pure python,
independent of Sage or the notebook project.


To Do:

* Portable container for multiple, cross-linked worksheets.

* Notebook folders.

Reply all
Reply to author
Forward
0 new messages