5

I am about to improve my lecture slides from last semester. Specifically, I would like to add a fill-in-the-blank option. I found this code suggestion (from here):

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

I think that will be a very good method (Thank you Steven B. Segletes). However, I believe that a little bit of fine tuning could tremendously improve the learning experience of my students. So here is what I am looking for:

In the non-blackout version of my document (presentation), I would like the text (that is blacked out for the students) to appear in color (say blue).

I believe that this would allow my audience to follow my talks much better, since no effort is wasted on determining which parts (from the presentations) have to be manually copied and which not - an additional visual cue.

My thought is:

From the Censor Documentation I realize that I can use \StopCensoring and \RestartCensoring for switching between output options. How can I use the same switch to evoke colors. Something like:

\ifx{\RestartCensoring=True} 
\then{\renewcommand{\blackout}[][text=blue]{\blackout}} 
\else{Do noting} 
\fi

I am certain that the syntax of my if statement is incorrect, but since I am not sure how to implement this "little trick", this is all I got at the moment. Any help or totally different approaches are very welcome. Thanks guys!

Raphael
  • 308
  • 2
    Why not simply add \renewcommand\blackout[1]{\textcolor{red}{#1}} at the end of the preamble to compile your presentation without becoming entangled in conditionals? For the student version you only need add a % at the beginning of this line to restore the original \blackout command. – Fran Jan 05 '15 at 07:46
  • You can have a look at PAT. It uses the attribute mechanism from luatex (credit goes to Paul Isambert). – cjorssen Jan 05 '15 at 12:13
  • Thanks @Fran that seems to make more sense than my original suggestion. However, Steven B. Segletes provided a solution below that seems "more complete" in view of the Censor Package. – Raphael Jan 06 '15 at 02:24
  • Thanks @cjorssen , I appreciate the input, but Steven B. Segletes provided a smooth solution below. – Raphael Jan 06 '15 at 02:25

2 Answers2

5

Perhaps something like this (EDITED to provide capability for \censorboxes as well):

\documentclass{article}
\usepackage{censor,xcolor}
\censorruledepth=-.2ex
\censorruleheight=.1ex
\makeatletter
\renewcommand\StopCensoring{%
           \def\censor##1{\textcolor{blue}{##1}}%
           \def\censorbox##1{\bgroup\color{blue}\un@censorbox{##1}\egroup}%
           \let\xblackout\blackout%
}
  \renewcommand\censor@box[2][]{\fboxsep=0pt\fbox{\color{white}%
                      #1\setbox0\hbox{#2}%
                      \rule[-\the\dp0]{\the\wd0}{\the\ht0+\the\dp0}}}
\makeatother
\begin{document}
And the answer is \censor{forty two}.
\StopCensoring

And the answer is \censor{forty two}.
\RestartCensoring

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

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

The tabular answer is 
\censorbox{\begin{tabular}{|c|c|}\hline a & b\\ \hline\end{tabular}}
\StopCensoring

The tabular answer is 
\censorbox{\begin{tabular}{|c|c|}\hline a & b\\ \hline\end{tabular}}
\end{document}

enter image description here

  • Thank you Steven! This solution works perfectly. I am using different "Output Options" (Presentation, Presentation With Note Slides, Handout, Beamerarticle). For my Presentations, I placed the \StopCensoring command in the preamble, and now it automatically produces the blue text. In the handout and article, it leaves the blanks (since it is the censored version). – Raphael Jan 06 '15 at 02:19
  • Can I mark this as "The Solution" so that other users know that the original question has been answered (to the satisfaction of the questioner)? – Raphael Jan 06 '15 at 02:31
  • @Raphael To mark a preferred answer as the "accepted" solution, you click on the check mark in the left column next to that answer. After considering all the given answers, you should try to make a point to accept the best answer for any given question that you ask on this forum. (if you later change your mind, you can even unaccept an answer and accept another, though this is somewhat rare). – Steven B. Segletes Jan 06 '15 at 02:51
  • @Seven B. Segletes Your solution works great and I already updated all my presentations. It seems that the students really like/love it. Thanks – Raphael Jan 18 '15 at 23:03
  • @ Steven B. Segletes I do have one follow up question though. When I compile the uncensored version everything works out, even if I use the \censor command within an equation or align environment. But if I compile the censored (student) version, the command does not work with (parts of) equations. Maybe it has something to do with the underline it tries to draw, but I am not sure. I already tried your solution (\mblackout) from here (http://tex.stackexchange.com/questions/135453/hiding-part-of-text-leaving-blank-space) but with out any success. – Raphael Jan 18 '15 at 23:12
  • @Raphael I would not expect \censor to work across align tabs &, though I think the \mblackout should be workable if you are not extending its argument across a & or a \\. – Steven B. Segletes Jan 19 '15 at 01:56
  • @Raphael For some reason, the \mblackout you cite in my other answer breaks with \usepackage{amsmath}. I have not yet determined why. – Steven B. Segletes Jan 19 '15 at 04:39
  • @Raphael \frac is redefined by amsmath in a way which breaks \mblackout. This "fix" will allow amsmath to be loaded in the cited answer: \let\svfrac\frac\usepackage{amsmath}\let\frac\svfrac but I don't know what it might break inside of amsmath. – Steven B. Segletes Jan 19 '15 at 04:46
  • @ Steven B. Segletes Thanks for your answers and for providing the "fix". I will play around with that and see where it will get me. I'll keep you posted. – Raphael Jan 20 '15 at 02:30
  • Okay. I am happy but confused. I got everything to work (I think), but I am not 100% sure if I understand... In my preamble, I defined \mblackout and I added the "amsmath line". Now, is it correct, that for every math expression censoring (or parts of it), I must use \mblackout ? I also had partial luck using \censor with brackets as you suggested (http://tex.stackexchange.com/questions/202385/why-does-using-the-amsmath-package-break-the-following-code), but that also fails sometimes. So I am unable to recognize a pattern and not sure what to use from now on (futureproof?). – Raphael Jan 20 '15 at 05:27
  • @Raphael I had forgotten that answer. However, I am still not sure that I can propose a general workaround that makes \mblackout work in all cases. But I will continue to think about it. But yes, censor was not designed for math, and so \mblackout was the best I could do to accommodate it. – Steven B. Segletes Jan 20 '15 at 11:55
  • 1
    Steven B. Selgetes Thanks for your response and all the work you do. I would like to make sure that you know that all my comments here are not complaints or anything like that. In fact, it is amazing what your tools (and all the other LaTeX tools) allow me to do. Sometimes I just try to find the silver bullet (to avoid extra/double work), although it is already a "high value solution". However, thank you for all your work and efforts. If you find an "ultimate solution", I will be happy to know. But also, I am already happy with what I can do so far. THANKS so much! – Raphael Jan 20 '15 at 20:25
  • @Raphael You are most welcome. I am happy to see a solution be applied for practical use. – Steven B. Segletes Jan 20 '15 at 20:35
  • B. Selgetes I really like the power of my handouts not, but I noticed that the "fill-in-the-blank-lines" are a little to intense and I would like "tone down" the color (maybe light gray) and use a dashed line. So I tried to use the 'dashrule package' and implement the command \renewcommand\censorrule[1]{\protect\hdashrule[-0.3mm]{#1}{0.1pt}{1pt 5pt}} but it gives me an error and I do not understand why. Could you provide further assistant? And possibly make it work for the \mblackout and \blackout command? I would highly appreciate it – Raphael Apr 20 '15 at 02:51
  • @Raphael \censor, \blackout, and \xblackout can all be color-corrected with the redefinition, \renewcommand\censorrule[1]{\protect\textcolor{black!20}{\rule[\censorruledepth]{#1}{\censorruleheight}}}, for example. The \censorruleheight length can be made smaller to make the underline less prominent. I would have to spend a bit more effort to try to understand properly the interactions of dashrule and censor packages that make it incompatible. So perhaps the color change and rule thinning would suffice... – Steven B. Segletes Apr 20 '15 at 10:54
  • B. Selgetes Thanks for your quick response. I really appreciate your support! I used the \censorruleheight command to reduce the line thickness and it produces very nice results (although a dotted line would be awesome). The color correction also works, but for some reason, it won't work for equations (math environment) using the \mblackout command. I would assume that I have to adjust this part of my code: \newcommand\mblackout[2][\dp\strutbox]{% \let\@cenword\m@cenword% \def\mcensorruledepth{#1}% \blackout{{#2}}% \let\@cenword\sv@cenword% } But I am uncertain how. – Raphael Apr 21 '15 at 04:06
  • Interestingly, If I set \censorruleheight to zero, the line does disappear for both (including the math environment). – Raphael Apr 21 '15 at 04:17
  • @Raphael For the math censor, it is \m@cenword that needs redefining: \newcommand\m@cenword[1]{\ThisStyle{% \textcolor{black!20}{\stackengine{\mcensorruledepth}{$\SavedStyle\phantom{#1}$}% {\rule{\widthof{$\SavedStyle#1$}}{\the\censorruleheight}}{U}{c}{F}{T}{L}}}}. You will also need to load the scalerel and stackengine packages. – Steven B. Segletes Apr 21 '15 at 10:40
  • Works perfectly!… Thank you soooo much. I honestly don't understand, why that also fixed the thickness of the line (since the only change from my original version is the \textcolor comannd), but I am very happy that it works now. Thanks. My students (and I) will appreciate your help once again ;-) – Raphael Apr 21 '15 at 22:55
  • Sadly, after updating to Version 4.2 of the Sensor Package, the line \newcommand\m@cenword[1]{\ThisStyle{% \textcolor{black!20}{\stackengine{\mcensorruledepth}{$\SavedStyle\phantom{#1}$}% {\rule{\widthof{$\SavedStyle#1$}}{\the\censorruleheight}}{U}{c}{F}{T}{L}}}} now produces an error (Missing delimiter). Would you know how I can fix that? – Raphael Mar 06 '23 at 17:16
2

You can simply redefine \blackout and \xblackout. (We suppose that color or xcolor package is loaded).

\def\xblackout{\textcolor{blue}}  \let\blackout=\xblackout
wipet
  • 74,238
  • Thanks for tip @wipet. I decided to go with Steven B. Segletes code suggestion, since it allows me evoke other commands provided by the censor package. But thanks anyways. – Raphael Jan 06 '15 at 02:28