The answer to your question is two fold:
Yes, comments are ignored when compiling and the text of a comment is irrecoverable from the final document.
However, no. It is often possible to tell where / how long the comments in the source were. For instance, take the following senario:
Line 1
Line 2
vs.
Line 1%
Line 2
In the compiled output, the newline character after Line 1
in the first example is treated as whitespace and converted to a space, so the output reads Line 1 Line 2
. However, in the second example, the comment character comments out the whitespace, so the final compiled output reads Line 1Line 2
. While this example doesn't leak any information itself, it does show how easy it is for comments to modify the structure of a TeX document in ways that you wouldn't expect.
While I doubt this is relevant to your use case, it does make it possible to get some information about where comments were, and sometimes how long they were, so it might be good to think through your questions / answers to make sure you're not leaking any information in this manner (that being said, are your students likely to think it through this far?).
EDIT: Saw right after posting that someone beat me to it. Sorry for the redundant info.
Best Answer
Based on this answer, you could use
accsupp
to define a\squelch
command:The squelched text cannot be highlighted in Acrobat, and copying the whole line gives this:
It's easy to combine this with
fancyhdr
:You could also define a variant
\squelchstyle
for use with KOMA-Script's\addtokomafont
: