python - 使用 Python 将 LaTeX 字符串与内联方程拆分
问题描述
如何通过保留顺序来拆分包含文本、内联方程和方程块的 LaTeX 字符串?
我想分开
Functions $f(x)$ and $g(x)$ is related as $$f(x)-g(x)=h(x)$$
进入
['Functions ','f(x)','and','g(x)','is related as ','f(x)-g(x)=h(x)']
解决方案
如何使用列表理解:
text_in = "Functions $f(x)$ and $g(x)$ is related as $$f(x)-g(x)=h(x)$$"
foo = [x.strip() for x in text_in.split("$") if x]
print(foo)
这给了你:
['Functions', 'f(x)', 'and', 'g(x)', 'is related as', 'f(x)-g(x)=h(x)']
推荐阅读
- laravel - 如何将其转换为文件?
- python - Python - 从另一个嵌套类访问嵌套类数据
- macos - MacOS Sierra:为什么将 NSScrollView 添加到子视图会更改(/损坏?)超级视图的绘制顺序?
- scala - Scala实现反射以查找成员名称
- winforms - 有没有办法在 .NET 3.5 应用程序中使用 TLS 1.2?
- json - 在 Windows 上使用 MongoDB 打开 JSON 文件
- r - 如何添加用于绘制 geom_jitter 的样本大小
- python - 如何使用枢轴重塑熊猫数据框?
- html - 我缺少哪些标题来抓取 NBA 统计数据?
- swift - 从标签栏控制器推送视图控制器