Ask Your Question

I can't show special characters

asked 2019-09-29 21:16:03 +0200

jdk2py gravatar image

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


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

edit retag flag offensive close merge delete



Please provide a very precise example of what you do.

FrédéricC gravatar imageFrédéricC ( 2019-09-29 21:53:55 +0200 )edit

2 Answers

Sort by » oldest newest most voted

answered 2019-09-29 22:04:46 +0200

tmonteil gravatar image

updated 2019-09-29 22:05:18 +0200

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.

edit flag offensive delete link more



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/ 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

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2019-09-30 00:09:44 +0200 )edit

answered 2019-09-29 22:08:02 +0200

nbruin gravatar image

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


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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-09-29 21:16:03 +0200

Seen: 1,032 times

Last updated: Sep 29 '19