This question follows this Applying TikZ options stored in a file. I just wonder why the following fails to read the file. Please ignore the content of filecontents; although it works, it's just for developing a MNWE. The problem is with my use of \input
.
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{myaux.tex}
\documentclass{article}
\makeatletter
\def\chapno{1}
\def\exno{1.1}
\chardef\other=12
\newwrite\ans
\immediate\openout\ans=answers
\def\answer{%
\par\medbreak
\immediate\write\ans{}%
\immediate\write\ans{\string\ansno\chapno.\exno:}%
\copytoblankline
}
\def\copytoblankline{\begingroup\setupcopy\copyans}
\def\setupcopy{%
\def\do##1{\catcode`##1=\other}%
\dospecials
\catcode`\|=\other
\obeylines%
}
\def\ifnextisspace{%
\expandafter\futurelet\expandafter\next
\expandafter\ifn@xtisspace\string
}
\def\ifn@xtisspace{%
\ifx\next\@sptoken\expandafter\gobblespace
\else\expandafter\writetofile\fi
}
\@namedef{gobblespace} {\ifnextisspace}
\def\writetofile#1\@nil{\immediate\write\ans{#1}}
{\obeylines %
\gdef\copyans#1
{\def\next{#1}%
\ifx\next\@empty %
\let\next=\endgroup %
\else %
\expandafter\ifnextisspace\next\@nil %
\let\next=\copyans %
\fi %
\next %
}%
}
\answer xxx
yyy \ifx xx
\fi zzz
\begin{document}
x
\end{document}
\end{filecontents}
\makeatletter
\begingroup
\lccode`\A=1 \lccode`\B=1 \catcode`\A=7
\lowercase{\endgroup\def\catch@marker{AB}}
\edef\reserved@a{%
\long\def\noexpand\catchfile##1\catch@marker{%
\noexpand\unexpanded\noexpand\expandafter{##1}%
}%
}
\reserved@a
\def\catchfilecontent#1#2{%
\begingroup
\everyeof\expandafter{\catch@marker\noexpand}%
\makeatletter
\edef\reserved@a{\endgroup
\long\def\noexpand#1{%
\expandafter\catchfile\expandafter\@empty
\@@input #2
}%
}%
\reserved@a
}
\makeatother
% Test
\catchfilecontent\myauxfile{myaux.tex}
\begin{document}
x
\end{document}
\input
-related error, but a complaint aboutIllegal parameter number in definition of \myauxfile
which is exactly the same as if I copy the contents offilecontents
directly into\long\def\myauxfile{
. So the problem does seem to lie insidefilecontents
. – Stephan Lehmke Jun 11 '12 at 4:04#
by##
insidefilecontents
, it works. As for the direct definition. So the file catching seems to work as expected (what else did you expect from Heiko? :) – Stephan Lehmke Jun 11 '12 at 4:33#1
when scanning the replacement text for\def\myauxfile{<contents of the file>}
. Thecatchfile
package takes precautions against this, so\CatchFileDef\myauxfile{myaux.tex}{}
works perfectly. – egreg Jun 11 '12 at 7:23\input
. I will fix the 'Illegal parameter' problem. – Ahmed Musa Jun 11 '12 at 16:18