Ask Your Question
2

%display latex makes output centered (in exported tex file)

asked 2021-11-17 00:09:42 +0200

jakupl gravatar image

updated 2021-11-17 17:13:00 +0200

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-11-18 01:16:51 +0200

jakupl gravatar image

updated 2021-11-21 23:52:22 +0200

Ok 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
sage-9.4/local/lib/python3.9/site-packages/nbconvert/templates/latex/document_contents.tplx
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 *))
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-11-17 00:09:42 +0200

Seen: 192 times

Last updated: Nov 21 '21