Ask Your Question
1

SageTeX UnicodeDecodeError

asked 2019-04-02 13:03:58 +0100

dsejas gravatar image

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!

edit retag flag offensive close merge delete

Comments

What is the encoding of your LaTeX source file ? Windows' default of Latin1 is a source of endless problems.

  • Try to specify UTF-8 as your default encoding for everythng.

  • Similarly, at the top of your Sage/Python snippets, try placing # -*- coding: utf-8 -*- to clarify..

HTH,

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2019-04-02 15:56:09 +0100 )edit

I am using Linux Ubuntu. My editor (TeXstudio) is using UTF-8 encoding, and I am also using the "utf8" option for the "inputenc" package. The fist line of my "book.sagetex.sage" file is

## -*- encoding: utf-8 -*-

However, I could reduce the problem to the fact of using accented Spanish words; if I delete the accents, the problem disappears. However, with SageMath v8.6, I didn't have that problem.

By the way,the command sys.getdefaultencoding() returns 'ascii'. So I updated my locales to use UTF-8, but nothing changes.

dsejas gravatar imagedsejas ( 2019-04-02 16:19:48 +0100 )edit

However, with SageMath v8.6

Therefore it's a new problem. This bug should be reported on Trac (or, if you can't access trac, on sage-support and/or sage-release...).

Did you restart your session (or reboot) ?

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2019-04-02 19:29:30 +0100 )edit

3 Answers

Sort by ยป oldest newest most voted
2

answered 2019-04-02 22:13:16 +0100

I agree with the comments that it looks like a bug in SageTeX. I opened https://trac.sagemath.org/ticket/27598.

In the file /SageMath/local/lib/python2.7/site-packages/sagetex.py, try replacing the line "m.update(bytearray(line,'utf8'))" with "m.update(line)". Does that fix it?

(In general this is probably not the right thing to do. I think it will work with Python 2 but not Python 3, but if your Sage is built with Python 2, the default, it could work.)

edit flag offensive delete link more

Comments

Thanks, this fixed the problem for me too. I had multiple sagetex.py lying around in my filesystem, and I needed to change it in only one of them (the others were still with the correct "m.update(line)"

ARG gravatar imageARG ( 2019-08-31 11:06:59 +0100 )edit
0

answered 2019-04-02 22:34:51 +0100

dsejas gravatar image

Hello.

Thank you for your answers. Indeed, as indicated by John Palmieri, the error seems to happen due to the new line m.update(bytearray(line,'utf8')). If replaced with m.update(line)(i.e., the old behavior), the problem is fixed. Thank you for reporting the issue on trac.sagemath.org.

Coincidentally, before reading this, I could zero in on the problem, so I filed a new issue report for SageTeX (https://github.com/sagemath/sagetex/i...). I will mention the report by John.

Thank you very much for your help, Emmanuel and John.

edit flag offensive delete link more
0

answered 2019-06-18 11:06:01 +0100

Marcus gravatar image

Hello, Thank you all very much for your help! I had exactly the same problem and all seams to work fine for me now!

Marcus

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

Stats

Asked: 2019-04-02 13:03:58 +0100

Seen: 710 times

Last updated: Apr 02 '19