
私は、ドキュメント内の各段落の冒頭に、次のようなタイトルの付いた「特別な」コメントを書くのが好きです。
\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
。LaTex\section
ソース
ファイル (または、メイン ファイルに他のソース ファイルが含まれている場合はそのグループ) を解析し、セクション コマンドと「特別な」コメントのみを含む新しいファイルを生成し、通常のテキスト (コメントなし) に変換するか、またはさらに良い方法として、箇条書きリストに変換します。
したがって、前のコードでパーサーを実行すると生成される出力は次のようになります。
\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}
これまでのところ、私が得た最善の解決策は、特別なコメントに文字シーケンスのラベルを付け(つまり、「%$」で始める)、ソース ファイル内の「%$」とセクション コマンドの出現箇所を grep することです。
前もって感謝します。
答え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) サマリーが外部ドキュメントである場合の 2 つのアプローチを示します。
どちらの場合も、マクロを繰り返し使用して\addxyzline{type}{content}
aux ファイルにさまざまな行を追加できる tex ファイルがあります。また、.aux ファイルを読み込んで .xyz ファイルを作成するマクロもあります。これは、セクション化が行われる前、またはすべてのセクション化が行われた後、\writexyz
ソース ドキュメントの の後に表示できます。\begin{document}
アプローチ 1: 同一文書内の連続要約
\writexyz
このアプローチでは、マクロは .xyz ファイルに内容を書き込むだけでなく、2 回目のパスでそのドキュメントを処理し、内容を適切にフォーマットします。
エグゼクティブ サマリー (すべての\addxyzline
情報を含む) は、 の呼び出し時に表示されます\writexyz
。この MWE では、これを目次の後、文書の主題の前に配置します。\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
情報が含まれています。
次に、非常にシンプルな 2 番目の 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 では、「section」、「begin」、「item」、「end」を使用しています。その他の便利な呪文としては、
\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=empty
ConTeXt に出力に見出し (この場合はサブ主題) を配置しないように指示します。ToCincrementnumber=yes
エントリが他のファイルからアクセス可能な方法で記述されていることを確認する必要があります。
次に、アウトラインを作成するために別のファイルを作成します。メイン ファイルの名前は であると仮定しますtest.tex
。
\starttext
\ctxlua{job.load("test.tuc")}
\placelist[section,subsubject]
[pagenumber=no, headnumber=no]
\stoptext
これにより