16

I am preparing some lecture notes/slides and would like to efficiently create two versions of the output: a complete version for myself, and a version for my students with certain text replaced with blanks or an empty box so that they can fill it in during lectures.

the \underline{\phantom{text}} command does the trick, but it would be time consuming to create a separate version of the document and insert this in all the relevant places.

How can one use macros to give us the ability to easily toggle between the teacher version (with full text) and student version (with blanks)?

I was going to post this as a question but then figured it out so thought I'd share it.

4 Answers 4

12

The censor package will break across lines with the \blackout and \xblackout commands. The first will show inter-word spaces. The latter will not.

By default, the "blackout" is a thick \rule. To make it an underline (use Version 3.21 of censor, dated 30-JUL-13), I reset the parameters \censorruledepth and \censorruleheight.

\documentclass{article}
\usepackage{censor}
\censorruledepth=-.2ex
\censorruleheight=.1ex
%\StopCensoring
\begin{document}
An the answer is \xblackout{forty two}.

The beginning six words of the Gettysburg Address are \blackout{Four score and seven years ago}.
\end{document}

enter image description here

Uncommenting the \StopCensoring command will put your text back into the document, i.e., create the teacher's copy.

EDITED to reflect availability of V3.21 censor (bug fix) at at http://ctan.org/tex-archive/macros/latex/contrib/censor

6

Create a macro called \doBlank with two versions: one which replaces the argument with an underlined blank, and the other which leaves the argument unchanged. Then, to toggle between document versions we simply comment out one definition or the other:

Here is the teacher's version:

\documentclass[a4paper,12pt]{article}

%\newcommand{\doBlank}[1]{\underline{\phantom{#1}}}
\newcommand{\doBlank}[1]{#1}

\begin{document}

The last five words \doBlank{are replaced by a blank}.

\end{document}

Now for the student's version:

\documentclass[a4paper,12pt]{article}

\newcommand{\doBlank}[1]{\underline{\phantom{#1}}}
%\newcommand{\doBlank}[1]{#1}

\begin{document}

The last five words \doBlank{are replaced by a blank}.

\end{document}
3
  • 3
    This solution has the problem that it doesn't work if the text being replaced by the underline breaks across lines. And, for blanks intended to be filled by hand, one should probably make them larger than the printed version.
    – Jellby
    Commented Jul 29, 2013 at 9:07
  • Those are valid points Jellby, any suggestions on how to address those issues? Commented Jul 29, 2013 at 12:59
  • There's the package soul, which you can use for underlines across lines. As for the placeholder width, if it's for printing you could use white spaced-out text (also provided by soul). Otherwise, if I come up with a better idea I'll post an answer ;)
    – Jellby
    Commented Jul 29, 2013 at 14:40
5

My colleague and I have adapted this code from the eqexam package and used it for fill-in questions in examinations:

\newcommand{\fillin}[3][u]{  
%% #1= the box (u=underlined, e=empty, b=boxed) #2= space for the  
%% answer, #3= the correct answer  
\space  
    \ifx#1u\let\fillin@Fmt=\underbar%%% by default underlined space  
    \else\ifx#1e\let\fillin@Fmt=\relax%%% empty space  
    \else\ifx#1b\let\fillin@Fmt=\fbox%%% box  
    \fi\fi\fi  
     \fillin@Fmt{\parbox[b][.8\height][b]{#2}{%  
            \strut\hfil\fill@ans@color{#3}\hfil}%  
 }  
 }

We have tried to have the text of the answer splitted across lines, but it does not work. As in this command you can define the length of the blank space, the problem of the greater space to be filled by hand should be solved.

We will think about the possibility to split text across lines and we will post the solution if find it.

EDIT:

A part of the code missing in my previous answer. I apologize.

Here is a m.w.e. with the complete code:

\documentclass{article}  
\usepackage{calc} 

\newif \ifteacher  

\makeatletter  
    \ifteacher  
    \teachertrue  
    %\teacherfalse
    \def\fill@ans@color#1{\bfseries\color{red}{#1}}%%% with solutions  
    answers are in red by default  
    \else  
    \def\fill@ans@color#1{\phantom{#1}}%%% without solutions option -> no  
    answers
    \fi  

\newcommand{\fillin}[3][u]{  
%% #1= the box (u=underlined, e=empty, b=boxed) #2= space for the  
%% answer, #3= the correct answer  
\space  
    \ifx#1u\let\fillin@Fmt=\underbar%%% by default underlined space  
    \else\ifx#1e\let\fillin@Fmt=\relax%%% empty space  
    \else\ifx#1b\let\fillin@Fmt=\fbox%%% box  
    \fi\fi\fi  
    \fillin@Fmt{\parbox[b][.8\height][b]{#2}{%  
        \strut\hfil\fill@ans@color{#3}\hfil}%  
 }  
 }  
\makeatother  

\begin{document}  


2+4=\fillin{4cm}{6}  
\end{document}

If you want teacher version you have to uncomment the \teachertrue command, if you want student version you have to uncomment the other one.

EDIT 2

The switch \teachertrue or \teacherfalse must be put in the preamble. The above code should now work.

6
  • 1
    Could you please post a m.w.e of this code? I'm having trouble implementing it using the syntax \fillin{u}{8em}{my correct answer} Also, is there then an easy way to compile with the blanks replaced by the correct answers, for the teacher's copy (if used for lecture notes)? Commented Jul 30, 2013 at 8:16
  • A piece of the code was missing in my previous answer, I apologize. I edited the answer ad added the correct code in a m.w.e..
    – grames
    Commented Jul 30, 2013 at 23:04
  • 1
    When I compile your m.w.e. it blanks out the answer regardless of which of \teachertrue or \teacherfalse is commented out. Commented Jul 31, 2013 at 13:29
  • It is the position of the switch \teachertrue or \teacherfalse that is not correct. I updated the m.w.e. and added some explanation in the answer.
    – grames
    Commented Jul 31, 2013 at 16:48
  • OK, it still isn't working as is, but when I moved \teachertrue and \teacherfalse outside the control structure (i.e. above \ifteacher) then it does work. It is also necessary to add \usepackage{color} at the top. Thanks. Commented Aug 1, 2013 at 6:23
1

Answering a question on fr.comp.text.tex (see end of the discussion), Paul Isambert wrote some code using LuaTeX machinery (code links are now broken). At the time, we discussed that matter privately by email and Paul enhanced his code to fit my needs. He gave me the permission to post the resulting code (PAT = 'poly à trous', code commented in French, feel free to fork and/or commit).

From my point of view, one thing that is really interesting is that it avoids "orphan" blanks at the beginning of a line: if the blank at the beginning of a line is too small, then it is discarded. It is also robust enough to go through maths, texts and mixture of both.

It is a good example of how attributes can be used to do some "post processing" with LuaTeX.

\documentclass{article}

\usepackage{PAT,pgffor}

\def\test#1{%
  \foreach \i in {1,...,#1}{%
    test }}

\begin{document}

Test \trou{Test} Test

Test \trou{\test{20}} Test

Test \trou{$\displaystyle\int$ Test} Test

Test $\displaystyle \trou{\int_{0}^{t^2} x^2 dx}$ Test

Test $$\int_{0}^{\trou{t^{2}}} \frac{x^2}{\trou{2}} dx$$ Test

Test \trou{abc \par def} Test

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .