# I can't show special characters

Hi everyone! Thank you in advance for your time. I'm working in Ubuntu 18.04 and Sagemath 8.1. I want to show a string with special characters, like accents. I don't have problems with printing something like "á" in my Jupyter notebook, but when I use show, I get something like this

PGh0bWw+PHNjcmlwdCB0eXBlPSJtYXRoL3RleDsgbW9kZT1kaXNwbGF5Ij5cbmV3Y29tbWFuZHtcQm9sZH1bMV17XG1hdGhiZnsjMX19XHZlcmJ8w6F8PC9zY3JpcHQ+PC9odG1sPg==

How can I fix this? If somebody could help me, I'll appreciate that too much.

edit retag close merge delete

1

Please provide a very precise example of what you do.

( 2019-09-29 14:53:55 -0500 )edit

Sort by » oldest newest most voted

For show(<string>) the code executed is basically show(latex(<string>)).

If you want to work with non-ascii characters, you should go for unicode. In Python3 that's going to be the default. At the moment we're still on Python2, so you should do something like

S= u'á'


If you do that, then you'll see that show(S) gives you an error. If you define

T='á'


then show(T) basically "silently" fails: the non-ascii character gets inserted into a TeX typesetting routine that is currently not capable of handling non-ascii characters. There are variants of TeX (specifically XeTeX) that are unicode-capable, but that's not what is currently used in sage.

The normal LaTeX way of typesetting a word like "rápido" would be as "r\'apido", but that doesn't seem to be supported in the notebook either.

I think it would be entirely reasonable to open a feature-request to let "show" support non-ascii (and particularly accented) characters.

more

I can reproduce the issue, this is probably because of some wrong handling of unicode in Python 2. Indeed, if you compile Sage with Python 3 support (or if you wait until Python 3 becomes the default), it works correctly.

more

1

Of note: on a python3-based Sage, this works correctly in a Jupyter notebook. In a terminal, |show displays the LaTeX command necessary to print the string.

But in a sage-shell-mode buffer wit inline-typesetting enabled this fails:

sage: S="à"
sage: show(S)
[ Snip...]
/home/charpent/.emacs.d/elpa/sage-shell-mode-20180215.835/emacs_sage_shell_view.py in displayhook(self, plain_text, rich_output)
55         elif isinstance(rich_output, OutputLatex):
56             text = "" + plain_text.text.get() + ""
58             return ({u'text/plain': text}, {})
59         else:

TypeError: can only concatenate str (not "bytes") to str


This is now issue 45 in sage-shell-mode`

( 2019-09-29 17:09:44 -0500 )edit