# 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}



Ideally, I would want to see the following latex output: \frac{x^{3}}{3}

edit retag close merge delete

1

The 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.

( 2018-07-12 06:33:37 -0600 )edit

Please indicate if you are working in the Sage REPL, in the Jupyter Notebook, in the SageNB notebook, in the sage-mode for Emacs...

( 2018-07-12 13:12:41 -0600 )edit

Are you using the Sage jupyter notebook, the old Sage notebook, Sage's command-line interface, or CoCalc?

( 2018-07-12 13:14:36 -0600 )edit

Sort by » oldest newest most voted

%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}

more

The \newcommand{\Bold}stuff dates back quite some time, apparently, and is explained here: http://doc.sagemath.org/html/en/refer... 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...

( 2018-07-12 07:08:58 -0600 )edit

latex(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 approach

( 2018-07-12 07:49:16 -0600 )edit


( 2018-07-12 13:19:25 -0600 )edit

As 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.

( 2018-07-12 13:41:00 -0600 )edit

## Stats

Seen: 492 times

Last updated: Jul 12 '18