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

Can 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?I forgot to write

`sage:`

....