Opened 8 months ago

Closed 5 months ago

#27598 closed defect (duplicate)

Unicode problem with SageTeX

Reported by: jhpalmieri Owned by:
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: packages: standard Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

Running SageTeX with Python 2 on this file fails:

\documentclass{article}
\usepackage{sagetex}
\begin{document}

\begin{sageblock}
  s = "hello á goodbye"
\end{sageblock}

\end{document}

(With Python 3, I think it works.) The error occurs when running Sage:

$ sage junk.sagetex.sage
Processing Sage code for junk.tex...
Code block (line 5) begin...end
Traceback (most recent call last):
  File "junk.sagetex.sage.py", line 16, in <module>
    _st_.endofdoc()
  File "/Users/jpalmier/Desktop/Sage/git/sage/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 14: ordinal not in range(128)

Change History (5)

comment:1 Changed 8 months ago by jhpalmieri

The problem is with the use of the bytearray function. With Python 2:

>>> bytearray('á')
bytearray(b'\xc3\xa1')
>>> bytearray('á', 'utf8')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)

With Python 3:

>>> bytearray('á')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: string argument without an encoding
>>> bytearray('á', 'utf8')
bytearray(b'\xc3\xa1')
Last edited 8 months ago by jhpalmieri (previous) (diff)

comment:2 Changed 5 months ago by dimpase

this is hopefully fixed in #27968, which includes the recently merged PR that deals with this issue.

comment:3 Changed 5 months ago by dimpase

  • Status changed from new to needs_review

please confirm that #27968 provides the fix, then this can be closed.

comment:4 Changed 5 months ago by jhpalmieri

  • Milestone changed from sage-8.8 to sage-duplicate/invalid/wontfix
  • Status changed from needs_review to positive_review

Confirmed. Marked as duplicate.

comment:5 Changed 5 months ago by chapoton

  • Resolution set to duplicate
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.