Ask Your Question
1

Print Latex Normally?

asked 2018-07-12 12:05:01 +0200

o6p gravatar image

updated 2018-07-12 20:08:20 +0200

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}

edit retag flag offensive close merge delete

Comments

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.

Iguananaut gravatar imageIguananaut ( 2018-07-12 13:33:37 +0200 )edit
1

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

slelievre gravatar imageslelievre ( 2018-07-12 20:12:41 +0200 )edit
1

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

John Palmieri gravatar imageJohn Palmieri ( 2018-07-12 20:14:36 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-07-12 13:54:28 +0200

Iguananaut gravatar image

%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}
edit flag offensive delete link more

Comments

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

Iguananaut gravatar imageIguananaut ( 2018-07-12 14:08:58 +0200 )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

o6p gravatar imageo6p ( 2018-07-12 14:49:16 +0200 )edit

Yes, 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...

Iguananaut gravatar imageIguananaut ( 2018-07-12 20:19:25 +0200 )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.

John Palmieri gravatar imageJohn Palmieri ( 2018-07-12 20:41:00 +0200 )edit

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: 2018-07-12 12:05:01 +0200

Seen: 1,984 times

Last updated: Jul 12 '18