ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 12 May 2020 05:42:33 -0500An error using unicode?https://ask.sagemath.org/question/51384/an-error-using-unicode/ Following the short answer of "Automatic substitution of unicode characters", the following code works nicely
%display unicode_art
π = var('pi')
solu=solve(π^2 - π==0, π)
solu
But if this code works nicely too
var("w0, pi, D, I")
A = matrix(SR, 2, 2, [[w0, 1],[w0-pi,1]])
y = vector([w0-D, w0-D-pi+I])
sol=A.solve_right(y)
%display unicode_art
sola=sol[0].full_simplify().function(D, pi, I, w0)
solb=sol[1].full_simplify().function(D, pi, I, w0)
f(x, D, π, I, w0)=sola*x + solb
f(x, D, π, I, w0)
The use of unicode on the preceding code generates an error
%display unicode_art
π = var('pi')
var("w0, π, D, I")
A = matrix(SR, 2, 2, [[w0, 1],[w0-π,1]])
y = vector([w0-D, w0-D-π+I])
sol=A.solve_right(y)
sola=sol[0].full_simplify().function(D, π, I, w0)
solb=sol[1].full_simplify().function(D, π, I, w0)
f(x, D, π, I, w0)=sola*x + solb
CyrilleTue, 12 May 2020 05:42:33 -0500https://ask.sagemath.org/question/51384/Pb with unicode characterhttps://ask.sagemath.org/question/50931/pb-with-unicode-character/ The following code works perfectly
var("w0, pi, D, I")
A = matrix(SR, 2, 2, [[w0, 1],[w0-pi,1]])
y = vector([w0-D, w0-D-pi+I])
sol=A.solve_right(y)
sola=sol[0].full_simplify().function(D, pi, I, w0)
solb=sol[1].full_simplify().function(D, pi, I, w0)
f(x, D, pi, I, w0)=sola*x + solb
show("f(x, D, pi, I, w0)=", f(x, D, pi, I, w0))
But if I use \pi <TAB> in replacement of pi, there is a Macsyma error
CyrilleWed, 22 Apr 2020 16:03:10 -0500https://ask.sagemath.org/question/50931/Should I avoid using unicode in names of variables?https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/ Hello, Sage community!
Since Sage now supports Python 3, the possibility of using tildes and other unicode letters in names of variables is real. For example, I could define a constant `Gauß` instead of `Gauss` (with a "ß" instead of "ss"); or I could define a function called `Müller` (with two dots over the "u"). In Spanish and other languages, this is a more pressing matter. If I defined a function `design(howMany)`, in Spanish it would be `diseño(cuántos)`.
However, it seems quite strange to have tildes, betas, etc. in variable names. Is it a good programming behavior to avoid this kind of names?, or, should I use them sparely?
Thanks in advance!dsejasSat, 04 Jan 2020 19:23:51 -0600https://ask.sagemath.org/question/49370/unicode codinghttps://ask.sagemath.org/question/49080/unicode-coding/```
# -*- coding = UTF-8 -*-
```
does not work ?
Big thanksJingenblThu, 19 Dec 2019 03:35:23 -0600https://ask.sagemath.org/question/49080/SageTeX UnicodeDecodeErrorhttps://ask.sagemath.org/question/45985/sagetex-unicodedecodeerror/Hello, Sage community.
I've been writing a book with the help of SageTeX. Until yesterday, I was working with SageMath v8.6, and everything work perfectly. Today I downloaded SageMath v8.7 binary for Linux, and replaced the corresponding SageTeX files. But when I tried to compile the book, suddenly I receive an error message:
> Traceback (most recent call last):
>
> File "book.sagetex.sage.py", line 5158, in <module>
>
> `_st_.endofdoc()`
>
> File "/SageMath/local/lib/python2.7/site-packages/sagetex.py", line 276, in endofdoc
>
> m.update(bytearray(line,'utf8'))
>
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 29: ordinal not in range(128)
The only difference from yesterday is the new version of SageMath. Can somebody explain/help me with this matter?
Thanks in advance for your answers!dsejasTue, 02 Apr 2019 06:03:58 -0500https://ask.sagemath.org/question/45985/UnicodeDecodeError in matplotlib if 'python' set instead of 'sage' in Notebookhttps://ask.sagemath.org/question/37364/unicodedecodeerror-in-matplotlib-if-python-set-instead-of-sage-in-notebook/Hello!
I am trying to make publication ready images for LaTeX in Sage with matplotlib (due to the complex nature of the plot) in Notebook.
I have a lot of numerical calculations (not symbolic) so I switch to 'python-mode' using drop-down list on top of the Worksheet (so it looks like 'File...', 'Action...', 'Data...', 'python') so that my constants would read as native python's data types not Sage's symbolic objects.
Now having the switch on top of the page in 'python' mode the following code:
from matplotlib import rc
rc('text', usetex=True)
rc('text.latex', unicode=True)
rc('text.latex', preamble='\usepackage[utf8]{inputenc}')
rc('text.latex', preamble='\usepackage[russian]{babel}')
font = {'family': 'serif',
'serif': ['Computer Modern Unicode']}
rc('font', **font)
import matplotlib.pyplot as plt
plt.plot([1], [1])
plt.title(ur'Тест')
plt.savefig("test.png")
yields ether UnicodeDecodeError or the image with the text corrupted:
![example of the corrupted output](/upfiles/14928022812226123.png)
But if I switch to 'sage' on top of the page, it works as expected:
![example of the valid output](/upfiles/14928023491980951.png)
I have no idea how that switch on top of the page affects matplotlib's output, but would really like to be able to use Cyrillic (utf8) letters and 'python' mode **at the same time**.
P.S. That magical switch on top of the page is really painful since I also can not save Worksheets if they contain utf-8 characters: [as in this still unresolved issue](https://ask.sagemath.org/question/26167/unicodedecodeerror-in-notebook-server-if-worksheet-is-set-to-python-instead-of-sage/) :-( :-(
**UPDATE:** Tested the MWE above in Jupiter - seems to work properly! And due to inevitable migration to Jupiter, the problem seems not to be obsolete.EugeneFri, 21 Apr 2017 14:24:54 -0500https://ask.sagemath.org/question/37364/Is there a way to use non english symbols?https://ask.sagemath.org/question/34071/is-there-a-way-to-use-non-english-symbols/ I try a simple command:
Graph({'Б':[1,2]}).plot().save("/tmp/plot.png")
but it fails:
/usr/lib/sagemath/local/lib/python2.7/site-packages/matplotlib-1.5.1-py2.7-linux-x86_64.egg/matplotlib/text.py in set_text(self, s)
1204 ACCEPTS: string or anything printable with '%s' conversion.
1205 """
-> 1206 self._text = '%s' % (s,)
1207 self.stale = True
1208
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)
How can I draw a graph with not only english symbols?Sergey PashininTue, 12 Jul 2016 06:20:04 -0500https://ask.sagemath.org/question/34071/Is it possible to use unicode letters in tag-nameshttps://ask.sagemath.org/question/33541/is-it-possible-to-use-unicode-letters-in-tag-names/ Im trying to create a tag tree using Icelandic characters like í á ú þ æ ý ð etc. But it is not allowed.
I've tried setting
ALLOW_UNICODE_SLUGS = True
but it does not seem to have any effect on this.ebergmundurTue, 24 May 2016 13:24:51 -0500https://ask.sagemath.org/question/33541/character encodinghttps://ask.sagemath.org/question/26556/character-encoding/ How can I chgange characte encoding in Sage notebook. I'm hungarian, and in string I need characterd like á, ő, ű, etc, but not \xc3, \xc5 and so on.czsanThu, 16 Apr 2015 03:57:45 -0500https://ask.sagemath.org/question/26556/UnicodeDecodeError in Notebook Server if Worksheet is set to 'python' instead of 'sage'https://ask.sagemath.org/question/26167/unicodedecodeerror-in-notebook-server-if-worksheet-is-set-to-python-instead-of-sage/Hello!
I have a worksheet with non-ascii characters in the source code (utf-8 comments). If I have 'sage' selected in the combo-box on top of the worksheet then "Save worksheet to a file" works well. But if I change this to 'python' than calling "Save worksheet to a file" leads to a UnicodeDecodeError:
'ascii' codec can't decode byte 0xd0 in position 6: ordinal not in range(128)
Traceback (most recent call last):
File "/home/sage/sage-6.5/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/sage/sage-6.5/local/lib/python2.7/site-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/sage/sage-6.5/local/lib/python2.7/site-packages/sagenb-0.11.4-py2.7.egg/sagenb/flask_version/decorators.py", line 22, in wrapper
return f(*args, **kwds)
File "/home/sage/sage-6.5/local/lib/python2.7/site-packages/sagenb-0.11.4-py2.7.egg/sagenb/flask_version/worksheet.py", line 48, in wrapper
return f(username, id, **kwds)
File "/home/sage/sage-6.5/local/lib/python2.7/site-packages/sagenb-0.11.4-py2.7.egg/sagenb/flask_version/worksheet.py", line 137, in wrapper
return f(*args, **kwds)
File "/home/sage/sage-6.5/local/lib/python2.7/site-packages/sagenb-0.11.4-py2.7.egg/sagenb/flask_version/worksheet.py", line 938, in worksheet_download
return unconditional_download(worksheet, title)
File "/home/sage/sage-6.5/local/lib/python2.7/site-packages/sagenb-0.11.4-py2.7.egg/sagenb/flask_version/worksheet.py", line 950, in unconditional_download
g.notebook.export_worksheet(worksheet.filename(), filename, title)
File "/home/sage/sage-6.5/local/lib/python2.7/site-packages/sagenb-0.11.4-py2.7.egg/sagenb/notebook/notebook.py", line 748, in export_worksheet
S.export_worksheet(username, id_number, output_filename, title=title)
File "/home/sage/sage-6.5/local/lib/python2.7/site-packages/sagenb-0.11.4-py2.7.egg/sagenb/storage/filesystem_storage.py", line 491, in export_worksheet
f.write(old_heading + g.read())
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 6: ordinal not in range(128)PetrThu, 12 Mar 2015 07:02:07 -0500https://ask.sagemath.org/question/26167/How to convert renpy python code into renpy python script?https://ask.sagemath.org/question/10410/how-to-convert-renpy-python-code-into-renpy-python-script/Is there anyone can help? I'm studying renpy programming now. N one thiong I cannot figure out is how can we change a renpy python code (RPYC) to Renpy python script (RPY)? The things I would like change is the symbols language i RPYC files actually.
I'll very appreciate the person who can help me solve this.
Thank you :)nami101Sun, 11 Aug 2013 17:54:12 -0500https://ask.sagemath.org/question/10410/Sage + Latex - How to change a font for axes label?https://ask.sagemath.org/question/10210/sage-latex-how-to-change-a-font-for-axes-label/I use [Sage][1] and LaTeX and when I do this:
\begin{sagesilent}
p2 = list_plot(zip(H, f(5)), True, color='blue', axes_labels=[u'$H,$ ??',u'$\mu, c$'])
p2.fontsize(14)
\end{sagesilent}
and run `sage DIPLOM.sagetex.sage` I get this:
/usr/lib/sagemath/local/lib/python2.7/site-packages/matplotlib/mathtext.py:887: MathTextWarning: Font 'default' does not have a glyph for '\u043a' [U43a]
MathTextWarning)
So how can I change a font name to use not only latin symbols?
PS: Even here these symbols are displayed as "??". Can't this site handle unicode?
[1]: http://www.sagemath.org/spokSun, 09 Jun 2013 00:09:43 -0500https://ask.sagemath.org/question/10210/unicode in sage terminalhttps://ask.sagemath.org/question/10066/unicode-in-sage-terminal/Hello
when I type
sage: "ä"
'\xc3\xa4' #latin1
sage: u"ä"
u'\xe4' #utf-8
I was actually hoping to display the actual character ä.
I'm aware of issues [#13296](http://trac.sagemath.org/sage_trac/ticket/13296) and [patch 1176c4b](https://github.com/sagemath/sagecell/commit/1176c4b210d83715ac26a67014d926aa9cfcd179)
I have sage 5.8 installed through ubuntu 12.04 repository
Still though I can't seem to print a german umlaut 'ä' neither in a sage terminal nor in a notebook
Anyone has the same problem in sage 5.8?Moataz ElmasryFri, 26 Apr 2013 05:02:58 -0500https://ask.sagemath.org/question/10066/PolynomialRing and from __future__ import unicode_literalshttps://ask.sagemath.org/question/9367/polynomialring-and-from-__future__-import-unicode_literals/Hello
sage: from __future__ import unicode_literals
sage: R=PolynomialRing(QQ,'x')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/moky/script/<ipython console> in <module>()
/home/moky/Sage/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_ring_constructor.pyc in PolynomialRing(base_ring, arg1, arg2, sparse, order, names, name, implementation)
425 if R is None:
426 raise TypeError("invalid input (%s, %s, %s) to PolynomialRing function; please see the docstring for that function"%(
--> 427 base_ring, arg1, arg2))
428
429 return R
TypeError: invalid input (Rational Field, x, None) to PolynomialRing function; please see the docstring for that function
I guess this is the same kind of problem that the one in [this question](http://ask.sagemath.org/question/840/from-__future__-import-unicode_literals-and)
By the way, this is "fixed" by using `str` :
sage: R=PolynomialRing(QQ,str('x'))
sage: f=R.lagrange_polynomial([(0,1),(1,4)]);f
3*x + 1
Laurent ClaessensSat, 29 Sep 2012 04:09:05 -0500https://ask.sagemath.org/question/9367/Why Sage can not plot Chinese labelhttps://ask.sagemath.org/question/9109/why-sage-can-not-plot-chinese-label/ I know that Matplotlib does not support UTF-8 without some change in matplotlibrc,So I edit the matplotlibrc and now when plot with matplotlib in sagenb,it supports UTF-8 now and it can show Chinese now.<br>
But for the sage plot function, when I want to set label with some Chinese characters,it raise exception :<br>
UnicodeEncodeError: 'ascii' codec can't encode character u'\u6211' in position 0: ordinal not in range(128).<br>
After I set the default encoding to UTF-8 in site.py,this exception does not raise again,but the Chinese characters are shown as box like [].
Below is my code:
p1=plot(sin,(-2*pi,2*pi),thickness=2.0,rgbcolor=(0.5,1,0),legend_label='sin(x)')
p2=plot(cos,(-2*pi,2*pi),thickness=3.0,color='purple',alpha=0.5,legend_label='cos(x)')
plt=p1+p2
x = u'\xd6\xd0\xb9\xfa\xc8\xcb'
plt.axes_labels((x,'y'))
show(plt)
Is there any solution?
I am sorry, it seems that this web site does not support Chinese, so I change the x shahuwangSun, 24 Jun 2012 21:53:57 -0500https://ask.sagemath.org/question/9109/Unicode Warninghttps://ask.sagemath.org/question/8389/unicode-warning/Sage 4.8 binary distibution runs but gives a message
"/local/lib/python2.6/site-packages/distribute-0.6.16-py2.6.egg/pkg_resources.py:2322: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal"
czsanFri, 27 Jan 2012 09:38:49 -0600https://ask.sagemath.org/question/8389/from __future__ import unicode_literals and variable nameshttps://ask.sagemath.org/question/8410/from-__future__-import-unicode_literals-and-variable-names/ Hello
It seems that making
from __future__ import unicode_literals
create some strange behaviour in Sage :
sage: from __future__ import unicode_literals
sage: x=var('x')
sage: f(x)=x**2 #ok
sage: f(3)
9
sage: f(x=3) # Not ok at all
u'x'^2
While it works when I force the argument of `var` to be `str`:
sage: y=var(str('y'))
sage: f(y)=y**2
sage: f(3) #ok
9
sage: f(y=3) #ok again
9
Should I forget about unicode_literals or open a ticket agains the `var` function which should convert its argument into a `str` ?
Thanks for advises
Laurent
Laurent ClaessensSun, 23 Oct 2011 23:50:00 -0500https://ask.sagemath.org/question/8410/unicode in doc stringshttps://ask.sagemath.org/question/8249/unicode-in-doc-strings/Hi!
Is it possible to use utf-8 characters in doc-strings? I tried to write description to __init__ method in russian language:
class Bazz:
def __init__(self):
"""
? ? ? ? ?
"""
pass
but then I write "Bazz(" and press tab:
> Traceback (most recent call last):
> File "", line 1, in File
> "_sage_input_66.py", line 10, in exec
> compile(u'print
> _support_.docstring("Bazz", globals(), system="sage")' + '\n', '', 'single')
> File "", line 1, in File
> "/opt/sage/devel/sagenb/sagenb/misc/support.py",
> line 263, in docstring return
> html_markup(s) File
> "/opt/sage/devel/sagenb/sagenb/misc/support.py",
> line 288, in html_markup return '
>
> ' + preamble + '
>
> ' + s + '
>
> ' UnicodeDecodeError: 'ascii' codec
> can't decode byte 0xd0 in position 11:
> ordinal not in range(128)
P.S. After I posted this question, site relapsed russian characters in code with '?' :-\EugeneSat, 30 Jul 2011 06:53:58 -0500https://ask.sagemath.org/question/8249/