Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance OutputHtml rich output for better pdf rendering of Jupyter notebook #11362

Open
williamstein opened this issue May 20, 2011 · 34 comments

Comments

@williamstein
Copy link
Contributor

Previously this ticket was for repairing "show for Cayley tables as MathJax does not support setlength".

While fixing that based on the latest Sage develop branch, I needed to augment OutputHtml rich output with latex whenever possible.

With the branch, Cayley tables are rendered correctly in Jupyter notebook. Moreover, because of the patch for OutputHtml, the notebook is exported as pdf correctly.

Checkout the uploaded Jupyterbook and try to export it as pdf.

Please test the branch for possible unexpected side effects, though I guess there would be none.

Below is the previous description of the ticket:


Define a finite group and its multiplication table:

sage: S = SymmetricGroup(3)
sage: T = S.multiplication_table()

The multiplication table can give latex code
to be copy-pasted in a paper:

sage: latex(T)
\setlength{\arraycolsep}{2\ex}
\begin{array}{r|*{6}{r}}
\multicolumn{1}{c|}{\ast}&a&b&c&d&e&f\\\hline
{}a&a&b&c&d&e&f\\
{}b&b&a&d&c&f&e\\
{}c&c&e&a&f&b&d\\
{}d&d&f&b&e&a&c\\
{}e&e&c&f&a&d&b\\
{}f&f&d&e&b&c&a\\
\end{array}}

but is also used for showing the table in a notebook worksheet.

In Sage 4.8 with SageNB we used to have:

sage: show(T)
Unknown control sequence '\setlength'

In Sage 9.2.rc0 with Jupyter, show(T) does
display a table but with \setlength displayed
in red instead of contributing to the rendering.

CC: @slel @kwankyu

Component: notebook

Keywords: latex, jupyter, mathjax

Author: Kwankyu Lee

Branch/Commit: public/11362 @ f3ad938

Issue created by migration from https://trac.sagemath.org/ticket/11362

@rbeezer
Copy link
Mannequin

rbeezer mannequin commented May 20, 2011

comment:1

I thought this was on #10787, but now I see it is not. I'm going to point it here.

I've been waiting on MathJax before tackling this, on the hope it has better support for tables.

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@slel
Copy link
Member

slel commented Oct 14, 2020

Changed keywords from none to latex, jupyter, mathjax

@slel
Copy link
Member

slel commented Oct 14, 2020

comment:6

Still a problem in Jupyter Notebook with Sage 9.2.rc0.

@slel

This comment has been minimized.

@slel slel changed the title showing a Cayley table fails in the notebook due to bad latex code Repair show for Cayley tables as MathJax does not support setlength Oct 14, 2020
@slel slel modified the milestones: sage-6.4, sage-9.3 Oct 14, 2020
@DaveWitteMorris
Copy link
Member

Branch: public/11362

@DaveWitteMorris
Copy link
Member

comment:8

The PR adds a variable sage.misc.latex_macros.sage_configurable_mathjax_macros that holds a list of macro definitions that pretty_print will include in all LaTeX code that is sent to MathJax. The PR then solves the problem on this ticket by adding \multicolumn and \setlength to this list as no-ops that swallow their arguments.


New commits:

7381952trac 11362 configurable mathjax macros
71b0986update doctests

@DaveWitteMorris
Copy link
Member

Commit: 71b0986

@DaveWitteMorris
Copy link
Member

Author: Dave Morris

@kwankyu
Copy link
Collaborator

kwankyu commented Mar 19, 2021

comment:10

I don't like the proposed solution. It seems a bandage.

A general solution that would also solve possible future problems would be to introduce a new magic method obj.mathjax() which provides latex code renderable by mathjax and defaults to an alias of obj.latex() when it is not defined for obj.

@DaveWitteMorris
Copy link
Member

comment:11

I sympathize with what you are saying, and I considered that solution (except that my idea was to add a keyword (maybe style="MathJax") to the _latex_ command. But I don't see how to make it will work without massive changes, because an object that does not have a _mathjax_ method will presumably call the _latex_ method of its subobjects (or subexpressions) and will therefore not do the right thing for MathJax.

I think of MathJax as being a version of latex, rather than a completely different format, so I think it is reasonable to just add a tweak to make it work better (as in my PR). The variable I added simply makes it possible to add definitions for latex macros that MathJax does not understand, and is completely analogous to the variable sage_configurable_latex_macros that is already in sage, which makes it possible to add definitions for sage macros that vanilla latex does not understand.

@kwankyu
Copy link
Collaborator

kwankyu commented Mar 20, 2021

comment:12

How about using _rich_repr_? This seems a general mechanism to serve the purpose that I have in mind about _mathjax_. There are many examples in Sage src.

@kwankyu
Copy link
Collaborator

kwankyu commented Mar 21, 2021

comment:13

Replying to @DaveWitteMorris:

I sympathize with what you are saying, and I considered that solution (except that my idea was to add a keyword (maybe style="MathJax") to the _latex_ command. But I don't see how to make it will work without massive changes, because an object that does not have a _mathjax_ method will presumably call the _latex_ method of its subobjects (or subexpressions) and will therefore not do the right thing for MathJax.

I think of MathJax as being a version of latex, rather than a completely different format, ...

MathJax is a javascript renderer for latex in html, and also sometimes means the subset of latex it supports. On the other hand LaTeX is a format for TeX which primarily targets printing.

It seems to me currently there is some unfortunate confused code in this respect in the rich output system in Sage. Perhaps straightening the confused code would give a natural solution of this ticket's problem. I will investigate more.

@slel
Copy link
Member

slel commented Mar 22, 2021

comment:14

Related:

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 24, 2021

Changed commit from 71b0986 to 35130bd

@kwankyu
Copy link
Collaborator

kwankyu commented Aug 24, 2021

Changed author from Dave Morris to Kwankyu Lee

@kwankyu
Copy link
Collaborator

kwankyu commented Aug 24, 2021

Reviewer: Dave Morris

@kwankyu

This comment has been minimized.

@kwankyu kwankyu changed the title Repair show for Cayley tables as MathJax does not support setlength Enhance OutputHtml rich output for better pdf rendering of Jupyter notebook Aug 24, 2021
@kwankyu
Copy link
Collaborator

kwankyu commented Aug 24, 2021

Cayley table

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 24, 2021

comment:20

Attachment: trac11362.ipynb.gz

Branch pushed to git repo; I updated commit sha1. New commits:

a365cabAdd an doctest

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 24, 2021

Changed commit from 35130bd to a365cab

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 24, 2021

Changed commit from a365cab to e08369b

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 24, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

e08369bFix a typo

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 25, 2021

Changed commit from e08369b to 2a52283

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 25, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

2a52283Return valid html string

@kwankyu
Copy link
Collaborator

kwankyu commented Aug 25, 2021

Changed reviewer from Dave Morris to none

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 31, 2021

Changed commit from 2a52283 to b545134

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 31, 2021

Branch pushed to git repo; I updated commit sha1. New commits:

b545134Fix doctests

@mkoeppe
Copy link
Member

mkoeppe commented Dec 18, 2021

comment:25

Stalled in needs_review or needs_info; likely won't make it into Sage 9.5.

@mkoeppe mkoeppe modified the milestones: sage-9.5, sage-9.6 Dec 18, 2021
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 10, 2022

Changed commit from b545134 to f3ad938

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 10, 2022

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

f3ad938Augment OutputHtml with latex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants