Sage is a neat bundle of mathematical software that can be used to do anything from finding class numbers of number fields (like I did to make this graph) to testing whether a finitely presented group is trivial (sometimes…). Typically one works with Sage in a “worksheet” in a web browser, so that it’s easy to organise large numbers of calculations for later reference. Navigating large worksheets, however, might be cumbersome without a table of contents, just like long math papers without a table of contents are hard to read.

In this post, we’ll go over how to (manually) make a table of contents in your Sage worksheet with HTML, with the following example: let’s say you have a section title “Invariant Theory Calculations”, and you have put this as text in your worksheet using Shift+LeftClick. It should look something like this:

Next, Shift-LeftClick on “Invariant Theory Calculations” to edit, and click on the “HTML” button as highlighted here:

You will see code that looks like:

<p><span style="font-size: large;">Invariant Theory Calculations</span></p>

Change it to:

<p><span style="font-size: large;"><a id="sec:invarianttheory">

Invariant Theory Calculations</a></span></p>

The <a> tag in HTML is for hyperlinks, and “id” allows you to create a bookmark on that page. I set “id” equal to “sec:invarianttheory” but you can write anything you want. To link to it in the table of contents, create a table of contents at the top of the document by Shift+LeftClick at the top to create a new cell, and then add a numbered list:

I’ve called the entry “Invariant Theory Calculations”. Highlight the text and click the link button. In this screenshot, I’ve highlighted the text and indicated on the image where the link button is:

Press that button, and you’ll get a popup window, one of which has the field “Link URL”. Type in that box: #sec:invarianttheory as in the screenshot below:

Make sure there is a # sign before the name you choose for the “id” field. Click “Update” and then “Save Changes” and you’ll have your first table of contents link! Now, whenever it is clicked, you’ll travel straight to that header “Invariant Theory Calculations”.

Unfortunately, adding a table of contents is not automatic like LaTeX and you have to add all the links yourself, and change them when necessary. To be even more organised, it’s possible to use Sage within a LaTeX document with sagetex though I have not tried this myself.