Ask Your Question

File -> Download as LaTeX

asked 2018-07-17 20:37:48 +0200

danielvolinski gravatar image

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.


edit retag flag offensive close merge delete


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

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2018-07-18 07:51:39 +0200 )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.

slelievre gravatar imageslelievre ( 2018-07-18 13:41:51 +0200 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2018-07-18 14:47:48 +0200

Iguananaut gravatar image

updated 2018-07-24 11:04:14 +0200

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

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

    def _repr_latex_(self):
        return self.latex

pi = Latex(r'$$ \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 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

edit flag offensive delete link 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....).

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2018-07-18 17:56:31 +0200 )edit

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

eric_g gravatar imageeric_g ( 2018-07-24 18:52:53 +0200 )edit

answered 2018-07-18 08:01:06 +0200

Emmanuel Charpentier gravatar image

updated 2018-07-18 08:03:59 +0200

That's not a question, that's a rant. But this is not

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

edit flag offensive delete link more



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.

danielvolinski gravatar imagedanielvolinski ( 2018-07-19 09:01:01 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-07-17 20:37:48 +0200

Seen: 1,710 times

Last updated: Jul 24 '18