Python 无法在另一个命令中替换命令
我正试图从latex源代码中删除许多自定义高亮显示命令。 \rni{}就是其中之一 下面是我所拥有的输入、预期输出和我所应用的方法的最低工作示例。不幸的是,它给了我一个类型错误,因为“命令”标题“没有子项”。我只想删除\rni{}命令本身,但保留其内容。(这不适用于正则表达式,因为我经常使用嵌套命令) 如何在ExpectedOutput文件中实现结果? 我的误解是什么导致了这个错误Python 无法在另一个命令中替换命令,python,latex,Python,Latex,我正试图从latex源代码中删除许多自定义高亮显示命令。 \rni{}就是其中之一 下面是我所拥有的输入、预期输出和我所应用的方法的最低工作示例。不幸的是,它给了我一个类型错误,因为“命令”标题“没有子项”。我只想删除\rni{}命令本身,但保留其内容。(这不适用于正则表达式,因为我经常使用嵌套命令) 如何在ExpectedOutput文件中实现结果? 我的误解是什么导致了这个错误 inputFile = r""" Line1 \caption{The\rni{ q
inputFile = r"""
Line1
\caption{The\rni{ quick brown fox jumps over the} lazy dog}
Line3
"""
expectedOutputFile = r"""
Line1
\caption{The quick brown fox jumps over the lazy dog}
Line3
"""
# Why does this code produce a TypeError on
# the thisMatch.replace_with(replacementText) line and how can I achieve
# the result in expectedOutputFile (removing the \rni{} command but
# keeping the contents)
from TexSoup import TexSoup
soup = TexSoup(inputFile)
matches = soup.find_all("rni")
thisMatch = matches[0]
replacementText = str(thisMatch.string)
thisMatch.replace_with(replacementText)
print(soup)