Comment out lines without using % and comment enviroment
LaTeX is a markup language. For the private information macros can be used. File exercise.435.tex
could look like:
\private{is the \filename{exercise.435.tex}}
\private{1.84 ex.\@ 127 page notes}
\begin{exercise}
...
\end{exercise}
Then macro \private
can be defined to set the contents in red and small font:
\newcommand*{\private}[1]{%
\ifhmode\newline\fi
\textcolor{red}{\small #1}%
\ignorespaces
}%
\newcommand*{\filename}[1]{#1}% or \texttt{#1} or ...
And it is easy to suppress the lines:
\newcommand*{\private}[1]{\ignorespaces}
\ignorespaces
removes the line end after \private{...}
to avoid unwanted spaces.
You could go the other way round, and change the catcode of % so that it no longer acts as comment char when you start reading the file. The exercise environment could then revert the change. You could also use some other (unused) char as special comment sign. But such catcode changes are a bit fragile, so it depends a lot on your document if the idea is usable:
\documentclass{article}
\begin{document}
\catcode`\%=9
% not ignored
% not ignored
\catcode`\%=13
\def%{\par Private: }
% not ignored
% not ignored
\catcode`\%=14
% ignored
% ignored
blub
\catcode`\@=14
@ ignored
@ ignored
exercise
\end{document}
If your input files all have the same form, that is some lines starting with \\
and an empty line after them, you can do by temporarily redefining \\
and changing the command for inputting the exercises:
\newcommand{\exeinput}[1]{%
\let\latexdoublebackslash\\
\ifprolog\let\\\showprolog\else\let\\\hideprolog\fi
\input{#1}}
\def\showprolog#1\par{%
\def\\{\par\noindent}% redefine `\\` to end lines
\par\noindent
#1% print the lines
\par % end the last line
\let\\\latexdoublebackslash}
\def\hideprolog#1\par{\let\\\latexdoublebackslash} % throw away the prolog lines
\newif\ifprolog
So you can say
\exeinput{exercise.435.tex}
and if you set \prologtrue
also the prolog lines will be printed.
However this would spectacularly fail if there's not an empty line between the prolog and the main contents, so a special markup is probably the best strategy. For instance, if your exercise files have the form
\startprolog
\\ is the exercise.435.tex % is the name of the file
\\ 1.84 ex. 127 page notes % is the source of exercise etc
\stopprolog
\begin{exercise}
. . .
\end{exercise}
you can say
\newif\ifprolog
\long\def\startprolog#1\stopprolog{%
\ifprolog
\par
\begingroup
\let\\\par
\color{red}\small #1
\par\medskip
\endgroup
\fi}
and so
\input{exercise.435.tex}
will print the exercise without the prolog unless you set \prologtrue
. The advantages are that you risk nothing if the prolog is not separated from the contents and that it's possible to reformat freely the prolog when you want to print it (maybe as a marginal note, for instance).