Here is one quick and dirty solution to the second question and a link to more advanced solutions (the comments above also contain useful links for both questions):
a) Create two main files where you (1) provide the commands with the spaces and (2) provide the same commands as empty commands (you can also just append something like \renewcommand{\rep}{}
and comment this in or out).
OR
b) Use parameters for your document and use a Makefile. Look at the answers to Passing parameters to a document for some inspiration. Here is an example of how such a Makefile could look like and how your .tex file can make use of it:
Makefile:
default: Exercise.pdf Solution.pdf
Exercise.pdf: *.tex
-rm Exercise.pdf
pdflatex -file-line-error --jobname=Exercise '\def\isexercise{1} \input{main.tex}'
pdflatex -file-line-error --jobname=Exercise '\def\isexercise{1} \input{main.tex}'
Solution.pdf: *.tex
-rm Solution.pdf
pdflatex -file-line-error --jobname=Solution '\input{main.tex}'
pdflatex -file-line-error --jobname=Solution '\input{main.tex}'
main.tex:
\documentclass{article}
\newcommand{\rep}{}
\ifdefined\isexercise
\renewcommand{\rep}{
\noindent\dotfill
\noindent\dotfill
\noindent\dotfill
\noindent\dotfill
}
\fi
\begin{document}
Exercise 1: \rep
\end{document}
rep
in atoggle
from theetoolbox
package.