Closed done-with-fish closed 4 years ago
I think this boils down to the following Py3 behavior.
$ /Applications/SageMath-9.0.app/Contents/Resources/sage/sage -python
Python 3.7.3 (default, Jan 2 2020, 12:09:18)
[Clang 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> Y = '\usepackage{sagetex}'
File "<stdin>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-1: truncated \uXXXX escape
>>> Z = r'\usepackage{sagetex}'
>>> Z.replace(r'\%', '').split('%')[0]
'\\usepackage{sagetex}'
At first I thought we might have to read things in as raw strings here:
with open(src + '.tex') as texf:
for line in texf:
if re.search(usepackage, line.replace(r'\%', '').split('%')[0]):
uses_sagetex = True
break
but maybe we have to do something better for the following line - maybe removing the raw string, weird as that sounds?
usepackage = r'\usepackage(\[.*\])?{sagetex}'
See this Stackoverflow question for what seems to be the same issue.
@dimpase what do you think? @fchapoton knows an awful lot about Py3 migration so I suspect he will know as well.
All I can say atm is that seems to be only place where this breaks (finding whether there is
\usepackage{sagetex}
in the file) - otherwise at least this example works.
Yes, I believe that is correct. @done-with-fish can you try changing the script to have
usepackage = '\usepackage(\[.*\])?{sagetex}'
or possibly
if re.search(usepackage, line.replace('\%', '').split('%')[0]):
just to see if those might possibly fix it, as indicated in the linked question?
Please test the fix proposal at #45
fixed by #45
I recently upgraded to SageMath version 9.0 which used Python 3.8.1. I'm running arch linux and have checked that my version of the run-sagetex-if-necessary.py script is exactly the same as the one here.
The run-sagetex-if-necessary.py script fails when running with python 3.
Here is a mwe where I cat a simple tex document and attempt to run the script: