# Issues with LaTeX generated by emacs-jupyter for Symbolics.jl expressions

**URL:** https://discourse.julialang.org/t/issues-with-latex-generated-by-emacs-jupyter-for-symbolics-jl-expressions/95584
**Category:** Jupyter-Notebook
**Tags:** jupyter, emacs, latex, symbolics
**Created:** [March 5, 2023, 7:23pm UTC](https://discourse.julialang.org/t/issues-with-latex-generated-by-emacs-jupyter-for-symbolics-jl-expressions/95584 "2023-03-05T19:23:12Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![a6a3uh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/a6a3uh/32/33773_2.png) [@a6a3uh](https://discourse.julialang.org/u/a6a3uh)
#### Post date: [March 5, 2023, 7:23pm UTC](https://discourse.julialang.org/t/issues-with-latex-generated-by-emacs-jupyter-for-symbolics-jl-expressions/95584/1 "2023-03-05T19:23:12Z")

</div>

This might be a really rare combination of techniques.  
I’m using `Emacs` with `org-mode`’s `org-babel` to write code blocks. And I’m using `emacs-jupyter` to connect to `Jupyter`’s `Julia` kernel.  
When working with `Symbolics.jl` it prints pretty latex in output. In order to see it rendered in my `ORG` document I’m choosing `:results raw` header arguments.

It works fine until I have multiline latex output. Latex get’s wrapped with `$$`. I suspect emacs-jupyer doing that but not sure where that is happening.  
Whats worse it also wraps output with some additional [stuff](https://github.com/nnicandro/emacs-jupyter/blob/eebeef1293287075f65d27f5442bb151bf27d92a/jupyter-org-client.el#L1051):

```julia
\\begin{minipage}{\\textwidth}
\\begin{flushright}\n" data "\n\\end{flushright}
\\end{minipage}")

```

Eventually what I get in my output is something like this:

```julia
\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}

```

Which can’t be rendered properly. If there where no `$$` stuff in generated output everything renders fine.

In `jupyter-repl` there are also issues with rendering multi-line expressions from `Symbolics.jl`. That’s why I’m suspecting `Symbolics.jl` in this behavior as well. And it seems the issue again connected to these extra `$$` stuff.

I have a little hope someone uses same combination of technologies and ran into same issues. And I’m not sure who is responsible for extra `$$` which breaks normal rendering (whether `emacs-jupyer` responsible for that or `Symbolics.jl`).

---

<div class="post-metadata">

### Author: ![a6a3uh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/a6a3uh/32/33773_2.png) [@a6a3uh](https://discourse.julialang.org/u/a6a3uh)
#### Post date: [March 5, 2023, 7:27pm UTC](https://discourse.julialang.org/t/issues-with-latex-generated-by-emacs-jupyter-for-symbolics-jl-expressions/95584/2 "2023-03-05T19:27:30Z")

</div>

I also should add that `SymPy.jl` output get’s rendered correctly at the same time with my org-babel code blocks output. And that makes me think that’s `Symbolics.jl`’s fault. But I have tested on different code with different expressions. So that might be not conclusive.

And also I’ve tried same `Symbolics.jl` code in `Jupyter` notebook and `Pluto.jl` notebook and everything renders fine which makes me believe the issue is with `emacs-jupyter`.

---

<div class="post-metadata">

### Author: ![a6a3uh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/a6a3uh/32/33773_2.png) [@a6a3uh](https://discourse.julialang.org/u/a6a3uh)
#### Post date: [March 5, 2023, 7:39pm UTC](https://discourse.julialang.org/t/issues-with-latex-generated-by-emacs-jupyter-for-symbolics-jl-expressions/95584/3 "2023-03-05T19:39:48Z")

</div>

Posted an [issue](https://github.com/nnicandro/emacs-jupyter/issues/440) in `emacs-jupyter` as my main suspect for that issue.

---

<div class="post-metadata">

### Author: ![a6a3uh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/a6a3uh/32/33773_2.png) [@a6a3uh](https://discourse.julialang.org/u/a6a3uh)
#### Post date: [March 7, 2023, 5:18pm UTC](https://discourse.julialang.org/t/issues-with-latex-generated-by-emacs-jupyter-for-symbolics-jl-expressions/95584/4 "2023-03-07T17:18:04Z")

</div>

Eventually the issue seems to be connected to Symbolics.jl. There are some comments in [pull request](https://github.com/JuliaSymbolics/Symbolics.jl/pull/763) describing that issue and one workaround: call `Symbolics.set_default(env=:raw)`. It works for me well.

There are some attemts to fix issue in emacs as provided in this [issue](https://github.com/nnicandro/emacs-jupyter/issues/295) from emacs-jupyer repo. But that didn;t worked for me for some reason.
