ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 03 Jan 2022 02:25:30 +0100formatting an output as a numbered equationhttps://ask.sagemath.org/question/60505/formatting-an-output-as-a-numbered-equation/ Hi there,
As by now and after googling for some time I didn't manage to find a option on how to format my dagemath outpiuts as numbered equation.
Consider this very basic example:
a=randint(-100,100)
b=randint(-100,100)
c=randint(-100,100)
s=solve(a*x^2+b*x+c==0,x)
ex1=latex(r"\noindent Consider this equation : ")
ex2='$$'+latex(a*x^2 + b*x +c ==0) +'$$'
ex3=latex("Solution : ")
ex4='$$'+latex(s)+'$$'
ex1 + ex2 + ex3 +ex4
I just need the equation to be included in an "equation" environment. One can see from my print that I'm at the very beginning stage in learning.
Thx in advance for the help.
Sat, 01 Jan 2022 14:47:22 +0100https://ask.sagemath.org/question/60505/formatting-an-output-as-a-numbered-equation/Comment by slelievre for <p>Hi there,
As by now and after googling for some time I didn't manage to find a option on how to format my dagemath outpiuts as numbered equation.
Consider this very basic example:</p>
<pre><code>a=randint(-100,100)
b=randint(-100,100)
c=randint(-100,100)
s=solve(a*x^2+b*x+c==0,x)
ex1=latex(r"\noindent Consider this equation : ")
ex2='$$'+latex(a*x^2 + b*x +c ==0) +'$$'
ex3=latex("Solution : ")
ex4='$$'+latex(s)+'$$'
ex1 + ex2 + ex3 +ex4
</code></pre>
<p>I just need the equation to be included in an "equation" environment. One can see from my print that I'm at the very beginning stage in learning.
Thx in advance for the help.</p>
https://ask.sagemath.org/question/60505/formatting-an-output-as-a-numbered-equation/?comment=60510#post-id-60510Welcome to Ask Sage! Thank you for your question.Sun, 02 Jan 2022 05:37:47 +0100https://ask.sagemath.org/question/60505/formatting-an-output-as-a-numbered-equation/?comment=60510#post-id-60510Answer by Emmanuel Charpentier for <p>Hi there,
As by now and after googling for some time I didn't manage to find a option on how to format my dagemath outpiuts as numbered equation.
Consider this very basic example:</p>
<pre><code>a=randint(-100,100)
b=randint(-100,100)
c=randint(-100,100)
s=solve(a*x^2+b*x+c==0,x)
ex1=latex(r"\noindent Consider this equation : ")
ex2='$$'+latex(a*x^2 + b*x +c ==0) +'$$'
ex3=latex("Solution : ")
ex4='$$'+latex(s)+'$$'
ex1 + ex2 + ex3 +ex4
</code></pre>
<p>I just need the equation to be included in an "equation" environment. One can see from my print that I'm at the very beginning stage in learning.
Thx in advance for the help.</p>
https://ask.sagemath.org/question/60505/formatting-an-output-as-a-numbered-equation/?answer=60512#post-id-60512Equation 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](https://doc.sagemath.org/html/en/tutorial/sagetex.html), 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](https://github.com/gpoore/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`](https://pandoc.org/), 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`](https://github.com/gpoore/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`](https://orgmode.org/)'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,Sun, 02 Jan 2022 11:49:41 +0100https://ask.sagemath.org/question/60505/formatting-an-output-as-a-numbered-equation/?answer=60512#post-id-60512Comment by slelievre for <p>Equation numbering (and, more generally, (cross-)references management) is <em>not</em> in the scope of Sage.</p>
<p>What you are looking for is a <strong>document preparation system</strong> able to include and manage Sage inputs, outputs and references to them.</p>
<p>One solution is Sage's <a href="https://doc.sagemath.org/html/en/tutorial/sagetex.html">SageTeX</a>, 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.</p>
<p>I have also had some success with <a href="https://github.com/gpoore/pythontex">PythonTeX</a>, which allows for the use of several languages (notably including <code>R</code>) the same way.</p>
<p>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...) :</p>
<ul>
<li><p>One possibility is to prepare LaTeX files and convert them to your desired output, for example with <a href="https://pandoc.org/"><code>pandoc</code></a>, which as an astonishing range of output formats.</p></li>
<li><p>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 :</p>
<ul>
<li><p><a href="https://github.com/gpoore/codebraid"><code>codebraid</code></a>, which uses <code>markdown</code> for text input and <code>pandoc</code> as the processor ; supports a handful of programming languages (including <code>R</code>), generates anything <code>pandoc</code> can generate ;</p></li>
<li><p><a href="https://orgmode.org/"><code>org-mode</code></a>'s <code>babel</code> 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 <code>pandoc</code> in some cases) ; interestingly, this tool is a package of the (remarkable) <code>emacs</code> text editor, which might be considered as a bug or as a feature, according to your taste...</p></li>
</ul></li>
<li><p>A third possibility is to use a system supporting <code>Python</code>code and feeding it <em>preprocessed</em> input, calling <code>from sage.all import *</code> early in the program code. The number of text preparation system supporting <code>Python</code> is larger than than the number of systems supporting <code>Sage</code> directly ; I am thinking of <code>knitr</code>, <code>rmarkdown</code> and derived systems, aiming at supporting <code>R</code> but able to support Python.</p></li>
<li><p>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 <code>markdown</code> abilities...</p></li>
</ul>
<p>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 <code>org-mode</code>, probably because I have been an <code>emacs</code> user for 35 years...</p>
<p>HTH,</p>
https://ask.sagemath.org/question/60505/formatting-an-output-as-a-numbered-equation/?comment=60523#post-id-60523In addition to SageTeX, pythonTeX and TeXmacs, there is also
- [texsurgery](https://framagit.org/pang/texsurgery)Mon, 03 Jan 2022 02:25:30 +0100https://ask.sagemath.org/question/60505/formatting-an-output-as-a-numbered-equation/?comment=60523#post-id-60523Comment by cav_rt for <p>Equation numbering (and, more generally, (cross-)references management) is <em>not</em> in the scope of Sage.</p>
<p>What you are looking for is a <strong>document preparation system</strong> able to include and manage Sage inputs, outputs and references to them.</p>
<p>One solution is Sage's <a href="https://doc.sagemath.org/html/en/tutorial/sagetex.html">SageTeX</a>, 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.</p>
<p>I have also had some success with <a href="https://github.com/gpoore/pythontex">PythonTeX</a>, which allows for the use of several languages (notably including <code>R</code>) the same way.</p>
<p>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...) :</p>
<ul>
<li><p>One possibility is to prepare LaTeX files and convert them to your desired output, for example with <a href="https://pandoc.org/"><code>pandoc</code></a>, which as an astonishing range of output formats.</p></li>
<li><p>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 :</p>
<ul>
<li><p><a href="https://github.com/gpoore/codebraid"><code>codebraid</code></a>, which uses <code>markdown</code> for text input and <code>pandoc</code> as the processor ; supports a handful of programming languages (including <code>R</code>), generates anything <code>pandoc</code> can generate ;</p></li>
<li><p><a href="https://orgmode.org/"><code>org-mode</code></a>'s <code>babel</code> 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 <code>pandoc</code> in some cases) ; interestingly, this tool is a package of the (remarkable) <code>emacs</code> text editor, which might be considered as a bug or as a feature, according to your taste...</p></li>
</ul></li>
<li><p>A third possibility is to use a system supporting <code>Python</code>code and feeding it <em>preprocessed</em> input, calling <code>from sage.all import *</code> early in the program code. The number of text preparation system supporting <code>Python</code> is larger than than the number of systems supporting <code>Sage</code> directly ; I am thinking of <code>knitr</code>, <code>rmarkdown</code> and derived systems, aiming at supporting <code>R</code> but able to support Python.</p></li>
<li><p>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 <code>markdown</code> abilities...</p></li>
</ul>
<p>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 <code>org-mode</code>, probably because I have been an <code>emacs</code> user for 35 years...</p>
<p>HTH,</p>
https://ask.sagemath.org/question/60505/formatting-an-output-as-a-numbered-equation/?comment=60518#post-id-60518Very nice and informative answer!
There is also the [GNU Texmacs](http://www.texmacs.org/tmweb/home/welcome.en.html). It can run sage, R, python, maxima and a bunch of other CAS integrated in an interesting WYSIWYG text format. I don't know exactly why, but it is a very underestimated software.Sun, 02 Jan 2022 19:56:05 +0100https://ask.sagemath.org/question/60505/formatting-an-output-as-a-numbered-equation/?comment=60518#post-id-60518