I have a kind of learning document with exercises. In this document I have texts with gaps. The gaps are currently filled by dots. I am using the following commands for this purpose:
\newcommand{\gapunit}{.....}
\newcommand{\tinygap}{\gapunit}
% ===== EGREG VARIANT =====
\makeatletter
\newcount\my@repeat@count% initialize a new counter for the loop
\newcommand{\myrepeat}[3]{% new command with 2 arguments
\begingroup% using a group here allows nested calls
\my@repeat@count=1% initialize at 1, so that there are argument - 1 iterations and the last iterations doesn't have a separator following it
\@whilenum\my@repeat@count<#1\do{#2#3\advance\my@repeat@count1}#2% as long as the iteration count is smaller than the argument, advance, meaning that the counter will be increased by 1
\endgroup%
}
\makeatother
\newcommand{\shortgap}{%
\myrepeat{3}{\gapunit}{\ }
}
\newcommand{\mediumgap}{%
\myrepeat{5}{\gapunit}{\ }
}
\newcommand{\longgap}{%
\myrepeat[10]{\gapunit}{\ }
}
Now I want to add solutions to the PDF which I compile. I thought maybe I could add white text, which I write on top of the dots (want to have the dots and the white text) to add solutions. I am quite OK with the idea, that someone could highlight white text to read it. In the end either someone "cheats themselves" or really learns something.
But how can I write white text on top of the gaps?
If there is a not too complicated better way of getting solutions into my PDF, I am open to ideas as well. I just don't want to lose the gap dots and don't want to add pages of code to my template, to get something super fancy, when actually white text is totally sufficient : )
Good would be a solution, which figures out the background color used by the document somehow, so that it does not have to be set in stone to be white.
Here is the document on GitHub, in case I am too vague about the gaps thing or something: repo
Edit
I am using Andrew's solution in a slightly modified way:
\newlength\blankblanklength
\newlength\blanktextlength
\newlength\blankcenterindentation
\newcommand\BlankText[2][]{%
% do some length calculations for text length
\if\relax\detokenize{#1}\relax%
\settowidth{\blanktextlength}{#2}%
\else%
\setlength\blanktextlength{#1}%
\fi% calculate width of text
\rlap{\makebox[\blanktextlength][c]{\textcolor{white}{#2}}}% write the text without moving, centered in a box
\raisebox{-0.5ex}{\hbox to \blanktextlength{\dotfill}}% add dots to cover text
}
\newcommand{\ShortBlankText}[1]{%
\BlankText[2cm]{#1}
}
\newcommand{\MediumBlankText}[1]{%
\BlankText[3.2cm]{#1}
}
\newcommand{\LongBlankText}[1]{%
\BlankText[4.4cm]{#1}
}

xsim's\blankcommand? – cgnieder Oct 16 '17 at 09:50\usepackage{xcolor}you can use\textcolor{white}{solution text}to write white text. – Oct 16 '17 at 10:29\blankwill do two things: it will set the linespread according to an option explained below and will insert\parafter the lines. The starred version doesn’t do these things." – Does not sound like having placeholder dots plus something invisible. I don't think this is a solution for me. – Zelphir Kaltstahl Oct 16 '17 at 11:36\llap{...}or\rlap{...}. I'll add an example solution. – Oct 16 '17 at 12:33xsiminto my installed packages. So I think your hint is very good, just not practical for me at this very moment. – Zelphir Kaltstahl Oct 16 '17 at 20:24