First time here? Check out the FAQ!

Ask Your Question
1

SageTeX Warning of Sagemath-9.0 on string with Escaped 'S'

asked 5 years ago

rana-aerea gravatar image

After I installed SageMath-9.0 (MacApplication), I encountered the following warning in the log of SageTeX compilation.

Console /Applications/SageMath-9.0.app/Contents/Resources/sage/local/lib/python3.7/site-packages/sagetex.py:63: DeprecationWarning: invalid escape sequence \S [re.match(' *\S', line) for line in lines]

I looked through the internet and found a similar situation in some other software.

  • ThiefMaster
  • "invalid escape sequence" DeprecationWarnings with Python 3.6 #646
  • github.com/pallets/jinja/issues/646

I am trying the solution of this page on GitHub.

The relevant part is around line 63 of sagetex.py, which I quote here.

```python
def strip_common_leading_spaces(s):
    lines = s.splitlines()
    lead = min(m.end() for m in
                  [re.match(r' *\S', line) for line in lines]
                  if m is not None) - 1
    return '\n'.join(line[lead:] for line in lines)
```

As in this quotation, I just inserted the letter 'r' to the left of the string on line 63. It is the first line of the deepest indentation in this quotation.

Is this a good solution?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 5 years ago

vdelecroix gravatar image

updated 5 years ago

Short answer: Yes.

This deprecation warning is most certainly due to the Python 2 to Python 3 switch that happened with Sage version 9.0. Invalid escape sequence (such as "\S") will be treated as error in the future. One could either use two backslashes as in "\\S" (the string "\\" is a single character, the backslash symbol) or use the r as you did (in which case all backslashes will be consider as character, even the linebreak "\n").

Preview: (hide)
link

Comments

Thank you for precise information. I am happy to know my solution did not harm SageTeX. I feel using double backslash is a better habit. I update the file.

rana-aerea gravatar imagerana-aerea ( 5 years ago )

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: 5 years ago

Seen: 805 times

Last updated: Feb 20 '20