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

Fix MIME"text/latex" output to ensure it's in a TeX environment #763

Merged
merged 1 commit into from
Oct 15, 2022

Conversation

ChrisRackauckas
Copy link
Member

See the discussion in fonsp/Pluto.jl#488 and JuliaStrings/LaTeXStrings.jl#50 and fonsp/Pluto.jl#1164. IIUC, @stevengj makes the argument that no MIME"text/latex" output can be assumed to be a single LaTeX statement, which is reasonable, and the natural consequence of that is that no display environment using MIME"text/latex" should assume that the output is a single expression and put $$ x $$ for you. And if that's the case, it's the job the displayer to output properly formatted TeX with the display environments defined. That is sensible, and we just need to make sure that Symbolics and ModelingToolkit does that everywhere.

See the discussion in fonsp/Pluto.jl#488 and JuliaStrings/LaTeXStrings.jl#50 and fonsp/Pluto.jl#1164. IIUC, @stevengj makes the argument that no `MIME"text/latex"` output can be assumed to be a single LaTeX statement, which is reasonable, and the natural consequence of that is that no display environment using `MIME"text/latex"` should assume that the output is a single expression and put `$$ x $$` for you. And if that's the case, it's the job the displayer to output properly formatted TeX with the display environments defined. That is sensible, and we just need to make sure that Symbolics and ModelingToolkit does that everywhere.
@codecov-commenter
Copy link

codecov-commenter commented Oct 15, 2022

Codecov Report

Merging #763 (9db4342) into master (6cf49a4) will decrease coverage by 0.43%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master     #763      +/-   ##
==========================================
- Coverage   76.85%   76.42%   -0.44%     
==========================================
  Files          25       25              
  Lines        3180     3177       -3     
==========================================
- Hits         2444     2428      -16     
- Misses        736      749      +13     
Impacted Files Coverage Δ
src/latexify_recipes.jl 56.11% <0.00%> (-0.72%) ⬇️
src/array-lib.jl 78.08% <0.00%> (-2.47%) ⬇️
src/wrapper-types.jl 77.50% <0.00%> (-1.25%) ⬇️
src/solver.jl 82.59% <0.00%> (-0.59%) ⬇️
src/build_function.jl 74.41% <0.00%> (-0.59%) ⬇️
src/semipoly.jl 90.86% <0.00%> (-0.44%) ⬇️
src/arrays.jl 77.90% <0.00%> (-0.37%) ⬇️
src/utils.jl 78.94% <0.00%> (-0.16%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@ChrisRackauckas ChrisRackauckas merged commit 2388acd into master Oct 15, 2022
@ChrisRackauckas ChrisRackauckas deleted the ChrisRackauckas-patch-1 branch October 15, 2022 18:25
@akirakyle
Copy link

This change seems to have broken latexify of symbolics expressions in emacs-jupyter and I can't seem to figure out why this change was made even after reading though the linked issues. Before this change everything rendered fine in emacs-jupyter with the environment given in the recipe (which appears to be the equation environment for everything in symbolics). Now the environments are wrapped in the double dollar signs by default which won't render in emacs org-mode. Explicitly, after this change, this looks something like

#+begin_src jupyter-julia
@variables p a
#+end_src

#+RESULTS:
:RESULTS:
$$ \begin{equation}
\left[
\begin{array}{c}
p \\
a \\
\end{array}
\right]
\end{equation}
 $$
:END:

For now it seems possible to work around it by using set_default(env=:raw)

I tried to figure out how this is handled in pluto so that I could do something similar in emacs-jupyter, but couldn't see anything like env=:raw being set.

@a6a3uh
Copy link

a6a3uh commented Mar 6, 2023

For now it seems possible to work around it by using set_default(env=:raw)

Could you pls clarify where this set_default(env=:raw) should be executed?

@akirakyle
Copy link

set_default(env=:raw) should be executed in the julia environment. Note that I suspect (given my limited understanding of Julia's I/O) that this may cause issues with the display of other datatypes. I haven't extensively tested it though.

@a6a3uh
Copy link

a6a3uh commented Mar 11, 2023

set_default(env=:raw) should be executed in the julia environment.

In my case it does not get rid off these double dollar stuff.

For example:
Before:

\begin{minipage}{\textwidth}
\begin{flushright}
$$ \begin{equation}
\left[
\begin{array}{c}
t_2 + v_{{1}} \lambda^{x}_{{1}} + \left( \lambda^{v}_{{1}} + \mu^{a}_{{1}} \right) \left( \lambda^{v}_{{1}} + \mu^{a}_{{1}} - a\left( t \right) \right) \\
 - t_2 - v_{{2}} \lambda^{x}_{{2}} - \left( \lambda^{v}_{{2}} + \mu^{a}_{{2}} \right) \left( \lambda^{v}_{{2}} + \mu^{a}_{{2}} - a\left( t \right) \right) \\
\end{array}
\right]
\end{equation}
 $$
\end{flushright}
\end{minipage}

After:

\begin{minipage}{\textwidth}
\begin{flushright}
$$ \left[
\begin{array}{c}
t_2 + v_{{1}} \lambda^{x}_{{1}} + \left( \lambda^{v}_{{1}} + \mu^{a}_{{1}} \right) \left( \lambda^{v}_{{1}} + \mu^{a}_{{1}} - a\left( t \right) \right) \\
 - t_2 - v_{{2}} \lambda^{x}_{{2}} - \left( \lambda^{v}_{{2}} + \mu^{a}_{{2}} \right) \left( \lambda^{v}_{{2}} + \mu^{a}_{{2}} - a\left( t \right) \right) \\
\end{array}
\right] $$
\end{flushright}
\end{minipage}

It rather removed equation thing and that makes it renders properly in latex fragment of org-mode (which is great). But still there are issues with rendered latex in jupyter-repl.

Perhaps suggestion from this emacs-jupyter issue discussion could help here. But I didn't managed it to work for me yet.

@sebeaumont
Copy link

I've applied a couple of workarounds as suggested -- but I think $$ x $$ is not the right way to do this (as far as TeX gurus comment on it). It would appear that MathJax copes with this but certainly org-latex does not so I wonder what is correct here.

@wgmitchener
Copy link

wgmitchener commented Aug 22, 2024

I'm seeing something similar when running Julia in a Jupyter notebook either using Jupyter lab or VS Code. If I save a notebook as LaTeX, the output from a Symbolics calculation has extra dollars, as in
$$ \begin{equation} ...
So it's not just emacs.

@ChrisRackauckas
Copy link
Member Author

I'll go with whatever @fonsp and @stevengj suggest as the right format.

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

Successfully merging this pull request may close these issues.

6 participants