I'm using SageMath 8.2 on a Windows 10 Native with Jupyter Notebook.

The output file obtained by File -> Download as Latex is appalling!

All the output and input cells are placed in verbatim Latex constructs which prevents the usage of all the facilities provided by Latex. I understand why the input cells are in verbatim Latex constructs, after all you want to see exactly what the user wrote, but output cell should not be in verbatim Latex constructs.

The Greek characters are not used at all, even when variables have been defined including their Greek character.

All kind of arrows are printed |--> instead of taking advantage of the many arrows in Latex.

Long lines are just cut when the border is reached.

Exponentials are not shown properly, they appear with the ^ symbol.

The * character (multiplication) should not appear in results.

Daniel

edit retag close merge delete

Edit : comment promoted to answer, see below...

( 2018-07-18 00:51:39 -0600 )edit

Please provide a link to a Jupyter Notebook worksheet and the resulting .tex file. For example, you could do that using the "share" functionality in CoCalc.

( 2018-07-18 06:41:51 -0600 )edit

Sort by » oldest newest most voted

I agree with Emmanuel that this is not a question, though it is a valid issue. I would be helpful to at least see an example notebook.

That said I think I see what you're saying. Even if the notebook has %display latex set, when exporting the notebook to tex it wraps all code output blocks in verbatim, and containing the plain-text output rather than the latex output. If you put latex in a markdown cell it does get converted properly but only if you have pandoc installed. And it seems Sage does not include pandoc by default (perhaps it should, assuming there's no license conflict, etc.)

I confirmed that this isn't just an issue with Sage. You can also test this easily in a plain Python notebook, e.g. by defining a class with a _repr_latex_method (see https://ipython.readthedocs.io/en/sta...)

class Latex(object):
def __init__(self, latex):
self.latex = latex

def _repr_latex_(self):
return self.latex

pi = Latex(r'$$\pi$$')
pi


When I run this, it sees the _repr_latex_ and indeed renders the output cell as latex. However, when I run "Download as PDF" it just shows the default plain-text in a verbatim block, as you pointed out. I don't like that either, and it's either a bug, or there should at least be an option to control that.

The "Download as Latex" feature in the Jupyter is, well, a Jupyter-specific feature. It doesn't know anything about Sage, and I'm not sure if the necessary APIs exist in Jupyter to ensure that a code block containing latex-formatted output actually renders the latex when converting to a tex file. This would be an issue for https://github.com/jupyter/nbconvert A quick search of the open issues didn't reveal anything obviously related to me though.

As we move towards emphasizing Jupyter more, we should definitely improve the latex handling story there. Latex is very important for Sage, and in general handled better overall by the classic sage notebook (which you can still try using if it does improve certain tasks for you). This might be an issue to add to https://trac.sagemath.org/ticket/25837

more

Latex is very important for Sage, and in general handled better overall by the classing sage notebook

And even better by \LaTeX and SageTeX (or Pyhontex, which may be estimated as better-maintained....).

( 2018-07-18 10:56:31 -0600 )edit
1

See Trac #23330 for the "Download as PDF" issue and references there, especially this comment.

( 2018-07-24 11:52:53 -0600 )edit

That's not a question, that's a rant. But this is not https://rant.sagemath.org

Since you show neither :

• anything you process, nor

• any part of what you expected to get,

it's pretty hard to divine how you could get it : I'm still running Homo Sapiens L. V 1.0 (i. e. no telepathic interface)...

Would you consider putting down your input and your expected output and either ask a real question here or report a bug via sage-support ?

Hint : creating a \Latex file perusing Sagetex (or Pythontex) might get you results closer to what you seem to expect. A good tool for this is emacs + Sage shell mode

more

1

This is a list of bugs in SageMath regarding TeX. There is no need for an example, you can try it with your own files and get a similar result. The TeX and PDF output as it is today is not suitable to be presented in any academic forum.

( 2018-07-19 02:01:01 -0600 )edit