Pythontex 警告:“DeprecationWarning:无效的转义序列 \m”

Pythontex 警告:“DeprecationWarning:无效的转义序列 \m”

当在下面的示例中使用类似pythontex功能时,我收到以下警告:sagefamily

This is PythonTeX 0.18

----  Messages for sage:default:default  ----
  /usr/local/texlive/2021/texmf-dist/scripts/pythontex/pythontex_utils.py:231: DeprecationWarning: invalid escape sequence \m
    '''

--------------------------------------------------
PythonTeX:  Sage_Warning - 0 error(s), 0 warning(s)

这个警告是什么意思?我该如何消除它?

如果我无法摆脱它,那么至少有没有一种方法可以防止 emacs 每次我从 emacs 编译它(更改 sage 代码后)时显示此消息?

最小示例:

\documentclass{article}

\usepackage[gobble=auto,usefamily=sage]{pythontex}

\begin{document}

\begin{sagecode}
a = 2
b = 3
\end{sagecode}

\(\sage{a}\)

\end{document}

运行pdflatex myfilename.tex然后pythontex myfilename.tex重现警告(要再次重现警告,您必须更改 sagecode 块或删除目录pythontex-files-myfilename,然后pythontex myfilename.tex再次执行)。

pdflatex --version
pdfTeX 3.141592653-2.6-1.40.23 (TeX Live 2021)
kpathsea version 6.3.3
Copyright 2021 Han The Thanh (pdfTeX) et al.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Han The Thanh (pdfTeX) et al.
Compiled with libpng 1.6.37; using libpng 1.6.37
Compiled with zlib 1.2.11; using zlib 1.2.11
Compiled with xpdf version 4.03
sage --version
SageMath version 9.2, Release Date: 2020-10-24

答案1

正如 Marijn 在评论中提到的,这是一个纯 Python 警告,因为作者意外地在文档字符串中pythontex使用了转义序列(写入)。\m\mathchoice

正如错误所告诉你的,问题发生在pythontex_utils.py231 行。在该行中,文档字符串以包含多个未转义的反斜杠开始,从而导致意外的转义序列(\m顺便说一句,不仅仅是)。为了解决这个问题,作者应该转义每个反斜杠,或者通过在开头的引号pythontex前添加一个来使文档字符串“原始” 。r

由于这个问题很容易解决,如果你在项目的问题追踪器

相关内容