如何解决TexSoup无法替换另一个命令中的命令
我正试图从我的乳胶源中剥离出许多自定义突出显示命令。 \ rni {}是其中之一。
下面是我所拥有的输入,预期输出和我正在应用的方法的最小工作示例。不幸的是,它给我一个TypeError,因为“命令“标题”没有子项”。我只希望删除\ rni {}命令本身,但保留其内容。 (这不适用于正则表达式,因为我经常使用嵌套命令)。
如何在ExpectedOutputFile中获得结果? 我是怎么引起这个错误的误解?
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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。