주석을 포함한 LaTex 문서의 구조 추출

주석을 포함한 LaTex 문서의 구조 추출

나는 내 문서의 각 단락 시작 부분에 다음과 같이 제목이 있는 "특별한" 설명을 작성하는 것을 좋아합니다.

\section{Introduction}

% 1.0 Visually tracking balls is an interesting problem.  
Text related to why tracking balls is important, blah, blah, blah.   
Blah, blah, blah. 

% 1.1 Tracking balls is difficult because of these challenges.  
Text relating the challenges, blah, blah, blah.  
More blah, blah, blah. 

% 2.0 Previous work.  
Text relating the existing work on tracking balls, blah, blah, blah.  
Blah, blah, blah. 

이는 내 문서의 내용을 체계적으로 유지하는 데 도움이 됩니다.

내가 하고 싶은 일은 문서의 구조를 추출하는 것입니다. 즉, 섹션 구분 명령(예: \chapter, \section등)과 각 단락 시작 부분의 "특수" 주석을 추출하는 것입니다.
LaTex 소스 파일(또는 기본 파일에 다른 소스 파일이 포함된 경우 그 그룹)을 구문 분석하고 섹션 지정 명령과 "특수" 주석만 포함된 새 파일을 일반 텍스트로 변환하고 싶습니다( 주석 처리되지 않음) 또는 글머리 기호 목록으로 바뀌는 것이 더 좋습니다.

따라서 이전 코드에서 파서를 실행하여 생성된 출력은 다음과 같습니다.

\section{Introduction}

\begin{itemize}  
  \item 1.0 Visually tracking balls is an interesting problem.  
  \item 1.1 Tracking balls is difficult because of these challenges.  
  \item 2.0 Previous work.  
\end{itemize}

지금까지 내가 얻은 가장 좋은 해결책은 특수 주석에 문자 순서로 레이블을 지정한 다음(예: "%$"로 시작) 소스 파일에서 "%$" 및 섹션화 명령의 발생을 파악하는 것입니다.

미리 감사드립니다.

답변1

여기서는 grep 및 sed(Windows의 cygwin bash)를 사용하는 명령줄 도구를 사용하여 쉽게 수행할 수 있지만 다른 시스템도 유사하거나 Perl을 사용할 수 있습니다.

zz.tex원본 파일인 경우

명령줄

$ grep "\(sub\)*section\|^%" zz.tex | sed -e '/^\\s/ a \\\\begin{itemize}' -e 's/^%/\\item /' -e '$ a \\\\end{itemize}'

출력

\section{Introduction}
\begin{itemize}
\item  1.0 Visually tracking balls is an interesting problem.  
\item  1.1 Tracking balls is difficult because of these challenges.  
\item  2.0 Previous work.  
\end{itemize}

답변2

여기서는 "목차" 접근 방식을 사용합니다. 즉, aux 파일에 정보를 명시적으로 쓰고 거기에서 처리한다는 의미입니다. 1) "XYZecutive 요약"이 원본 문서에 포함되어 있는 경우와 2) 요약이 외부 문서인 경우의 두 가지 접근 방식을 제시하도록 편집되었습니다.

두 경우 모두 매크로를 반복적으로 사용하여 \addxyzline{type}{content}aux 파일에 다양한 줄을 추가할 수 있는 tex 파일이 있습니다. 또한 \writexyz.aux 파일을 읽고 .xyz 파일을 생성하는 매크로 도 있습니다 . \begin{document}섹션이 발생하기 전이나 모든 섹션이 발생한 후에 소스 문서에서 뒤에 나타날 수 있습니다 .

접근법 1: 동일한 문서의 XYZecutive 요약

이 접근 방식에서 \writexyz매크로는 .xyz 파일에 내용을 쓸 뿐만 아니라 두 번째 단계에서 해당 문서를 처리하여 내용의 형식을 적절하게 지정합니다.

실행 요약(모든 정보 포함 \addxyzline)은 호출 시 나타납니다 \writexyz. 이 MWE에서는 이를 toc 뒤, 문서 문제 앞에 배치합니다. 나는 \addtocontents요약 섹션이 목차에서 중복 섹션으로 끝나지 않도록 매크로 정의를 사용합니다 .

