
この質問から新しいパッケージが生まれました:
comment_io
コンパイル前にオンとオフを切り替えることができる列挙環境を使用してドキュメントを作成したいと思います。
たとえば、次のようなセクションがあるとします。
\begin{enumerate}
\item This is a test.
\item This is another test.
\item This is yet another test.
\end{enumerate}
通常の状況では、これは次のように 3 つの項目を持つ列挙リストとしてコンパイルされます。
1. This is a test.
2. This is another test.
3. This is yet another test.
この特定の列挙環境を消去して、コンパイルされた出力が次のようになるようにする方法が欲しいです。
This is a test. This is another test. This is yet another test.
さらに、これをさまざまな環境に対してグローバルに実行できるようにしたいと考えています (つまり、問題の環境の各インスタンスをローカル レベルで編集する必要はありません)。
ただし、ドキュメント内に他の列挙環境を残しておきたいと思います (消失環境内にネストされている場合でも)。
コンテキスト: 各セクションを列挙された階層に配置する Tractatus スタイルを使用してテキストを書きたいと思います。ただし、この列挙を削除して、テキストを通常の記事として表示できるようにしたいと考えています。最後に、この通常の記事で、列挙されたリストを表示する機能が必要です (その場合、Tractatus 列挙の一部にはなりません)。
答え1
ネストされた(または他のリスト)環境が機能できるようにするには、この新しい on-off 内で no-op にするつもりなら、enumerate
キャプチャする必要があります。このために、その定義をプリアンブルに保存し、使用するたびに最初に使用できるように復元します。\item
enumerate
enuemrate
etoolbox
\AtBeginEnvironment
他のリストもネストする予定の場合は、\item
同様の方法で復元する必要があります。
enumerate*
以下に、ネストされた をサポートしながらもコンパイル中にオフにするものを定義しましたenumerate
。
\documentclass{article}
\usepackage{etoolbox}
\AtBeginEnvironment{enumerate}{\let\item\olditem}
\let\olditem\item
\newenvironment{enumerate*}
{\par\let\item\relax}
{\par}
\begin{document}
\begin{enumerate*}
\item Something
\begin{enumerate}
\item Something else
\item Another thing
\begin{enumerate*}
\item This is it
\item This is another it
\end{enumerate*}
\end{enumerate}
\item Last thing
\end{enumerate*}
\end{document}
enumerate*
何もしないように再定義されます\item
( になります\relax
)。そのため、オプションの引数がある場合は完全に無視されます。つまり、 は\item[<stuff>]
デフォルトで になります[<stuff>]
。必要に応じて、オプションの引数を取り込むように調整できます。
によって挿入された垂直調整を調整することもできますenumerate*
。
答え2
皆さんの回答に感謝します。しかし、最終的には、さまざまな方法を試して頭を悩ませた後、ファイルに含まれる特定のコマンドに応じて行をコメントアウト (またはコメント解除) する独自のスクリプトを Python で作成することにしました。
たとえば、元のファイルは次のようになります。
\begin{document}
\begin{enumerate}
\item
This is a test.
\item
This is another test.
\item
This is yet another test.
\end{enumerate}
\end{document}
これらすべての列挙をオフにするオプションが必要な場合は、コメントアウトしたい各行の末尾に、次のように小さなコマンドを追加するだけです。
\begin{document}
\begin{enumerate} %@
\item %@
This is a test.
\item %@
This is another test.
\item %@
This is yet another test.
\end{enumerate} %@
\end{document}
そして、私のスクリプトが魔法をかけると、ファイルは次のように変わります。
\begin{document}
%@ \begin{enumerate}
%@ \item
This is a test.
%@ \item
This is another test.
%@ \item
This is yet another test.
%@ \end{enumerate}
\end{document}
これは面倒に思えるかもしれませんが、何が起こっているかすべてわかっているので、私にとってはこれが絶対的に最善の解決策です。
Pythonで書かれたこのプログラムを使用したり見たりしたい人は、CTAN。
答え3
enumitem
ニーズに応じて新しい環境を定義します。
\documentclass{article}
\usepackage{enumitem}
\newlist{myenum}{enumerate*}{3}
\setlist[myenum]{leftmargin=!,label=\arabic*.}
\begin{document}
\begin{myenum}
\item This is a test.
\item This is another test.
\item This is yet another test.
\begin{myenum}[label=]
\item Second level This is a test.
\item This is another test.
\item This is yet another test.
\begin{myenum}[label=\roman*.]
\item Third level This is a test.
\item This is another test.
\item This is yet another test.
\end{myenum}
\end{myenum}
\end{myenum}
\end{document}
答え4
これは、あなたのユースケースではほぼ目的を果たします。より高度な列挙環境やオプションでは堅牢ではない可能性があります。ネストを希望どおりに処理できないためです。
\documentclass{article}
\usepackage{etoolbox}
\newtoggle{killenumerate}
\toggletrue{killenumerate}
\newenvironment{myenumerate}
{\iftoggle{killenumerate}
{\renewcommand{\item}{}}
{\begin{enumerate}}
}
{\iftoggle{killenumerate}
{}
{\end{enumerate}}
}
\begin{document}
Enumeration switched off selectively in preamble.
\begin{myenumerate}
\item One item in myenumerate environment
\item Two
\item Three
\end{myenumerate}
\begin{enumerate}
\item One item in ordinary enumerate
\item Two
\item Three
\end{enumerate}
Enumeration switched on for the rest of the document.
\togglefalse{killenumerate}
\begin{myenumerate}
\item One item in myenumerate environment
\item
\item Two
\item Three
\end{myenumerate}
\end{document}