Ask Your Question

Revision history [back]

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.

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 *))