2014-11-01 1 views
1

제거하려는 마크 업으로 채워진 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 's/\$[a-z]+\$//'과 같은 것이 정상적으로 작동합니다.

내 질문은 어떻게 여러 줄에 걸쳐 확장 수식을 제거 할 수 있습니다. \[\] 사이의 모든 항목을 제거하고 싶습니다.

답변

2

사용은 Range Operator .. 여러 줄에 걸쳐 두 패턴 사이에 텍스트를 제거 :

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 

스위치 :

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


And then we return to some more text. 

또는 한 - 라이너

  • -n : 입력 파일에 각각 “ 행 ”에 대해 while(<>){...} 루프를 만듭니다.
  • -e : perl에게 명령 줄에서 코드를 실행하도록 지시합니다.
+0

철저한 답변 주셔서 감사합니다. – keegan