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.Sun, 10 Feb 2019 14:12:53 +0100Piecewise in SageTeXhttps://ask.sagemath.org/question/45278/piecewise-in-sagetex/ Hi, am trying to use the "piecewise" command in SageTeX but i get an error no matter what i try. It is like the SageTeX doesnt know what "piecewise" means, like the command "piecewise" is not implemented in SageTeX.
I tried different ways of typing the piecewise command in sage terminal and it works fine.
sage: f=piecewise([[(-15,0),6],[(0,44),sqrt(-x^2+52*x+36)]])
and
sage: f=piecewise([((-15,0), 6), ([0,44], sqrt(-x^2+52*x+36))]); f
But when i do the same in sagetex and compile with
# sage filename.sagetex.sage
Then i get
Processing Sage code for modul-2.tex...
Sage commandline 0 (line 193)
Sage commandline 1 (line 200)
Sage commandline 2 (line 209)
/usr/lib/python2.7/site-packages/sagetex.py:209: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
DELETED LINK
result = eval(preparse(splitup[i][2]), globals, locals)
Sage commandline 3 (line 239)
Sage commandline 4 (line 246)
Sage commandline 5 (line 252)
/usr/lib/python2.7/site-packages/sagetex.py:218: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
DELETED LINK
exec(preparse(splitup[i][2]), globals, locals)
Sage commandline 6 (line 309)
Sage commandline 7 (line 315)
Sage commandline 8 (line 322)
Sage commandline 9 (line 496)
Sage commandline 10 (line 505)
Sage commandline 11 (line 520)
Sage commandline 12 (line 530)
Sage commandline 13 (line 538)
Sage commandline 14 (line 559)
**** Error in Sage code on line 561 of modul-2.tex! Traceback follows.
Traceback (most recent call last):
File "modul-2.sagetex.sage.py", line 119, in <module>
""", globals(), locals(), False)
File "/usr/lib/python2.7/site-packages/sagetex.py", line 196, in commandline
splitup = self.split_sage_cmds(s)
File "/usr/lib/python2.7/site-packages/sagetex.py", line 138, in split_sage_cmds
starts[0] = re.search(prompt, s).start()
AttributeError: 'NoneType' object has no attribute 'start'
**** Running Sage on modul-2.sage failed! Fix modul-2.tex and try again.
I tried inside env, sagecommandline and \sage{} and env. sageblock.
I didnt get error in sageblock but then when i tried to plot the function later i got the error anyways.
Can anyone help me from here? How can i define piecewise functions in SageTeX??Sun, 03 Feb 2019 01:17:24 +0100https://ask.sagemath.org/question/45278/piecewise-in-sagetex/Comment by dazedANDconfused for <p>Hi, am trying to use the "piecewise" command in SageTeX but i get an error no matter what i try. It is like the SageTeX doesnt know what "piecewise" means, like the command "piecewise" is not implemented in SageTeX. </p>
<p>I tried different ways of typing the piecewise command in sage terminal and it works fine. </p>
<pre><code>sage: f=piecewise([[(-15,0),6],[(0,44),sqrt(-x^2+52*x+36)]])
</code></pre>
<p>and</p>
<pre><code>sage: f=piecewise([((-15,0), 6), ([0,44], sqrt(-x^2+52*x+36))]); f
</code></pre>
<p>But when i do the same in sagetex and compile with </p>
<pre><code># sage filename.sagetex.sage
</code></pre>
<p>Then i get </p>
<pre><code>Processing Sage code for modul-2.tex...
Sage commandline 0 (line 193)
Sage commandline 1 (line 200)
Sage commandline 2 (line 209)
/usr/lib/python2.7/site-packages/sagetex.py:209: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
DELETED LINK
result = eval(preparse(splitup[i][2]), globals, locals)
Sage commandline 3 (line 239)
Sage commandline 4 (line 246)
Sage commandline 5 (line 252)
/usr/lib/python2.7/site-packages/sagetex.py:218: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
DELETED LINK
exec(preparse(splitup[i][2]), globals, locals)
Sage commandline 6 (line 309)
Sage commandline 7 (line 315)
Sage commandline 8 (line 322)
Sage commandline 9 (line 496)
Sage commandline 10 (line 505)
Sage commandline 11 (line 520)
Sage commandline 12 (line 530)
Sage commandline 13 (line 538)
Sage commandline 14 (line 559)
**** Error in Sage code on line 561 of modul-2.tex! Traceback follows.
Traceback (most recent call last):
File "modul-2.sagetex.sage.py", line 119, in <module>
""", globals(), locals(), False)
File "/usr/lib/python2.7/site-packages/sagetex.py", line 196, in commandline
splitup = self.split_sage_cmds(s)
File "/usr/lib/python2.7/site-packages/sagetex.py", line 138, in split_sage_cmds
starts[0] = re.search(prompt, s).start()
AttributeError: 'NoneType' object has no attribute 'start'
**** Running Sage on modul-2.sage failed! Fix modul-2.tex and try again.
</code></pre>
<p>I tried inside env, sagecommandline and \sage{} and env. sageblock.
I didnt get error in sageblock but then when i tried to plot the function later i got the error anyways.</p>
<p>Can anyone help me from here? How can i define piecewise functions in SageTeX??</p>
https://ask.sagemath.org/question/45278/piecewise-in-sagetex/?comment=45290#post-id-45290Can you post your LaTeX code? I have no trouble plotting the piecewise function you used with `sagetex`. Maybe I don't understand what you are attempting. Also, are you using Cocalc off the internet or is this compiled using Sage from your computer? If Sage from your computer, what version of Sage?Sun, 03 Feb 2019 17:06:26 +0100https://ask.sagemath.org/question/45278/piecewise-in-sagetex/?comment=45290#post-id-45290Comment by Martin MÃ¥rtensson for <p>Hi, am trying to use the "piecewise" command in SageTeX but i get an error no matter what i try. It is like the SageTeX doesnt know what "piecewise" means, like the command "piecewise" is not implemented in SageTeX. </p>
<p>I tried different ways of typing the piecewise command in sage terminal and it works fine. </p>
<pre><code>sage: f=piecewise([[(-15,0),6],[(0,44),sqrt(-x^2+52*x+36)]])
</code></pre>
<p>and</p>
<pre><code>sage: f=piecewise([((-15,0), 6), ([0,44], sqrt(-x^2+52*x+36))]); f
</code></pre>
<p>But when i do the same in sagetex and compile with </p>
<pre><code># sage filename.sagetex.sage
</code></pre>
<p>Then i get </p>
<pre><code>Processing Sage code for modul-2.tex...
Sage commandline 0 (line 193)
Sage commandline 1 (line 200)
Sage commandline 2 (line 209)
/usr/lib/python2.7/site-packages/sagetex.py:209: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
DELETED LINK
result = eval(preparse(splitup[i][2]), globals, locals)
Sage commandline 3 (line 239)
Sage commandline 4 (line 246)
Sage commandline 5 (line 252)
/usr/lib/python2.7/site-packages/sagetex.py:218: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
DELETED LINK
exec(preparse(splitup[i][2]), globals, locals)
Sage commandline 6 (line 309)
Sage commandline 7 (line 315)
Sage commandline 8 (line 322)
Sage commandline 9 (line 496)
Sage commandline 10 (line 505)
Sage commandline 11 (line 520)
Sage commandline 12 (line 530)
Sage commandline 13 (line 538)
Sage commandline 14 (line 559)
**** Error in Sage code on line 561 of modul-2.tex! Traceback follows.
Traceback (most recent call last):
File "modul-2.sagetex.sage.py", line 119, in <module>
""", globals(), locals(), False)
File "/usr/lib/python2.7/site-packages/sagetex.py", line 196, in commandline
splitup = self.split_sage_cmds(s)
File "/usr/lib/python2.7/site-packages/sagetex.py", line 138, in split_sage_cmds
starts[0] = re.search(prompt, s).start()
AttributeError: 'NoneType' object has no attribute 'start'
**** Running Sage on modul-2.sage failed! Fix modul-2.tex and try again.
</code></pre>
<p>I tried inside env, sagecommandline and \sage{} and env. sageblock.
I didnt get error in sageblock but then when i tried to plot the function later i got the error anyways.</p>
<p>Can anyone help me from here? How can i define piecewise functions in SageTeX??</p>
https://ask.sagemath.org/question/45278/piecewise-in-sagetex/?comment=45412#post-id-45412I forgot to write `sage:` ....Sun, 10 Feb 2019 14:12:53 +0100https://ask.sagemath.org/question/45278/piecewise-in-sagetex/?comment=45412#post-id-45412Answer by Emmanuel Charpentier for <p>Hi, am trying to use the "piecewise" command in SageTeX but i get an error no matter what i try. It is like the SageTeX doesnt know what "piecewise" means, like the command "piecewise" is not implemented in SageTeX. </p>
<p>I tried different ways of typing the piecewise command in sage terminal and it works fine. </p>
<pre><code>sage: f=piecewise([[(-15,0),6],[(0,44),sqrt(-x^2+52*x+36)]])
</code></pre>
<p>and</p>
<pre><code>sage: f=piecewise([((-15,0), 6), ([0,44], sqrt(-x^2+52*x+36))]); f
</code></pre>
<p>But when i do the same in sagetex and compile with </p>
<pre><code># sage filename.sagetex.sage
</code></pre>
<p>Then i get </p>
<pre><code>Processing Sage code for modul-2.tex...
Sage commandline 0 (line 193)
Sage commandline 1 (line 200)
Sage commandline 2 (line 209)
/usr/lib/python2.7/site-packages/sagetex.py:209: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
DELETED LINK
result = eval(preparse(splitup[i][2]), globals, locals)
Sage commandline 3 (line 239)
Sage commandline 4 (line 246)
Sage commandline 5 (line 252)
/usr/lib/python2.7/site-packages/sagetex.py:218: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
DELETED LINK
exec(preparse(splitup[i][2]), globals, locals)
Sage commandline 6 (line 309)
Sage commandline 7 (line 315)
Sage commandline 8 (line 322)
Sage commandline 9 (line 496)
Sage commandline 10 (line 505)
Sage commandline 11 (line 520)
Sage commandline 12 (line 530)
Sage commandline 13 (line 538)
Sage commandline 14 (line 559)
**** Error in Sage code on line 561 of modul-2.tex! Traceback follows.
Traceback (most recent call last):
File "modul-2.sagetex.sage.py", line 119, in <module>
""", globals(), locals(), False)
File "/usr/lib/python2.7/site-packages/sagetex.py", line 196, in commandline
splitup = self.split_sage_cmds(s)
File "/usr/lib/python2.7/site-packages/sagetex.py", line 138, in split_sage_cmds
starts[0] = re.search(prompt, s).start()
AttributeError: 'NoneType' object has no attribute 'start'
**** Running Sage on modul-2.sage failed! Fix modul-2.tex and try again.
</code></pre>
<p>I tried inside env, sagecommandline and \sage{} and env. sageblock.
I didnt get error in sageblock but then when i tried to plot the function later i got the error anyways.</p>
<p>Can anyone help me from here? How can i define piecewise functions in SageTeX??</p>
https://ask.sagemath.org/question/45278/piecewise-in-sagetex/?answer=45284#post-id-45284Somebody called `gh-JCGoran` seems to have stumbled on this already, and reported [Trac#27078](https://trac.sagemath.org/ticket/27078).
But the implementation isn't trivial.
I also note that the `sympy` representatin of this function is questionable...Sun, 03 Feb 2019 14:24:53 +0100https://ask.sagemath.org/question/45278/piecewise-in-sagetex/?answer=45284#post-id-45284Answer by Martin MÃ¥rtensson for <p>Hi, am trying to use the "piecewise" command in SageTeX but i get an error no matter what i try. It is like the SageTeX doesnt know what "piecewise" means, like the command "piecewise" is not implemented in SageTeX. </p>
<p>I tried different ways of typing the piecewise command in sage terminal and it works fine. </p>
<pre><code>sage: f=piecewise([[(-15,0),6],[(0,44),sqrt(-x^2+52*x+36)]])
</code></pre>
<p>and</p>
<pre><code>sage: f=piecewise([((-15,0), 6), ([0,44], sqrt(-x^2+52*x+36))]); f
</code></pre>
<p>But when i do the same in sagetex and compile with </p>
<pre><code># sage filename.sagetex.sage
</code></pre>
<p>Then i get </p>
<pre><code>Processing Sage code for modul-2.tex...
Sage commandline 0 (line 193)
Sage commandline 1 (line 200)
Sage commandline 2 (line 209)
/usr/lib/python2.7/site-packages/sagetex.py:209: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
DELETED LINK
result = eval(preparse(splitup[i][2]), globals, locals)
Sage commandline 3 (line 239)
Sage commandline 4 (line 246)
Sage commandline 5 (line 252)
/usr/lib/python2.7/site-packages/sagetex.py:218: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
DELETED LINK
exec(preparse(splitup[i][2]), globals, locals)
Sage commandline 6 (line 309)
Sage commandline 7 (line 315)
Sage commandline 8 (line 322)
Sage commandline 9 (line 496)
Sage commandline 10 (line 505)
Sage commandline 11 (line 520)
Sage commandline 12 (line 530)
Sage commandline 13 (line 538)
Sage commandline 14 (line 559)
**** Error in Sage code on line 561 of modul-2.tex! Traceback follows.
Traceback (most recent call last):
File "modul-2.sagetex.sage.py", line 119, in <module>
""", globals(), locals(), False)
File "/usr/lib/python2.7/site-packages/sagetex.py", line 196, in commandline
splitup = self.split_sage_cmds(s)
File "/usr/lib/python2.7/site-packages/sagetex.py", line 138, in split_sage_cmds
starts[0] = re.search(prompt, s).start()
AttributeError: 'NoneType' object has no attribute 'start'
**** Running Sage on modul-2.sage failed! Fix modul-2.tex and try again.
</code></pre>
<p>I tried inside env, sagecommandline and \sage{} and env. sageblock.
I didnt get error in sageblock but then when i tried to plot the function later i got the error anyways.</p>
<p>Can anyone help me from here? How can i define piecewise functions in SageTeX??</p>
https://ask.sagemath.org/question/45278/piecewise-in-sagetex/?answer=45411#post-id-45411I found out that i made a very silly mistake. I forgot to write
> sage:
Before miy command. I was very tired and had been looking myself blind on the code. I realized this when i started to try writing other command that usually work, and they didnt work (ofcause) then i copy pasted some old code that worked and i realized that `sage:` was missing............................. x-) stupid me, Sorry for the inconvenience. Sun, 10 Feb 2019 14:11:52 +0100https://ask.sagemath.org/question/45278/piecewise-in-sagetex/?answer=45411#post-id-45411