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, 12 Jul 2018 20:41:00 +0200Print Latex Normally?https://ask.sagemath.org/question/42944/print-latex-normally/Hi. When I use `%display latex` I don't really see Latex I want to see.
For example:
%display latex
integrate(x^2,x)
OUT: \newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{3} \, x^{3}
Isn't `newcommand` completely extra here? How would I go on about getting latex output that doesn't include `\newcommand`?
Ideally, I would want to see the following latex output: `\frac{x^{3}}{3}`Thu, 12 Jul 2018 12:05:01 +0200https://ask.sagemath.org/question/42944/print-latex-normally/Comment by Iguananaut for <p>Hi. When I use <code>%display latex</code> I don't really see Latex I want to see.
For example:</p>
<pre><code>%display latex
integrate(x^2,x)
OUT: \newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{3} \, x^{3}
</code></pre>
<p>Isn't <code>newcommand</code> completely extra here? How would I go on about getting latex output that doesn't include <code>\newcommand</code>?</p>
<p>Ideally, I would want to see the following latex output: <code>\frac{x^{3}}{3}</code></p>
https://ask.sagemath.org/question/42944/print-latex-normally/?comment=42949#post-id-42949The formatting of your post is a bit confusing because it's not clear where the line breaks are. If you want to have pre-formatted multi-line text, don't use backticks since that is only for inline formatting. Instead, indent the full text by 4 spaces (you can do this automatically by selecting all the lines and pressing `Ctrl-K`.Thu, 12 Jul 2018 13:33:37 +0200https://ask.sagemath.org/question/42944/print-latex-normally/?comment=42949#post-id-42949Comment by slelievre for <p>Hi. When I use <code>%display latex</code> I don't really see Latex I want to see.
For example:</p>
<pre><code>%display latex
integrate(x^2,x)
OUT: \newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{3} \, x^{3}
</code></pre>
<p>Isn't <code>newcommand</code> completely extra here? How would I go on about getting latex output that doesn't include <code>\newcommand</code>?</p>
<p>Ideally, I would want to see the following latex output: <code>\frac{x^{3}}{3}</code></p>
https://ask.sagemath.org/question/42944/print-latex-normally/?comment=42982#post-id-42982Please indicate if you are working in the Sage REPL, in the Jupyter Notebook, in the SageNB notebook, in the sage-mode for Emacs...Thu, 12 Jul 2018 20:12:41 +0200https://ask.sagemath.org/question/42944/print-latex-normally/?comment=42982#post-id-42982Comment by John Palmieri for <p>Hi. When I use <code>%display latex</code> I don't really see Latex I want to see.
For example:</p>
<pre><code>%display latex
integrate(x^2,x)
OUT: \newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{3} \, x^{3}
</code></pre>
<p>Isn't <code>newcommand</code> completely extra here? How would I go on about getting latex output that doesn't include <code>\newcommand</code>?</p>
<p>Ideally, I would want to see the following latex output: <code>\frac{x^{3}}{3}</code></p>
https://ask.sagemath.org/question/42944/print-latex-normally/?comment=42985#post-id-42985Are you using the Sage jupyter notebook, the old Sage notebook, Sage's command-line interface, or CoCalc?Thu, 12 Jul 2018 20:14:36 +0200https://ask.sagemath.org/question/42944/print-latex-normally/?comment=42985#post-id-42985Answer by Iguananaut for <p>Hi. When I use <code>%display latex</code> I don't really see Latex I want to see.
For example:</p>
<pre><code>%display latex
integrate(x^2,x)
OUT: \newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{3} \, x^{3}
</code></pre>
<p>Isn't <code>newcommand</code> completely extra here? How would I go on about getting latex output that doesn't include <code>\newcommand</code>?</p>
<p>Ideally, I would want to see the following latex output: <code>\frac{x^{3}}{3}</code></p>
https://ask.sagemath.org/question/42944/print-latex-normally/?answer=42950#post-id-42950`%display latex` I think is intended more for use in the notebook, where the latex would actually be rendered. I'm not sure why so much of the latex display output includes the `\newcommand{\Bold}` definition--seems like a historical artifact and I'm not sure if it's still necessary. But if you just want the plain latex formatting for some output you can do:
sage: latex(integrate(x^2,x))
\frac{1}{3} \, x^{3}
Thu, 12 Jul 2018 13:54:28 +0200https://ask.sagemath.org/question/42944/print-latex-normally/?answer=42950#post-id-42950Comment by Iguananaut for <p><code>%display latex</code> I think is intended more for use in the notebook, where the latex would actually be rendered. I'm not sure why so much of the latex display output includes the <code>\newcommand{\Bold}</code> definition--seems like a historical artifact and I'm not sure if it's still necessary. But if you just want the plain latex formatting for some output you can do:</p>
<pre><code>sage: latex(integrate(x^2,x))
\frac{1}{3} \, x^{3}
</code></pre>
https://ask.sagemath.org/question/42944/print-latex-normally/?comment=42953#post-id-42953The `\newcommand{\Bold}` stuff dates back quite some time, apparently, and is explained here: http://doc.sagemath.org/html/en/reference/misc/sage/misc/latex_macros.html I do think it's a bit excessive. There's no need for it to be added to every latex-formatted output if it's for defining commands that are not even used...Thu, 12 Jul 2018 14:08:58 +0200https://ask.sagemath.org/question/42944/print-latex-normally/?comment=42953#post-id-42953Comment by o6p for <p><code>%display latex</code> I think is intended more for use in the notebook, where the latex would actually be rendered. I'm not sure why so much of the latex display output includes the <code>\newcommand{\Bold}</code> definition--seems like a historical artifact and I'm not sure if it's still necessary. But if you just want the plain latex formatting for some output you can do:</p>
<pre><code>sage: latex(integrate(x^2,x))
\frac{1}{3} \, x^{3}
</code></pre>
https://ask.sagemath.org/question/42944/print-latex-normally/?comment=42958#post-id-42958latex(input) does indeed work, thanks. Is there no way to latexify output without manually wrapping the sage code in latex()? I think this works well, but I'd much rather prefer the %display latex approachThu, 12 Jul 2018 14:49:16 +0200https://ask.sagemath.org/question/42944/print-latex-normally/?comment=42958#post-id-42958Comment by Iguananaut for <p><code>%display latex</code> I think is intended more for use in the notebook, where the latex would actually be rendered. I'm not sure why so much of the latex display output includes the <code>\newcommand{\Bold}</code> definition--seems like a historical artifact and I'm not sure if it's still necessary. But if you just want the plain latex formatting for some output you can do:</p>
<pre><code>sage: latex(integrate(x^2,x))
\frac{1}{3} \, x^{3}
</code></pre>
https://ask.sagemath.org/question/42944/print-latex-normally/?comment=42986#post-id-42986Yes, but you'll wind back up with the same problem that it prepends `\newcommand{\Bold}` everywhere. Sometimes this is necessary because some objects' latex representations require that. But I think that's a bit of a bug. It shouldn't be output at all if the `\Bold` command is not actually being used. And even if it is, the `\newcommand` declaration should be included, at least optionally, only as part of some preamble that would go into your latex file or a style. In fact, you can get such a thing with `sage.misc.latex.latex_extra_preamble()`. Then do `import sage.misc.latex_macros; del sage.misc.latex_macros.sage_configurable_latex_macros[:]` and it will shut up forever about `\newcommand{\Bold}` :) This is not ideal though; there should be a better way...Thu, 12 Jul 2018 20:19:25 +0200https://ask.sagemath.org/question/42944/print-latex-normally/?comment=42986#post-id-42986Comment by John Palmieri for <p><code>%display latex</code> I think is intended more for use in the notebook, where the latex would actually be rendered. I'm not sure why so much of the latex display output includes the <code>\newcommand{\Bold}</code> definition--seems like a historical artifact and I'm not sure if it's still necessary. But if you just want the plain latex formatting for some output you can do:</p>
<pre><code>sage: latex(integrate(x^2,x))
\frac{1}{3} \, x^{3}
</code></pre>
https://ask.sagemath.org/question/42944/print-latex-normally/?comment=42989#post-id-42989As you said in your answer, `%display latex` is supposed to render the latex, so any preamble parts will not print. So it may be a bug to include this command where not needed, but it's a minor bug since it's not supposed to print. One alternative is to parse the latex to see which parts of the preamble are needed and only include those, but that could get complicated. Feel free to implement it if you want. Perhaps a better alternative, if we knew in which context `%display latex` was actually just printing the latex code rather than rendering it, would be to change it to print the value of `latex(input)`, without the preamble.Thu, 12 Jul 2018 20:41:00 +0200https://ask.sagemath.org/question/42944/print-latex-normally/?comment=42989#post-id-42989