Opened 7 months ago
Closed 3 months ago
#32942 closed enhancement (fixed)
Introduce `align_latex` option that allows latex displays aligned left or centered
Reported by: | klee | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-9.6 |
Component: | notebook | Keywords: | |
Cc: | egourgoulhon | Merged in: | |
Authors: | Kwankyu Lee | Reviewers: | Eric Gourgoulhon |
Report Upstream: | N/A | Work issues: | |
Branch: | 3427da0 (Commits, GitHub, GitLab) | Commit: | 3427da09ec598d8b4284a250c2d077d3bef941cf |
Dependencies: | #33475 | Stopgaps: |
Description (last modified by )
This
%display latex dm = get_display_manager() dm.preferences.align_latex = 'left' # or 'center' or None (1+x)^10/(1+x+x^2)
displays the expression flush left, which is the new default.
Motivated by ticket:32859#comment:32.
Change History (31)
comment:1 Changed 7 months ago by
- Dependencies set to u/klee/32942
comment:2 Changed 7 months ago by
- Branch set to u/klee/32942
- Commit set to 6ef43a0eba5a86a8ad33932bb0cfe89924b3f525
- Dependencies u/klee/32942 deleted
comment:3 Changed 7 months ago by
- Description modified (diff)
- Status changed from new to needs_review
comment:4 Changed 7 months ago by
- Description modified (diff)
comment:5 Changed 7 months ago by
- Commit changed from 6ef43a0eba5a86a8ad33932bb0cfe89924b3f525 to 5ebf3e552eaa9b095a0a66e34f5915c3baf91136
Branch pushed to git repo; I updated commit sha1. New commits:
5ebf3e5 | Fix doctest failures
|
comment:6 Changed 7 months ago by
- Description modified (diff)
comment:7 Changed 7 months ago by
- Cc egourgoulhon added
comment:8 Changed 7 months ago by
- Description modified (diff)
comment:9 Changed 7 months ago by
- Description modified (diff)
comment:10 Changed 7 months ago by
- Commit changed from 5ebf3e552eaa9b095a0a66e34f5915c3baf91136 to 4fbbeb76b4d2830e02326caa2c31917b2eb89245
comment:11 Changed 6 months ago by
- Milestone changed from sage-9.5 to sage-9.6
comment:12 follow-up: ↓ 13 Changed 4 months ago by
Sorry for the delay in reviewing!
A few comments:
- the option name
display_latex
sounds a little too vague and also may - introduce some confusion with the magic%display latex
. Wouldn'talign_latex
be a better name? - I've tested the new feature with Jupyterlab 3.3 (cf. #32069), it works well!
- Regarding Jupyter (classic), LaTeX outputs are always left-aligned for me (on two distinct Ubuntu 20.04 computers), as discussed at ticket:32859#comment:16 and setting
dm.preferences.display_latex = 'center'
does not change this... - Shouldn't
'left'
be the default, instead of'center'
? Left-align is the default for SymPy MathJax display in a pure Python 3 notebook and I see no reason to deviate from SymPy policy here. It also better (more readable) for short outputs, like0
.
comment:13 in reply to: ↑ 12 ; follow-up: ↓ 14 Changed 4 months ago by
Replying to egourgoulhon:
A few comments:
- the option name
display_latex
sounds a little too vague and also may - introduce some confusion with the magic%display latex
. Wouldn'talign_latex
be a better name?
I agree.
- Regarding Jupyter (classic), LaTeX outputs are always left-aligned for me (on two distinct Ubuntu 20.04 computers), as discussed at ticket:32859#comment:16 and setting
dm.preferences.display_latex = 'center'
does not change this...
"left" alignment is forced in the classic notebook. It seems developers decided so. Hence align_latex
is only for jupyterlab.
- Shouldn't
'left'
be the default, instead of'center'
? Left-align is the default for SymPy MathJax display in a pure Python 3 notebook and I see no reason to deviate from SymPy policy here. It also better (more readable) for short outputs, like0
.
I personally agree. But since "center" alignment has been de facto default in jupyterlab, and "left" alignment is expensive in that the additional code `\displaystyle" is inserted in every output cell, I am not sure if changing the default is a right thing... If you strongly insist, then I would follow. Do you?
comment:14 in reply to: ↑ 13 ; follow-up: ↓ 17 Changed 4 months ago by
Replying to klee:
- Shouldn't
'left'
be the default, instead of'center'
? Left-align is the default for SymPy MathJax display in a pure Python 3 notebook and I see no reason to deviate from SymPy policy here. It also better (more readable) for short outputs, like0
.I personally agree. But since "center" alignment has been de facto default in jupyterlab,
What do you mean by "de facto default"? I have the impression that, on the contrary, Jupyterlab's default is left-aligned, see e.g. the discussion LaTeX display math in output cells should be left-aligned on Jupyterlab github. For instance, in Jupyterlab with Python 3 kernel, the following cells all result in a left-aligned output:
import sympy sympy.sqrt(2)
from IPython.display import Latex Latex(r"$\sqrt{2+x}$")
Latex(r"$$\sqrt{2+x}$$")
Latex(r"\[\sqrt{2+x}\]")
Latex(r"\begin{equation}\sqrt{2+x}\end{equation}")
and "left" alignment is expensive in that the additional code `\displaystyle" is inserted in every output cell
Yes this is (one more!) drawback of our "%display latex" magic; instead of relying on Jupyter's native latex display...
I am not sure if changing the default is a right thing... If you strongly insist, then I would follow. Do you?
Despite the \displaystyle burden, I would vote in favor on the left-aligned default, for compatibility both with the display in Sage classic Jupyter and with the default for SymPy and Latex in Jupyterlab. It seems also that users prefer left-aligned, cf. https://ask.sagemath.org/question/59775/. Shall we organize a vote on sage-devel?
comment:15 Changed 4 months ago by
- Commit changed from 4fbbeb76b4d2830e02326caa2c31917b2eb89245 to 45e530a346e6b16d7dbf81c22b569ff46686a1d1
comment:16 Changed 4 months ago by
- Description modified (diff)
comment:17 in reply to: ↑ 14 ; follow-up: ↓ 19 Changed 4 months ago by
Replying to egourgoulhon:
Replying to klee:
- Shouldn't
'left'
be the default, instead of'center'
? Left-align is the default for SymPy MathJax display in a pure Python 3 notebook and I see no reason to deviate from SymPy policy here. It also better (more readable) for short outputs, like0
.I personally agree. But since "center" alignment has been de facto default in jupyterlab,
What do you mean by "de facto default"?
I meant center alignment is status quo, and is what users got used to in jupyterlab (including myself).
I have the impression that, on the contrary, Jupyterlab's default is left-aligned, see e.g. the discussion LaTeX display math in output cells should be left-aligned on Jupyterlab github. For instance, in Jupyterlab with Python 3 kernel, the following cells all result in a left-aligned output:
import sympy sympy.sqrt(2)from IPython.display import Latex Latex(r"$\sqrt{2+x}$")Latex(r"$$\sqrt{2+x}$$")Latex(r"\[\sqrt{2+x}\]")Latex(r"\begin{equation}\sqrt{2+x}\end{equation}")and "left" alignment is expensive in that the additional code `\displaystyle" is inserted in every output cell
Yes this is (one more!) drawback of our "%display latex" magic; instead of relying on Jupyter's native latex display...
I am not sure if changing the default is a right thing... If you strongly insist, then I would follow. Do you?
Despite the \displaystyle burden, I would vote in favor on the left-aligned default, for compatibility both with the display in Sage classic Jupyter and with the default for SymPy and Latex in Jupyterlab. It seems also that users prefer left-aligned, cf. https://ask.sagemath.org/question/59775/. Shall we organize a vote on sage-devel?
I agree. The current default center alignment may be regarded as a defect. No vote in fixing a defect. But perhaps we need to advertise (in release tour?) how to change the behavior for those users that do not like the new default.
comment:18 Changed 4 months ago by
- Summary changed from Introduce `display_latex` option that allows latex displays aligned left to Introduce `align_latex` option that allows latex displays aligned left or centered
comment:19 in reply to: ↑ 17 ; follow-up: ↓ 21 Changed 4 months ago by
Replying to klee:
I agree. The current default center alignment may be regarded as a defect. No vote in fixing a defect. But perhaps we need to advertise (in release tour?) how to change the behavior for those users that do not like the new default.
OK. Thanks for the changes.
There are 2 doctests failures in src/sage/misc/html.py
.
comment:20 Changed 4 months ago by
- Dependencies set to #33475
comment:21 in reply to: ↑ 19 Changed 4 months ago by
Replying to egourgoulhon:
There are 2 doctests failures in
src/sage/misc/html.py
.
Fixed. Thanks
I preemptively solved merge conflicts with already positively reviewed #33475, by adding it as dependency.
comment:22 Changed 4 months ago by
- Commit changed from 45e530a346e6b16d7dbf81c22b569ff46686a1d1 to 74e26967a878d845b97ece4183f731decfd81e60
Branch pushed to git repo; I updated commit sha1. New commits:
ecac525 | Fix two doctest failures
|
f3d3fda | deTeX documentation title
|
528ef65 | Use new commands \SL and \PSL
|
9187bf1 | Fix a glitch
|
eff36ec | Fix another glitch
|
fe4811c | Fix doctest failures
|
7285ad3 | Fix more doctest failures
|
11ed990 | Speed up macro parsing
|
7da2b5f | Fix an error in removing $
|
74e2696 | Merge branch 'trac33475'
|
comment:23 Changed 4 months ago by
- Description modified (diff)
comment:24 Changed 4 months ago by
- Description modified (diff)
comment:25 follow-up: ↓ 26 Changed 4 months ago by
- Reviewers set to Eric Gourgoulhon
- Status changed from needs_review to needs_work
The following notebook cell
%display latex x
yields
\displaystylex
The argument of \displaystyle
should be wrapped into curly brackets.
comment:26 in reply to: ↑ 25 Changed 4 months ago by
Replying to egourgoulhon:
The following notebook cell
%display latex xyields
\displaystylexIn
src/sage/misc/html.py
, the argument of\displaystyle
should be wrapped into curly brackets.
\displaystyle
does not take an argument. I put a space after \displaystyle
to prevent it from being combined with the following string. I am running doctesting.
comment:27 Changed 4 months ago by
- Commit changed from 74e26967a878d845b97ece4183f731decfd81e60 to 3427da09ec598d8b4284a250c2d077d3bef941cf
Branch pushed to git repo; I updated commit sha1. New commits:
3427da0 | Put a space after \displaystyle
|
comment:28 Changed 4 months ago by
- Status changed from needs_work to needs_review
comment:29 Changed 4 months ago by
- Status changed from needs_review to positive_review
Looks good. I've tested the latest version on various notebooks, both with Jupyter and Jupyterlab. Thanks!
comment:30 Changed 4 months ago by
Thank you!
I will announce this change on sage-devel.
comment:31 Changed 3 months ago by
- Branch changed from u/klee/32942 to 3427da09ec598d8b4284a250c2d077d3bef941cf
- Resolution set to fixed
- Status changed from positive_review to closed
New commits:
Introduce display_latex preference