2

I'm looking for a macro (or perhaps a package?) that would support "fill in the missing word(s)” questions.

I started with

\def\missingword#1{#1}
\def\missingword#1{\rule[-2pt]{5cm}{.1pt}}

Di \missingword{dov'è} sei?

and got

enter image description here

at “first compilation” and for the answers, I could recompile with the second definition inactivated. However, it would be nice if LaTeX could calculate the space needed for “dov'è” in the current typeface and font size and multiply by a factor to support “handwriting needs more space than typography” so it wouldn’t be a static length like the sample above and also “give a hint” about the answer's length/complexity. TIA.

PS. I just discovered a typo; it should be only “dove”, not “dov'è”. Sorry about that for all of you who speak Italian.

7
  • 4
    Have a look at ctan.org/pkg/dashundergaps (beware that ctan is running a special halloween theme today, don't get scared) Commented yesterday
  • 1
    IMO,maybe also have a look at cloze package at: ctan.org/search?phrase=cloze Commented yesterday
  • BTW: Don't use \def in LaTeX (if you don't really need it and know what you are doing). Commented yesterday
  • @cabohah OK! I did not know what. What is the main reason? Commented yesterday
  • @samcarter_is_at_topanswers.xyz Anyone who isn't terrified by expl3 is unlikely to be scared by a Halloween theme! Commented 21 hours ago

2 Answers 2

4

Give cloze a try:

\documentclass{article}
\usepackage{cloze}% it need lualatex
\clozeset{text_color=black}
\clozesetfont{\normalfont}
\parindent=0pt
\begin{document}

Hello \cloze{this is the answer} World!

You can also use \texttt{spread} to achieve what you want.

Hello \cloze[spread=1.2]{this is the answer} World!

Lorem \cloze[text_color=magenta]{ipsum} dolor sit amet, consetetur \cloze[width=10cm]{sadipscing elitr, sed diam nonumy eirmod tempor} invidunt ut \cloze[thickness=2pt,hide]{labore} et dolore \cloze[margin=1em]{magna aliquyam erat} , sed diam voluptua.
 
\end{document}

result

3

If you don't need line breaks in the missing text, you can use \phantom and a tabular:

\documentclass{article}
\newcommand*{\missingword}[1]{\begin{tabular}{@{}l@{}}\phantom{#1}\\\hline\end{tabular}}
\begin{document}
\raggedright

Di \missingword{dov'è} sei?

\smallskip

Di dov'è sei?

\end{document}

tabular as missing text

or something like \uline instead of a tabular:

\documentclass{article}
\usepackage[normalem]{ulem}
\newcommand*{\missingword}[1]{\uline{\phantom{#1}}}
\begin{document}
\raggedright

Di \missingword{dov'è} sei?

\smallskip

Di dov'è sei?

\end{document}

With almost the same result.

As an alternative, i.e. if you need a factor, you can indeed measure the text width \settolength:

\documentclass{article}

\newlength{\missingwordlength}
\newcommand*{\missingword}[2][1]{%
  \settowidth{\missingwordlength}{#2}%
  \rule[-2pt]{#1\missingwordlength}{.1pt}}

\begin{document}
\raggedright

Di \missingword{dov'è} sei?

\smallskip

Di dov'è sei?

\smallskip

Di \missingword[2.5]{dov'è} sei? (Factor: 2.5)

\end{document}

rule as missing word

or use package calc:

\documentclass{article}

\usepackage{calc}

\newcommand*{\missingword}[2][1]{\rule[-2pt]{\widthof{#2}*#1}{.1pt}}

\begin{document}
\raggedright

Di \missingword{dov'è} sei?

\smallskip

Di dov'è sei?

\smallskip

Di \missingword[5/2]{dov'è} sei? (Factor: 2.5)

\end{document}

with the same result.

2
  • support "linebreak"(?) Commented yesterday
  • 1
    @Explorer Some users want several words instead of a single word and then also want automatic line breaks of the underlined space. Commented yesterday

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.