Equation numbering (and, more generally, (cross-)references management) is not in the scope of Sage.
What you are looking for is a document preparation system able to include and manage Sage inputs, outputs and references to them.
One solution is Sage's SageTeX, which offers the possibility of interleaving the source of a Sage program and its results (textual, LaTeX and/or figures) with the text describing it, by post-processing the result of a first LaTeX run with a tool executing Sage snippets and inserting their source and/or results in the LaTeX source for (re-)processing. This solution, part of the standard Sage distributions, is the best for seasoned LaTeX users aiming at the preparation PDF/printed papers or presentations with their usual tools.
I have also had some success with PythonTeX, which allows for the use of several languages (notably including R
) the same way.
The problem is more complex when aiming at preparing other types of documents, such as (X)HTML pages or (shudder...) Word or Powerpoint files (a necessity outside scientific academia...) :
One possibility is to prepare LaTeX files and convert them to your desired output, for example with pandoc
, which as an astonishing range of output formats.
Another one is to use a document preparation system able to generate your desired output(there are legions) and pre- or post-process it with a SageTeX-like tool (those are rare...). I have had some success with :
codebraid
, which uses markdown
for text input and pandoc
as the processor ; supports a handful of programming languages (including R
), generates anything pandoc
can generate ;
org-mode
's babel
tool, which allows the insertion and execution of code written in about 70 programming languages and tools, and generate a large range of outputs (notably thanks to a clever use of pandoc
in some cases) ; interestingly, this tool is a package of the (remarkable) emacs
text editor, which might be considered as a bug or as a feature, according to your taste...
A third possibility is to use a system supporting Python
code and feeding it preprocessed input, calling from sage.all import *
early in the program code. The number of text preparation system supporting Python
is larger than than the number of systems supporting Sage
directly ; I am thinking of knitr
, rmarkdown
and derived systems, aiming at supporting R
but able to support Python.
It could be worthy to look for such tools for processing Jupyter notebooks : there exists an not-so-small cottage industry of Jupyter extensions, some of them aiming at extending its markdown
abilities...
I'm pretty certain that other tools, text formats and supported code languages are available somewhere on the 'Net ; what I mentioned is what I tried with at least some success. FWIW, I have used LaTeX for 35 years, but the limitations of PDF-only output made me look at other solutions ; it turns out that my current personal favorite is org-mode
, probably because I have been an emacs
user for 35 years...
HTH,
Welcome to Ask Sage! Thank you for your question.