1

I am making some big documents for my students (around 200 pages). During the lessons, they have to fullfill some blanks (that helps to keep them awake).

Therefore, I need 2 versions of my documents, one with blanks for the students and one with everything filled for me.

I have some macro to do this. They do the job, but they are probably far from clean because I'm not an expert in LaTeX altough I progress every day.

Here is a code sample :

\documentclass[a4paper,11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage{ifthen}
\usepackage{lipsum}

\newcounter{ReplicateCount}
\newcommand{\Replicate}[2]{ %repeats #2 as many times as #1
    \setcounter{ReplicateCount}{#1}
    \whiledo{\value{ReplicateCount}>0}
    {#2\addtocounter{ReplicateCount}{-1}}
}
\newcommand{\hide}[2]{
    \ifthenelse{\equal{\edition}{E}}{
        ~\Replicate{#2}{ 
        \pagebreak[3]\vspace*{1cm}}
    }
    {
        #1
    }
}

\begin{document}

\def\edition{P}
\hide{\lipsum}{3} %will produce \lipsum

\def\edition{E}
\hide{\lipsum}{3} %will do \hspace*{3cm}, on 2 subsequent pages if   necessary

\end{document}

It works this way, at the beginning of my document, I decide which value to set to my variable \edition, and I just have one character to change to switch from student version to teacher version.

But here is my problem : of course, I need to leave more blanks on student version than the place it actually takes on my version. Therefore, the versions have different page numbers and this is unhappy. I would like that my version takes the exact same space than students (even if it leaves a blank at the end of every \hide call). I guess it would require a function that computes how much place a text actually takes on the printed version to adapt it. Also, I would like the macro to be working even if the hidden text is on 2 different pages.

Does anybody have an idea of how to make this work ? Thanks in advance for the help and hoping I could be sufficiently clear and apologizing in advance for my English, Im not native speaker ;-)

Hercule

  • If you hand it out in print, then you can make a teacher version with the text in black with some space below, and for the student version the same text in white (i.e., invisible in print, but selectable/copyable on screen) with the same space below. – Marijn Apr 05 '18 at 12:54

2 Answers2

0

What you might try is not so much hide the text for the students, but print it in white or (even better, but dependent on printer support) transparent. In that case, I'd print the teacher version in gray or with a mark in the margin.

If you want more space than occupied by the text, why not print it twice (you have the text block as an argument to the macro)? For the students, both would be printed white, for the teacher one will be gray and the other white (so invisible). As you "print" in both cases the exact same text, page numbers will be the same.

\documentclass[a4paper,11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage{ifthen}
\usepackage{lipsum}
\usepackage{color} % to use colours

\definecolor{gray}{rgb}{0.35,0.35,0.35} % color for teacher-only material

\newcommand{\hide}[1]{
    \ifthenelse{\equal{\edition}{E}}{   
        \color{white}
        #1

        #1
        \color{black}
    }
    {
         \color{gray}
        #1

         \color{white}      
        #1
        \color{black}
      }
}

\begin{document}
\lipsum[1]
\def\edition{P}
\hide{\lipsum[3]}
\lipsum[1]
\clearpage

\lipsum[1]
\def\edition{E}
\hide{\lipsum[3]}
\lipsum[1]

\end{document}

Note: not tested for the case where the teacher-only material flowes over to the next page.

remco
  • 1,017
0

I would use \phantom to hide the content, \makebox to increase the width and \rule to increase the height. To switch between the student and the master edition I would \let a control sequence to either \phantom (for hiding the argument) or \relax (which does nothing and would therefore not prevent the argument to be displayed) depending on the value of a flag. To switch between the editions comment or uncomment the line \StudentEditiontrue.

\documentclass{article}

\newif\ifStudentEdition

%\StudentEditiontrue


\ifStudentEdition
    \let\hiddenInStudentVersion=\phantom
\else
    \let\hiddenInStudentVersion=\relax
\fi

\newcommand{\hide}[1]{%
    \makebox[2\width][c]{%
        \rule{0pt}{2em}%
        \hiddenInStudentVersion{#1}%
    }%
}

\begin{document}
hello \hide{beautiful} world
\end{document}

Please note that this does not allow line or even page breaks.

jakun
  • 5,981
  • Thanks for the answer. The issue being I really need things on more than 1 page. Some of my exemples clearly require a page break, so I looked at phantom but it didn't seem good for my purpose. – HerculePoivrot Apr 05 '18 at 14:02