
¿Por qué lo siguiente .dtx
no se compila, mientras que el .tex
archivo equivalente sí lo hace? (Debes nombrar el archivo error.dtx
, eso es lo que \DocInput
incluye.)
DTX:
% \iffalse meta-comment
%<*driver>
\documentclass{ltxdoc}
\input pgfutil-common
\makeatletter
\def\myitem#1{%
\pgfutil@in@{,}{#1}%
\ifpgfutil@in@
\myitem@#1\@end
\else
\myitem@#1,\@end
\fi
}
\def\myitem@#1,#2\@end{\item\texttt{#1}\quad\marginpar{\small\it#2}}
\makeatother
\begin{document}
\DocInput{error.dtx}
\end{document}
%</driver>
% \fi
% \begin{description}
% \myitem{align,key} This is documentation for key \emph{align}.
% \end{description}
% \endinput
Látex:
\documentclass{ltxdoc}
\input pgfutil-common
\makeatletter
\def\myitem#1{%
\pgfutil@in@{,}{#1}%
\ifpgfutil@in@
\myitem@#1\@end
\else
\myitem@#1,\@end
\fi
}
\def\myitem@#1,#2\@end{\item\texttt{#1}\quad\marginpar{\small\it#2}}
\makeatother
\begin{document}
\begin{description}
\myitem{align,key} This is documentation for key \emph{align}.
\end{description}
\end{document}
Respuesta1
El diagnóstico a que se debe esto \else
es correcto. Un enfoque alternativo para resolverlo es colocar el nuevo código en la parte 'documento' de Docstrip. Para hacer eso, los caracteres de comentario en la definición deberán convertirse a^^A
% \iffalse meta-comment
%<*driver>
\documentclass{ltxdoc}
\input pgfutil-common %
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%\makeatletter
%\def\myitem#1{^^A
% \pgfutil@in@{,}{#1}^^A
% \ifpgfutil@in@
% \myitem@#1\@end
% \else
% \myitem@#1,\@end
% \fi
%}
%\def\myitem@#1,#2\@end{\item\texttt{#1}\quad\marginpar{\small\it#2}}
%\makeatother
% \show\myitem
% \begin{description}
% \myitem{align,key} This is documentation for key \emph{align}.
% \end{description}
% \endinput
Respuesta2
Cuando el documento se procesa por segunda vez (ingresado por \DocInput
), TeX lo encuentra \iffalse
en la parte superior del archivo. La intención es que esto \iffalse
coincida con el \fi
siguiente signo de comentario, saltándose así el preámbulo. Pero no es así. Se queda atascado \else
en la definición de \myitem
.
Normalmente, \ifpgfutil@in@
es seguro utilizar condicionales anidados, entonces, ¿por qué sucede esto?
La respuesta es que TeX encuentra no \ifpgfutil@in@
en la segunda pasada, ya que el código cat de @
es otro, no una letra --- \makeatletter
fue omitido por el \iffalse
que se quedó atascado en \ifpgfutil@in@
's \else
...
Una solución rápida y sucia es proporcionar un comentario \if
que solo será visible para TeX en la segunda pasada:
% \iffalse meta-comment
%<*driver>
\documentclass{ltxdoc}
\input pgfutil-common
\makeatletter
\def\myitem#1{%
\pgfutil@in@{,}{#1}%
\ifpgfutil@in@ %\if
\myitem@#1\@end
\else
\myitem@#1,\@end
\fi
}
\def\myitem@#1,#2\@end{\item\texttt{#1}\quad\marginpar{\small\it#2}}
\makeatother
\begin{document}
\DocInput{error.dtx}
\end{document}
%</driver>
% \fi
% \begin{description}
% \myitem{align,key} This is documentation for key \emph{align}.
% \end{description}
% \endinput
O, tal vez incluso mejor, poner todo el código potencialmente ofensivo en un archivo separado...