Perl 删除多行上的Latex标记

Perl 删除多行上的Latex标记,perl,sed,latex,Perl,Sed,Latex,我有一个LaTex文档,其中填充了我要删除的标记。假设文档如下所示 Here is some text, we can have inline $math$ symbols and \emph{markup}. Sometimes we find offset equations, \[ p(\theta|y) \propto p(y|\theta)p(\theta) \] And then we return to some more text. 我想删除所有的标记,我不需要保留包

我有一个LaTex文档,其中填充了我要删除的标记。假设文档如下所示

Here is some text, we can have inline $math$ symbols and \emph{markup}. 
Sometimes we find offset equations,

\[
  p(\theta|y) \propto p(y|\theta)p(\theta)
\]

And then we return to some more text.
我想删除所有的标记,我不需要保留包装在标记中的文本

所以对于
$…$
\emph{…}
这类东西,类似于
sed-E的/\$[a-z]+\$/'
的东西可以很好地工作

我的问题是如何删除跨越多条直线的方程。我想删除
\[
\]
之间的所有内容

使用删除跨多行的两个图案之间的文本:

use strict;
use warnings;

while (<DATA>) {
    next if /^\s*\\\[/ .. /^\s*\\\]/;
    print;
}

__DATA__
Here is some text, we can have inline $math$ symbols and \emph{markup}. 
Sometimes we find offset equations,

\[
  p(\theta|y) \propto p(y|\theta)p(\theta)
\]

And then we return to some more text.
或作为一个班轮:

perl -ne 'next if /^\s*\\\[/ .. /^\s*\\\]/; print' file.tex
开关:

  • -n
    :为输入文件中的每一行创建
    while(){…}
    循环
  • -e
    :告诉
    perl
    在命令行上执行代码
perl -ne 'next if /^\s*\\\[/ .. /^\s*\\\]/; print' file.tex