需要LaTeX的简单正则表达式 [英] Need simple regex for LaTeX
本文介绍了需要LaTeX的简单正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的LaTeX文件中,实际上有数千个以下结构的出现:
In my LaTeX files, I have literally thousands of occurrences of the following construct:
$\displaystyle{...math goes here...}$
我想用
\mymath{...math goes here...}
请注意,$消失了,但是花括号仍然保留---如果不是尾随的$,这将是基本的查找和替换.如果我只知道任何正则表达式,我相信它会毫无问题地解决这个问题.我需要做些什么正则表达式?
Note that the $'s disappear, but the curly braces remain---if not for the trailing $, this would be a basic find-and-replace. If only I knew any regex, I'm sure it would handle this with no problem. What's the regex I need to make this happen?
非常感谢.
出现了一些问题,请让我澄清一下
Some issues and questions have arisen, so let me clarify:
- 是的,
$\displaystyle{ ... }$
可以在同一行上出现多次. - 否,不能出现嵌套的
}$
(例如$\displaystyle{...{more math}$...}$
).我的意思是,我想如果将它放在\mbox
之类的东西中也是可以的,但是我无法想象为什么有人会在$\displaystlye{}$
构造中这样做,目的是在文本内联显示数学.无论如何,这不是我曾经做过或可能要做的事情. - 我尝试使用perl建议,但是尽管shell没有提出异议,但文件仍然不受影响.
- 我尝试使用sed建议,但是shell反对('"附近的意外令牌".我以前从未使用过sed(并且"man sed"很钝),但是我的操作是:导航到一个包含.tex文件并键入"
sed s/\$\\displaystyle({[^}]+})\$/\\mymath\1/g *.tex
"的目录.没有运气.如何使用sed执行我想要的操作?
- Yes,
$\displaystyle{ ... }$
can occur multiple times on the same line. - No, nested
}$
's (such as$\displaystyle{...{more math}$...}$
) cannot occur. I mean, I suppose it could if you put it in an\mbox
or something, but I can't imagine why anyone would ever do that inside a$\displaystlye{}$
construct, the purpose of which is to display math inline with text. At any rate, it's not something I've ever done or am likely to do. - I tried using the perl suggestion, but while the shell raised no objections, the files remained unaffected.
- I tried using the sed suggestion, but the shell objected to an "unexpected token near `('". I've never used sed before (and "man sed" was obtuse), but here's what I did: navigated to a directory containing .tex files and typed "
sed s/\$\\displaystyle({[^}]+})\$/\\mymath\1/g *.tex
". No luck. How do I use sed to do what I want?
再次非常感谢您提供的所有帮助.
Again, many many thanks for all offered help.
推荐答案
sed:
s/\$\\displaystyle({[^}]+})\$/\\mymath\1/g
这篇关于需要LaTeX的简单正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文