用$和多行替换LaTeX [英] Replace LaTeX with $ and multi-line
本文介绍了用$和多行替换LaTeX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用sed代替 $ some乳胶$
或
$$
some latex
$$
带有 {%math%}一些乳胶{%endmath%}
或
{% math %}
some latex
{% endmath %}
我尝试用sed解决此问题,但使用了类似的命令
I try sed to solve this problem but a command like
sed -e 's/\$\([^\$]\{1,\}\)\$/{% math %}\1{% endmath %}/g' filename
不适用于 $ some乳胶$
,而且我不知道如何处理多行.我该怎么办?
doesn't work for $some latex$
and I don't know how to deal with multi-line. How can I do this?
推荐答案
使用sed尝试一下:
sed -e ' /\$\$/{s/\$\$/{% math %}/;:a;N;/\$\$/!ba;s/\$\$/{% endmath %}/};s/^\(\$\)\(.*\)\(\$\)$/{% math %}\2{% endmath %}/' sourcefile
保留多行.
更新:
It seems there is a BSD (OS X?) sed issue with semi colons.
应该用新行替换它:
sed -e '
/\$\$/ {
s/\$\$/{% math %}/
:a
N
/\$\$/!ba
s/\$\$/{% endmath %}/;}
s/^\(\$\)\(.*\)\(\$\)$/{% math %}\2{% endmath %}/
' sourcefile
我还更新了最后一个 s
命令,以匹配注释中提到的 $ \ $ $
等行.
I also updated the last s
command to match lines like $ \$ $
mentioned in you comments.
这篇关于用$和多行替换LaTeX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文