
을 위한부분 컴파일 명령/환경?\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
잘 작동합니다.
이것이 어떻게 구현될 수 있는지 아이디어가 있습니까?
kpsewhich comment.sty
EDIT2: 더 가깝지만 아직 거기에는 없습니다. " 에서 본 적이 있습니다 .다른 '주석' 환경은 ... \excludecoment{versionb} 로 정의됩니다. 이러한 환경은 한 줄에 다시 열기 및 닫기 명령을 사용하여 \begin{versiona} ... \end{versiona} 로 사용됩니다. 이것은 LaTeX 환경이 아닙니다. 포함된 주석의 경우 \begin 및 \end 행은 존재하지 않는 것처럼 작동합니다. 특히 그룹화를 의미하지 않습니다 ..."
따라서 를 사용하는 아래 예제에서는 \excludecomment{versionb}
start{document}가 성공적으로 재정의되고 첫 번째 부분을 건너뛴 다음 주석이 중단되고 \lipsum[5]
조판되고 문서가 오류 없이 컴파일됩니다. 하지만 그 이상으로는 둘 중 하나를 적절하게 닫는 것이 매우 어렵습니다. 중단되지 않음(완전히 공백 문서) 또는 중단된 후 공백을 계속합니다.
\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
다음 매크로에 A를 추가할 수 있습니다 comment.sty
.
\gdef\ProcessCommentLine#1^^M{\def\test{#1}
\typeout{test: \meaning\test, \meaning\expandafter \csname End\CurrentComment Test\endcsname}
\end{versionb}
... 따라서 앞에 a가 없으면 \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
이 무시되고 문서가 완전히 컴파일됩니다. 하지만 로그에 다음 두 가지 경고가 생성됩니다(수정 방법을 모르겠습니다).(\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}
' \excludecomment
및 의 수정된 버전이 포함되어 있습니다 \ProcessCommentLine
. 특히, @UlrikeFischer가 지적했듯이, 읽을 때 Latex가 "주석 모드"에 있으면 \end{document}
건너뛰어 오류가 발생합니다. 따라서 재정의된 코드는 주석 모드를 중지하기 위한 토큰으로 \ProcessCommentLine
추가로 확인한 다음 해당 조건이 발생하면 \end{document}
적절한 것을 다시 실행합니다 .\end{document}
즉, 모드에서 컴파일 가능한 영역의 일부를 마음대로 \doskip
추가 \end{SKIPLINES}
하고 정의 할 수 있어야 하며 , 해당 부분 이 제대로 닫혔는지 걱정할 필요가 없습니다 . 해당 항목이 없는 문서(또는 추가 항목이 있는 문서 )\begin{SKIPLINES}
\end{document}
\end{SKIPLINES}
\begin{SKIPLINES}
\end{SKIPLINES}
분명히 이것은 정말로 적절한 해결책이 아니기 때문에(이 방법은 \input
ted 파일에서는 작동하지 않습니다) 결국 좀 더 박식한 답변이 나올 수 있기를 바랍니다. 하지만 지금은 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