Ask Your Question

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

asked 2020-02-20 19:26:31 +0200

rana-aerea gravatar image

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

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

I am trying the solution of this page on GitHub.

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

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-02-20 21:31:16 +0200

vdelecroix gravatar image

updated 2020-02-20 21:44:03 +0200

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").

edit flag offensive delete link more


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 ( 2020-02-21 04:15:12 +0200 )edit

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: 2020-02-20 11:55:33 +0200

Seen: 566 times

Last updated: Feb 20 '20