ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 18 Nov 2021 01:16:51 +0100%display latex makes output centered (in exported tex file)https://ask.sagemath.org/question/59775/display-latex-makes-output-centered-in-exported-tex-file/My headline sums it up.
I usually download my jupyter worksheet as latex and compile it for math assignments.
I recently upgraded to 9.4 (compiled from source), and suddenly all outputs are centered when %display latex is toggled. This doesn't happen when downloading as html.
Does anyone know how to put outputs back to the left, where they belong?
EDIT: After digging around, I have discovered that latex formatted output fields used to be wrapped in "\begin{math}" instead of $$. Here's an example.
It used to get exported like this:
```
\begin{math}
```
```
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{\pi}{3}
```
```
\end{math}
```
But since the last update, this has changed to:
```
$$\newcommand{\Bold}[1]{\mathbf{#1}}\frac{\pi}{3}$$
```
This change causes the output to be centered. Does anyone know how to get the math fields back when exporting to LaTeX?
SageMath version 9.4, Release Date: 2021-08-22
![image description](https://i.imgur.com/DndQsxj.png)Wed, 17 Nov 2021 00:09:42 +0100https://ask.sagemath.org/question/59775/display-latex-makes-output-centered-in-exported-tex-file/Answer by jakupl for <p>My headline sums it up.
I usually download my jupyter worksheet as latex and compile it for math assignments.</p>
<p>I recently upgraded to 9.4 (compiled from source), and suddenly all outputs are centered when %display latex is toggled. This doesn't happen when downloading as html.</p>
<p>Does anyone know how to put outputs back to the left, where they belong?</p>
<p>EDIT: After digging around, I have discovered that latex formatted output fields used to be wrapped in "\begin{math}" instead of $$. Here's an example. </p>
<p>It used to get exported like this:</p>
<p><code>
\begin{math}
</code></p>
<p><code>
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{\pi}{3}
</code></p>
<p><code>
\end{math}
</code></p>
<p>But since the last update, this has changed to:</p>
<p><code>
$$\newcommand{\Bold}[1]{\mathbf{#1}}\frac{\pi}{3}$$
</code>
This change causes the output to be centered. Does anyone know how to get the math fields back when exporting to LaTeX?</p>
<p>SageMath version 9.4, Release Date: 2021-08-22</p>
<p><img src="https://i.imgur.com/DndQsxj.png" alt="image description"></p>
https://ask.sagemath.org/question/59775/display-latex-makes-output-centered-in-exported-tex-file/?answer=59811#post-id-59811Ok after lots of digging, I actually came up with a hack, that fixes it. I have no idea if it breaks something else, but I haven't found any problems with it yet. Will post here if I find anything.
I opened the file <br> `sage-9.4/local/lib/python3.9/site-packages/nbconvert/templates/latex/document_contents.tplx` <br> and simply changed this:
% Display latex
((* block data_latex -*))
((( output.data['text/latex'] | strip_files_prefix )))
((* endblock data_latex *))
To this:
% Display latex
((* block data_latex -*))
\begin{math}
((( output.data['text/latex'] | strip_files_prefix )))
\end{math}
((* endblock data_latex *))
Now latex formatted outputs are in "double maths mode" like this:
\begin{math}
$$\newcommand{\Bold}[1]{\mathbf{#1}}\frac{\pi}{3}$$
\end{math}
If anyone knows how to get rid of the dollar signs, or actually knows of a better way to do this, please let me know.
EDIT:
I have now managed to remove the superfluous dollarsigns by adding strip_dollars to the filters. I still don't know if this might break something, but everything has been fine and dandy so far. Will report any issues, and I hope someone can benefit from this.
Here is the full edit:
% Display latex
((* block data_latex -*))
\begin{math}
((( output.data['text/latex'] | strip_files_prefix | strip_dollars )))
\end{math}
((* endblock data_latex *))Thu, 18 Nov 2021 01:16:51 +0100https://ask.sagemath.org/question/59775/display-latex-makes-output-centered-in-exported-tex-file/?answer=59811#post-id-59811