\documentclass{article}
\newcommand\addxyzline[2]{\addtocontents {xyz}{\protect \xyzline {#1}{#2}}}
\let\svaddtocontents\addtocontents
\makeatletter
\newcommand\writexyz{%
  \renewcommand\addtocontents[2]{\relax}%
  \clearpage\setcounter{section}{0}\noindent%
  {\Huge\hrulefill XYZecutive Summary\hrulefill\par}%
  \newcommand\xyzline[2]{\expandafter\csname##1\endcsname{##2}}\@starttoc{xyz}%
  \par\noindent\hrulefill\clearpage\setcounter{section}{0}%
  \let\addtocontents\svaddtocontents
}
\makeatother
\begin{document}
\tableofcontents% CAN UNCOMMMENT TO SEE THAT toc WORKS FINE
\writexyz

\section{Introduction}
\addxyzline{section}{Introduction}

\addxyzline{begin}{itemize}
\addxyzline{item}{1.0 Visually tracking balls is an interesting problem.}
Text related to why tracking balls is important, blah, blah, blah.   
Blah, blah, blah. 

\addxyzline{item}{1.1 Tracking balls is difficult because of these challenges.}
Text relating the challenges, blah, blah, blah.  
More blah, blah, blah. 

\addxyzline{item}{2.0 Previous work.}
Text relating the existing work on tracking balls, blah, blah, blah.  
Blah, blah, blah.
\addxyzline{end}{itemize}

\end{document}

여기에 이미지 설명을 입력하세요

접근법 2: 별도의 요약 문서

여기서는 이전과 같이 문서 본문을 생성하지만 \writexyz요약을 동일한 문서에 기록하지 않고 단지 .xyz 파일에만 기록합니다.

\documentclass{article}
\newcommand\addxyzline[2]{\addtocontents {xyz}{\protect \xyzline {#1}{#2}}}
\makeatletter
\newcommand\writexyz{\newcommand\xyzline[2]{}\@starttoc{xyz}}
\makeatother
\begin{document}
%\tableofcontents% CAN UNCOMMMENT TO SEE THAT toc WORKS FINE
\section{Introduction}
\addxyzline{section}{Introduction}

\addxyzline{begin}{itemize}
\addxyzline{item}{1.0 Visually tracking balls is an interesting problem.}
Text related to why tracking balls is important, blah, blah, blah.   
Blah, blah, blah. 

\addxyzline{item}{1.1 Tracking balls is difficult because of these challenges.}
Text relating the challenges, blah, blah, blah.  
More blah, blah, blah. 

\addxyzline{item}{2.0 Previous work.}
Text relating the existing work on tracking balls, blah, blah, blah.  
Blah, blah, blah.
\addxyzline{end}{itemize}

\writexyz
\end{document}

화면 출력의 경우 편집은 내용에 관계없이 원본 문서의 출력을 생성합니다 \addxyzline.

여기에 이미지 설명을 입력하세요

그러나 다음 정보가 포함된 .xyz 파일(이 경우 원본 파일 xyz.tex를 호출했기 때문에 xyz.xyz)도 생성됩니다.

\xyzline {section}{Introduction}
\xyzline {begin}{itemize}
\xyzline {item}{1.0 Visually tracking balls is an interesting problem.}
\xyzline {item}{1.1 Tracking balls is difficult because of these challenges.}
\xyzline {item}{2.0 Previous work.}
\xyzline {end}{itemize}

내 정보가 모두 들어있습니다 \addxyzline.

그런 다음 매우 간단한 두 번째 tex 파일이 있습니다.

\documentclass{article}
\newcommand\xyzline[2]{\csname#1\endcsname {#2}\par}
\begin{document}
\input{xyz.xyz}% NAME OF .xyz FILE GOES HERE IN THE ARGUMENT
\end{document}

xyz 요약 정보를 제공합니다.

여기에 이미지 설명을 입력하세요


추신

보시다시피, 의 첫 번째 인수는 \addxyzline매크로 이름의 텍스트입니다. 내 MWE에서는 "섹션", "시작", "항목" 및 "끝"을 사용했습니다. 다른 유용한 주문에는 다음이 포함될 수 있습니다.

\addxyzline{relax}{this is just text added on the same line}
\addxyzline{newline}{this is just text on a new line}

답변3

다음은 "목차" 접근 방식을 사용하는 ConTeXt 솔루션입니다. 사용하지 않는 섹션 제목을 선택하고 subsubject이를 사용하여 주석을 추가하세요.개요주요 문서에서:

\setuphead[subsubject][placehead=empty, before=,after=, incrementnumber=yes]

\starttext

\section{Introduction}

\subsubject{1.0 Visually tracking balls is an interesting problem.}
Text related to why tracking balls is important, blah, blah, blah.   
Blah, blah, blah. 

\subsubject{1.1 Tracking balls is difficult because of these challenges.}
Text relating the challenges, blah, blah, blah.  
More blah, blah, blah. 

\subsubject{2.0 Previous work. }
Text relating the existing work on tracking balls, blah, blah, blah.  
Blah, blah, blah. 

\stoptext

첫 번째 줄에서는 placehead=emptyConTeXt에게 출력에 머리(이 경우 주제)를 배치하지 말라고 지시합니다. incrementnumber=yes다른 파일을 통해 액세스할 수 있는 방식으로 ToC 항목이 작성되었는지 확인해야 합니다.

다음으로 별도의 파일을 만들어 개요를 만듭니다. 메인 파일의 이름은 test.tex.

\starttext
\ctxlua{job.load("test.tuc")}
\placelist[section,subsubject]
          [pagenumber=no, headnumber=no]   
\stoptext

이는

여기에 이미지 설명을 입력하세요

관련 정보