
のために部分コンパイルコマンド/環境?、ドキュメントの先頭に\begin{comment}
または を追加したいと思います(そうすれば、コードの他の場所でオフにすることができます)。\comment
したがって、たとえより大きな範囲では役に立たないとしても、この MWE では、演習として、基本的にはコマンド ラインを介して条件付きでテキスト全体を空白にしたいと思います (結果は空白ページになるか、PDF が存在しないことになります)。
編集:しかし、私はそのような方法でそれをやりたいと思います。そうすれば、後で文書に任意に追加し\end{comment}
たり\begin{comment}
、のみそのスニペットはコンパイルされます。
\documentclass[11pt]{book}
\usepackage{lipsum}
\ifx\doskip\relax
\typeout{DOSKIP}
\usepackage{etoolbox}
\usepackage{comment}
% https://tex.stackexchange.com/questions/14135/how-to-automatically-add-text-immediately-after-begindocument
%\AtBeginDocument{\comment} % ! Extra \endgroup.
%\AtBeginDocument{\begin{comment}} % Runaway argument? ! File ended while scanning use of \next.
%\AfterEndPreamble{\comment} % ! Extra \endgroup.
%\AfterEndPreamble{\begin{comment}} % Runaway argument? ! File ended while scanning use of \next.
%\AtEndDocument{\endcomment}%{\end{comment}}
% desperate try (also fails w/ ! Extra \endgroup.):
\protected\def\startcomment{\expandafter\comment}
\AtEndPreamble{
\startcomment
} % ! Extra \endgroup.
\fi
\begin{document}
\chapter{Some chapter}
\section{Section One}
\lipsum[1-3]
% later I might want to use here:
% \end{comment}
% \lipsum[5] % this would be typeset
% \begin{comment} % from this point on, again blanked
\end{document}
アイデアとしては、Latex がコマンドラインで ... を介して呼び出されると、ドキュメントが「空白」になるというものです。
pdflatex "\let\doskip\relax\input{test.tex}"
ただし、明らかにグループ化エラーがあります。それ以外の場合は、介入せずに を使用するだけでpdflatex test.tex
正常に動作します。
これをどのように実装できるかについて何かアイデアはありますか?
編集2: 近づいていますが、まだそこまでではありませんkpsewhich comment.sty
。その他の「コメント」環境は ... \excludecoment{versionb} によって定義されます。これらの環境は、開始コマンドと終了コマンドを独自の行に記述した \begin{versiona} ... \end{versiona} として使用されます。これは LaTeX 環境ではありません。インクルードされたコメントの場合、\begin 行と \end 行は存在しないかのように動作します。特に、グループ化を意味するものではありません...「
したがって、 を使用する以下の例では、\excludecomment{versionb}
begin{document} は正常にオーバーライドされ、最初の部分がスキップされ、次に comment が中断され、\lipsum[5]
タイプセットされ、ドキュメントはエラーなしでコンパイルされますが、それ以上に、中断されていない (完全に空白の doc) を適切に閉じることや、中断された後に空白のまま続行することは非常に困難です。
\documentclass[11pt]{book}
\usepackage{lipsum}
\usepackage{trace}
\ifx\doskip\relax
\typeout{DOSKIP}
\usepackage{etoolbox}
\usepackage{comment}
\excludecomment{versionb}
%\AtEndPreamble{ % here causes ! LaTeX Error: Missing \begin{document}.
\AtBeginDocument{%
% \expandafter\begin{versionb}\relax
\begin{versionb}
} %
%\AtEndDocument{\end{versionb}} % ! LaTeX Error: \begin{document} ended by \end{versionb}.
\fi
% \traceon
\begin{document}
\chapter{Some chapter}
\section{Section One}
\lipsum[1-3]
\end{versionb}
\lipsum[5]
% \begin{versionb}
%% \end{versionb} % can this be implicit, as per \AtEndDocument?
\end{document}
%%ENNDDD
\typeout
このマクロに を追加できますcomment.sty
:
\gdef\ProcessCommentLine#1^^M{\def\test{#1}
\typeout{test: \meaning\test, \meaning\expandafter \csname End\CurrentComment Test\endcsname}
\end{versionb}
...の前にがない場合\lipsum[5]
、ファイルの末尾を超えて行を読み取ろうとするため、問題が発生することがわかります。
...
test: macro:->\end{document}, \expandafter\end{versionb}
test: macro:->%%ENNDDD, \expandafter\end{versionb}
test: macro:->, \expandafter\end{versionb}
)
Runaway argument?
! File ended while scanning use of \next.
<inserted text>
\par
<*> \let\doskip\relax\input{test.tex}
したがって、このコードをあらゆる状況で動作させる方法についてはまだ助けが必要です...
答え1
の後のプリアンブルのどこかに次のコードを使用できます\documentclass
。
\def\doskipA{\begin{document}\end{document}}
\ifx\doskip\relax \expandafter\doskipA\fi
答え2
ようやく、理想的ではないかもしれませんが、何とかなりました。以下の MWE は次のように動作します。
でコンパイルすると
pdflatex test.tex
、comment
内容は無視され、ドキュメントは完全にコンパイルされます。ただし、ログに次の 2 つの警告が生成されます (修正方法はわかりません)。(\end occurred inside a group at level 2) ### semi simple group (level 2) entered at line 86 (\begingroup) ### semi simple group (level 1) entered at line 86 (\begingroup) ### bottom level...
pdflatex "\let\doskip\relax\input{test.tex}"
;でコンパイルすると、 と\excludecomment
呼ばれる が定義されSKIPLINES
、\begin{document}
自動的に起動します。コードは警告なしでコンパイルされ、\end{SKIPLINES}
との間のセグメント\begin{SKIPLINES}
(順序に注意)のみが\lipsum[5]
タイプセットされます。ここでは です。また、次のようなメッセージが端末に出力されます。... test: macro:->, macro:->\end{SKIPLINES} noend macro:-> macro:->\end{document} test: macro:->\end{document}, macro:->\end{SKIPLINES} yesend
おそらく、これには\excludecomment
追加の (?) グループ化を回避するために が必要です。ただし、まだ必要なハックがいくつかあるため、コードにはと{comment}
の修正バージョンが含まれています。特に、@UlrikeFischer が指摘したように、 の読み取り時に Latex が「コメント モード」になっていると、 はスキップされ、エラーが発生します。そのため、再定義された は、コメント モードを停止するためのトークンとして を追加でチェックし、その条件に遭遇した場合は を再実行します。\excludecomment
\ProcessCommentLine
\end{document}
\ProcessCommentLine
\end{document}
\end{document}
つまり、\doskip
モードでは、\end{SKIPLINES}
と\begin{SKIPLINES}
を任意に追加して、コンパイル可能な領域の一部を定義でき、 に対してそれらが適切に閉じられているかどうかを心配する必要はありません。 と の\end{document}
単一のペア\end{SKIPLINES}
は、それらをまったく含まないドキュメント (または を追加したドキュメント)\begin{SKIPLINES}
と同様に機能します。\end{SKIPLINES}
明らかに、これは本当に適切な解決策ではありません (これは ted ファイルでは機能しません\input
)。そのため、最終的にはより博学な回答が出てくることを期待しています。しかし、今のところ、MWE は次のとおりです (混乱していて申し訳ありません)。
\documentclass[11pt]{book}
\usepackage{lipsum}
\usepackage{trace}
\newif\ifSKIPLINESAct % if active
\ifx\doskip\relax
\typeout{DOSKIP}
\usepackage{etoolbox}
\usepackage{comment}
\usepackage{xstring}
\def\excludecommentB
#1{\message{Excluding comment '#1'}%
%\csarg\newif{if#1Act}% declare globally; http://tex.stackexchange.com/questions/228994/handling-a-conditionally-defined-newif-nested-in-an-ifx-conditional
\csarg\def{#1}{\endgroup \message{Excluding '#1' comment.}%
\csname #1Acttrue\endcsname
\begingroup
\DefaultCutFileName \def\ProcessCutFile{}%
\def\ThisComment####1{}\ProcessComment{#1}}%
\csarg\def{After#1Comment}{%
\global\csname #1Actfalse\endcsname% must globalize - inside a group here!
\CloseAndInputCutFile \endgroup}
\CommentEndDef{#1}}
% redef this too:
\csarg\xdef{EndDocTest}{\string\end\string{document\string}}
% \showme\EndDocTest
{\catcode`\^^M=12 \endlinechar=-1 %
\gdef\xComment#1^^M{\ProcessCommentLine}
\gdef\ProcessCommentLine#1^^M{\def\test{#1}
\typeout{test: \meaning\test, \expandafter\meaning \csname End\CurrentComment Test\endcsname}
\csarg\ifx{End\CurrentComment Test}\test
\edef\next{\endgroup\noexpand\EndOfComment{\CurrentComment}}%
\else \ThisComment{#1}\let\next\ProcessCommentLine
\fi%
% also add for end document; use \IfStrEq else catcodes could be a problem
\IfStrEq*{\EndDocTest}{\test}{%
%\traceon%
\typeout{yesend}%
\def\next{%\endgroup\noexpand\EndOfComment{\CurrentComment}%
\endgroup\noexpand\EndOfComment{\noexpand\CurrentComment}% % must add \noexpand to \CurrentComment, else it leaks and gets typeset in the doc!
%\SKIPLINESActfalse% no; use:
\AfterSKIPLINESComment% % both sets false and ends group
\enddocument%
}%
}{\typeout{noend \meaning\test\space\meaning\EndDocTest}%\ThisComment{#1}\let\next\ProcessCommentLine% don't execute here, just typeout
}%
\next}
}
\excludecommentB{SKIPLINES} % define, also \ifSKIPLINESAct
%\AtEndPreamble{ % here causes ! LaTeX Error: Missing \begin{document}.
\AtBeginDocument{%
% \expandafter\begin{SKIPLINES}\relax
\begin{SKIPLINES}
} % ! Extra \endgroup.
%\AtEndDocument{\end{SKIPLINES}} % ! LaTeX Error: \begin{document} ended by \end{SKIPLINES}. % redefine instead?
%% no need for this:
% \global\let\oldenddocument\enddocument
% \gdef\enddocument{% redefine
% %\ifSKIPLINESAct\expandafter\end\expandafter{SKIPLINES}\fi
% \oldenddocument%
% }
\else
% still need this, when calling without \doskip:
\makeatletter
\newenvironment{SKIPLINES}{%
\begingroup\def\@currenvir{document}%
}{%
% comment.sty: % sabotage LaTeX's environment testing \begingroup\def\@currenvir{#1}\end{#1}
\begingroup\def\@currenvir{SKIPLINES}%\endgroup
}
% \def\endSKIPLINES{\begingroup\def\@currenvir{SKIPLINES}} % nope
\makeatother
\fi
% \traceon
\begin{document}
\chapter{Some chapter}
\section{Section One}
\lipsum[1-3]
% \traceon
\end{SKIPLINES}
% \traceoff
\lipsum[5]
\begin{SKIPLINES} % will cause ### semi simple group (level 2) entered at line 90 if without \doskip and unclosed, but doc will compile
\lipsum[10]
% \end{SKIPLINES} % if this is uncommented when \doskip, it will allow the next typeout to execute (else they will be gobbled)
% these print to stdout only if \end{SKIPLINES} occured last previously:
\typeout{\meaning\endSKIPLINES}
\ifx\doskip\relax
\ifSKIPLINESAct\typeout{SKIPLINES Active}\else\typeout{no SKIPLINES}\fi%
\else
\fi
\end{document}
%%ENNDDD