I'm writing an exam for my students, and have defined 3 commands to insert spaces with \dotfill permitting them to write their responses: \rep,\replarge, \repLarge for short and large responses:

\newcommand{\rep}{\noindent \dotfill 




\newcommand{\repshort}\rep \rep 

\newcommand{\repLarge}\rep \rep \rep \rep

So, my questions are:

  1. is there any way to ameliorate those commands?
  2. how can I produce two pdf versions when compiling: One with the spaces produced with the commands, and the other without the spaces?
  • 2
    For (1), see Repeat command n times? – Werner Dec 24 '14 at 0:47
  • 3
    Before you implement too much on this, see if the exam class will suffice for any or all of your needs. Section 7 of the documentation shows several ways to leave space for answers, and section 8 covers printing solutions for a grading key or similar. – Mike Renfro Dec 24 '14 at 1:12
  • If you want to implement (2) yourself, wrap the body of rep in a toggle from the etoolbox package. – Ethan Bolker Dec 24 '14 at 1:24

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).


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:


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}'









Exercise 1: \rep

  • Thank you Cryingshadow for the response, but I am a trully poor user of windows$, I think that the Makefile doesn't work with the windows$ system. – hachemy Dec 25 '14 at 21:28
  • 1
    Use Cygwin (cygwin.com). – cryingshadow Dec 25 '14 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.