
네, 제목을 정확하게 읽으셨습니다!
무시하고 싶다모든 것그것은 파일 사이 \begin{document}
와 \end{document}
그 때 입니다. \input
나는 그것이 매우 간단할 것이라고 생각했습니다.패키지environ
:
\RenewEnviron{document}{}
하지만 그게 쉽지 않은 것으로 밝혀졌습니다. 아래 MWE는 올바른 결과를 산출합니다.
하지만 댓글은 그대로 유지됩니다. 주석 처리된 줄의 주석 처리를 해제하면 다음과 같이 끝납니다.
LaTeX 오류: \env@document@save@env 정의되지 않음
흥미롭게도 이 오류를 무시하면 이 오류를 지나 계속해서 올바른 결과를 얻을 수 있습니다. :-)
노트:
- 나는 서문에 다른 내용이 있을 수 있다는 것을 알고 있으므로 이것이 결코 일반적인 해결책은 아닙니다. 이 기능이 필요한 곳에 대해서는 서문오직필요한 모든 파일을 로드하는
\documentclass
두 개의\input
/ 가 있으므로 이것이 내 요구에 충분할 것입니다.\usepackage
.sty
암호:
\documentclass{article}
\usepackage{environ}
\usepackage{standalone}
\newtoks{\MyToken}
\usepackage{filecontents}
\begin{filecontents*}{foo.tex}
\documentclass{standalone}
\usepackage{MyStandardPackages}
\MyToken={foo}
% \begin{document}
% lots of text here
%
% \SetSomeVarable{\SomeVar}{Some Value}
%
% \begin{SomeEnvironment}
% lots more stuff here as well
% \end{SomeEnvironment}
% \end{document}
\end{filecontents*}
\MyToken={XXX}
\newcommand{\DisablePreamble}{%
\renewcommand{\documentclass}[2][]{}% remove def'n of \documentclass
\renewcommand{\usepackage}[2][]{}% ignore any \usepackage{}
% \RenewEnviron{document}{}% Ignore everything within the "document" environment.
}%
\newcommand*{\ExtractMyToken}[1]{%
\begingroup% What happens in the group stays in the group!
\DisablePreamble%
\input{#1}%
\global\MyToken=\expandafter{\the\MyToken}%
\endgroup%
}%
\begin{document}
MyToken=\the\MyToken
\ExtractMyToken{foo}
MyToken=\the\MyToken
\end{document}
답변1
이는 일반적인 문제입니다.environ
문제를 해결하는 방법은 문제가 있는 명령을 정의하는 것입니다.
\makeatletter
\providecommand{\env@document@save@env}{}% To keep environ happy
\providecommand{\env@document@process}{}%
\RenewEnviron{document}{}% Ignore everything within the "document" environment.
\makeatother
당신이 원하는 것을 달성하는 빠르고 더러운 방법은 다음을 사용하는 것입니다.
\renewcommand{\document}{\endgroup\endinput}
\input
에 도달하자마자 문서 읽기가 종료됩니다 \begin{document}
.
답변2
나는 (로컬에서) 정의할 것이다.
\def\begin#1{\endinput}`
그래서 파일이 그 시점에서 멈추거나 아마도 그럴 수도 있습니다(귀하의 사용 사례를 실제로 이해하지 못했습니다
\def\documentclass[#1]#2{\endinput}
더 일찍 중지합니다. (그러나 그렇게 하는 경우 파일을 입력하지 않는 것이 더 쉬울 것입니다.)