
Para¿Comandos/entorno de compilación parcial?, Me gustaría agregar \begin{comment}
o \comment
al comienzo del documento (para poder desactivarlo en otra parte del código).
Entonces, incluso si en el ámbito más amplio de las cosas es inútil, en este MWE, como ejercicio, me gustaría que todo el texto esté en blanco, básicamente, de manera condicional a través de la línea de comando (el resultado sería una página en blanco, o ni siquiera pdf).
EDITAR: Sin embargo, me gustaría que se hiciera de tal manera que pudiera agregar arbitrariamente \end{comment}
/ \begin{comment}
más adelante el documento y tenersoloese fragmento se compila.
\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}
La idea es que el documento quedará "en blanco" si se llama a Latex en la línea de comando a través de
pdflatex "\let\doskip\relax\input{test.tex}"
... sin embargo, claramente hay algunos errores de agrupación; de lo contrario, sin la intervención, simplemente usar pdflatex test.tex
funciona bien.
¿Alguna idea de cómo se podría implementar esto?
EDIT2: más cerca, pero aún no allí: lo he visto en kpsewhich comment.sty
"Otros entornos de 'comentarios' están definidos por ... \excludecomment{versionb} ; Estos entornos se utilizan como \begin{versiona} ... \end{versiona} con los comandos de apertura y cierre nuevamente en una línea propia. Este no es un entorno LaTeX: para un comentario incluido, las líneas \begin y \end actúan como si no existieran. En particular, no implican agrupación..."
Entonces, en el siguiente ejemplo, que usa \excludecomment{versionb}
, el inicio{documento} se anula con éxito, se omite la primera parte, luego se interrumpe el comentario, \lipsum[5]
se compone y el documento se compila sin errores, pero más allá de eso, es muy difícil cerrarlo correctamente. no interrumpido (documento completamente en blanco) o continuar con el borrado una vez que se haya interrumpido:
\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
Se puede agregar un a esta macro en comment.sty
:
\gdef\ProcessCommentLine#1^^M{\def\test{#1}
\typeout{test: \meaning\test, \meaning\expandafter \csname End\CurrentComment Test\endcsname}
... entonces, si no hay un \end{versionb}
antes de \lipsum[5]
, podemos ver que el problema ocurre porque se intenta leer las líneas más allá del final del archivo:
...
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}
Entonces, todavía necesito ayuda sobre cómo hacer que este código funcione en todas las circunstancias...
Respuesta1
Puede utilizar el siguiente código en algún lugar del preámbulo después de \documentclass
.
\def\doskipA{\begin{document}\end{document}}
\ifx\doskip\relax \expandafter\doskipA\fi
Respuesta2
Ok, finalmente llegué a alguna parte, aunque tal vez no sea la ideal. El siguiente MWE se comporta así:
Si se compila con
pdflatex test.tex
, elcomment
material se ignora y el documento se compila completamente; pero se generarán estas dos advertencias en el registro (no sé cómo solucionarlo):(\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...
Si se compila con
pdflatex "\let\doskip\relax\input{test.tex}"
; luego hay un\excludecomment
definido, lo llamaSKIPLINES
y\begin{document}
lo inicia automáticamente; el código se compila sin advertencias, y solo se compondrá el segmento entre\end{SKIPLINES}
y\begin{SKIPLINES}
(tenga en cuenta el orden) que se encuentra aquí .\lipsum[5]
También se enviarán mensajes como estos a la terminal:... test: macro:->, macro:->\end{SKIPLINES} noend macro:-> macro:->\end{document} test: macro:->\end{document}, macro:->\end{SKIPLINES} yesend
Supongo que esto requiere \excludecomment
que se evite la agrupación adicional (?). Sin embargo, todavía se necesitan algunos trucos, por lo que el código incluye versiones modificadas de {comment}
's \excludecomment
y \ProcessCommentLine
. En particular, como señaló @UlrikeFischer, si sucede que Latex está en "modo comentario" al leer \end{document}
, se omitirá, lo que generará errores; por lo que el redefinido \ProcessCommentLine
comprueba adicionalmente \end{document}
si hay un token para detener el modo de comentario y luego vuelve a ejecutar el adecuado \end{document}
si se encuentra esa condición.
Esto significa que uno debería poder, en \doskip
modo, agregar \end{SKIPLINES}
y \begin{SKIPLINES}
a voluntad, definir partes de las regiones compilables, sin necesidad de preocuparse si están cerradas correctamente para \end{document}
: un solo par de \end{SKIPLINES}
y \begin{SKIPLINES}
debería funcionar, tan bien como un documento sin ninguno de ellos (o con un adicional \end{SKIPLINES}
).
Obviamente, esta no es una solución verdaderamente adecuada (esta no funciona con \input
archivos ted), por lo que espero que eventualmente surja una respuesta más erudita; pero por ahora, aquí está el MWE (y perdón por el lío):
\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