Replying to myself. Somehow a rerun on this worked (weird). However,
the output is 7.099e-27, not 7.099 \times 10$^{-27}$.On Mar 3, 11:03 am, sm123123 <[email protected]> wrote: > :) > > I tried the \percent macro. > > I got: > > File "problemset.py", line 39 > _st_.inline(_sage_const_1 , latex(''%_sage_const_12p 3e"%lnm1)) > ^ > SyntaxError: invalid token > > where lnm1 is a variable defined in a \begin{sagesilent} ... > \end{sagesilent} environment. > > On Mar 3, 3:19 am, Dan Drake <[email protected]> wrote: > > > > > On Wed, 02 Mar 2011 at 07:34PM -0800, sm123123 wrote: > > > I tried using the format specs in SageTeX: > > > > \newcommand{\sagenum}[1]{\sage{''temp1=#1;%12.3e"%temp1}} > > > > This fails to compile as "%" is the comment character in LaTeX. > > > > If I escape it with a backslash (as is customary in LaTeX), Sage > > > chokes on the code. > > > > Catch 22. > > > There are three ways to avoid the catch-22. The first involves buying > > eggs for 22 cents and making a profit by selling them for 19 cents...or > > whatever it was. (It's been a while since I've read the book...) > > > The other two ways: > > > 1. SageTeX provides the \percent macro which puts a % into the Sage code > > without confusing TeX. > > > 2. You can use "new style" string > > formatting:http://docs.python.org/library/string.html#formatstrings > > > That doesn't use any percent signs (at least, I don't think it does for > > your use-cases). > > > NOte that your \sagenum won't work, since executing multiple statements > > separated by a semicolon isn't supported. Try > > > \newcommand{\sagenum}[1]{\sage{"\percent12.3e"\percent #1}} > > > which wraps the output in \texttt (since that's what Sage's latex() does > > to strings). If you want the plain output put into your file, try > > \sagestr instead of \sage. > > > Dan > > > -- > > --- Dan Drake > > ----- http://mathsci.kaist.ac.kr/~drake > > ------- > > > signature.asc > > < 1KViewDownload -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
