9

Apologies for the very long title.

I'm writing a "fill in the missing words" document. I have made a makro \fjern{} ("remove" in Norwegian) which underlines the argument and places it in a phantom environment.

Questions:

  1. In the provided MWE I get a nasty overfull hbox. Is there a way that I can avoid this without going raggedright on the entire document?
  2. I would like to print all the words I have removed in a random order, preferably with an option to print, or not to print, words occurring several times (differentiation for the students). How can I do this? I have absolutely no clue... (it would be absolutely awesome if a solution option could print the removed words in the correct places, highlighted somehow)

MWE:

\documentclass[12pt, a4paper, norsk]{article}

\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage{fouriernc}
\usepackage[margin=1in]{geometry}

\usepackage{parskip}

\newcommand\fjern[1]{\underline{\phantom{#1}}}

\begin{document}
\section*{Vokabular} % (fold)
\label{sec:vokabular}

\LARGE Et \fjern{atom} består av \fjern{protoner} og \fjern{nøytroner} i kjernen, med \fjern{elektroner} som kretser rundt. \fjern{Protoner} har en positiv ladning, \fjern{nøytroner} er nøytralt ladet og \fjern{elektroner} har en negativ ladning. 
% Print the removed words
\vspace{4em}
\textbf{Sett inn ordene:} atom, protoner, nøytroner, elektroner

% section vokabular (end)
\end{document}

producing

enter image description here

1
  • If you had not marked the word it would have hyphenated and split over the line. You could do that here (eg using soul or ulem) but would be pretty confusing. If you don't split the word the options are to make the line shorter so it fits (presumably subject to some minimum) or to bring it down and stretch the short line or bring it down and leave the short line ragged. – David Carlisle Oct 7 '13 at 10:44
9

I'd give the “fillin” rules some stretchability:

\documentclass[12pt, a4paper, norsk]{article}

\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage{fouriernc}
\usepackage[margin=1in]{geometry}

\usepackage{parskip}

%\newcommand\fjern[1]{\linebreak[2]\underline{\phantom{#1}}}
\newcommand\fjern[1]{%
  \sbox0{#1}%
  \hspace*{0pt}\leaders\hrule height 0pt depth 1pt\hskip\wd0 plus 2em\relax\mbox{}}

\begin{document}
\section*{Vokabular} % (fold)
\label{sec:vokabular}

{\LARGE Et \fjern{atom} består av \fjern{protoner} og \fjern{nøytroner}
i kjernen, med \fjern{elektroner} som kretser rundt.
\fjern{Protoner} har en positiv ladning, \fjern{nøytroner}
er nøytralt ladet og \fjern{elektroner} har en negativ ladning.\par}

% Print the removed words
\vspace{4em}

\textbf{Sett inn ordene:} atom, protoner, nøytroner, elektroner

% section vokabular (end)
\end{document}

enter image description here

With \hspace*{0pt} the following leaders won't disappear at the start of a line, because they follow glue. The final \mbox{} avoids them disappearing at the end of a line.


Here is a version that automatically shuffles the words. Only limitation: the words should be given all in lowercase; one can think to a not too much invasive syntax for allowing case variations.

\documentclass[12pt, a4paper, norsk]{article}

\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage{fouriernc}
\usepackage[margin=1in]{geometry}

\usepackage{parskip}
\usepackage{xparse}
\input{random}

\NewDocumentEnvironment{fillin}{}
 {\par\LARGE}
 {\par\bigskip\printremoved\par}

\ExplSyntaxOn
\NewDocumentCommand{\fjern}{O{2em}m}
 {
  \holene_fjern:nn { #1 } { #2 }
 }
\NewDocumentCommand{\printremoved}{ }
 {
  \holene_print_removed:
 }

\seq_new:N \l_holene_removed_words_seq
\seq_new:N \l_holene_shuffled_words_seq
\tl_new:N \l_holene_word_tl
\int_new:N \l_holene_random_int

\cs_new_protected:Npn \holene_fjern:nn #1 #2
 {
  \seq_put_right:Nn \l_holene_removed_words_seq { #2 }
  \sbox0{#2}%
  \hspace*{0pt}
  \leaders\hrule height 0pt depth 1pt\hskip\wd0 plus #1\scan_stop:
  \mbox{}
 }
\cs_new_protected:Npn \holene_print_removed:
 {
  \textbf{Sett~inn~ordene:~}
  \holene_shuffle:
  \seq_use:Nn \l_holene_shuffled_words_seq { ,~ }
 }
\cs_new_protected:Npn \holene_shuffle:
 {
  \int_compare:nF
   { \seq_count:N \l_holene_removed_words_seq = 0 }
   { \holene_get_random: \holene_shuffle: }
 }
\cs_new_protected:Npn \holene_get_random:
 {
  \setrannum { \l_holene_random_int }
    { 1 } { \seq_count:N \l_holene_removed_words_seq }
  \tl_set:Nx \l_holene_word_tl 
   { \seq_item:Nn \l_holene_removed_words_seq { \l_holene_random_int } }
  \seq_remove_all:NV  \l_holene_removed_words_seq \l_holene_word_tl
  \seq_put_right:NV \l_holene_shuffled_words_seq \l_holene_word_tl
 }
\cs_generate_variant:Nn \seq_remove_all:Nn { NV }
\cs_generate_variant:Nn \seq_put_right:Nn { NV }
\ExplSyntaxOff

\begin{document}
\section*{Vokabular} % (fold)
\label{sec:vokabular}

\begin{fillin}
Et \fjern{atom} består av \fjern{protoner} og \fjern{nøytroner}
i kjernen, med \fjern{elektroner} som kretser rundt.
\fjern{protoner} har en positiv ladning, \fjern{nøytroner}
er nøytralt ladet og \fjern{elektroner} har en negativ ladning.
\end{fillin}

% section vokabular (end)
\end{document}

Here's an instance

enter image description here

4
  • "great minds think alike" or something:-) +1 for being a bit quicker than me – David Carlisle Oct 7 '13 at 11:25
  • 1
    @DavidCarlisle Yes, but greater minds can also randomize the words. ;-) – egreg Oct 7 '13 at 12:18
  • Nice! But I'm not able to compile the last MWE... Get 24 errors associated with line 20:Illegal parameter number in definition of \fjern code }. Is it something I need to install to make it work? – Holene Oct 7 '13 at 12:39
  • @Holene Sorry, pasted the wrong version. Fixed. – egreg Oct 7 '13 at 13:42
5

This uses leaders so the underline can stretch or shrink .2 of the target width and has extra stretch white space before:

enter image description here

\documentclass[12pt, a4paper, norsk]{article}

\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage{fouriernc}
\usepackage[margin=1in]{geometry}

\usepackage{parskip}

\newcommand\fjern[1]{\leavevmode\sbox0{#1}%
\hskip0pt plus 1em
\hbox{}%
\nobreak
\leaders
\vbox{\kern.1ex\hrule width 1pt height 1pt\kern-.1ex}%
\hskip\wd0 plus.2\wd0 minus.2\wd0
\penalty0 }

\begin{document}
\section*{Vokabular} % (fold)
\label{sec:vokabular}

\LARGE Et \fjern{atom} består av \fjern{protoner} og \fjern{nøytroner} i kjernen, med \fjern{elektroner} som kretser rundt. \fjern{Protoner} har en positiv ladning, \fjern{nøytroner} er nøytralt ladet og \fjern{elektroner} har en negativ ladning. 

% Print the removed words ALWAYS have a blank line before \vspace!
\vspace{4em}
\textbf{Sett inn ordene:} atom, protoner, nøytroner, elektroner

% section vokabular (end)
\end{document}
4

Here is a version that uses my exsheets package and its \blank command with an extension to print the list of words to be filled in. The entries to be filled in are not shuffled but ordered alphabetically, though.

exsheets does not have Norsk translations for its headings, yet, so I used what a quick web search revealed... I'll add the correct ones to exsheets if you tell me which ones they are.

enter image description here

\documentclass[12pt, a4paper, norsk]{article}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage{fouriernc}
\usepackage[showframe,margin=1in]{geometry}

\usepackage{exsheets}
\SetupExSheets{
  headings-format = \bfseries
}

% no idea if those translations are correct:
\DeclareTranslation{Norsk}{exsheets-exercise-name}{Utøve}
\DeclareTranslation{Norsk}{exsheets-question-name}{Problemet}
\DeclareTranslation{Norsk}{exsheets-solution-name}{Oppløsning}


\usepackage{parskip}

\usepackage{expl3,l3sort}
\ExplSyntaxOn
\seq_new:N \g_holene_fillin_list_seq
\cs_new_protected:Npn \holene_addto_fillin_list:n #1
  {
    % \tl_to_lowercase:n ensures that entries are added lowercase only; this
    % means however, that you have to use \o instead of ø inside of \fjern,
    % probably other special characters need to be treated similarly.  (I
    % haven't checked the reason for this...)
    \tl_to_lowercase:n {
      \seq_gput_right:Nn \g_holene_fillin_list_seq {#1}
    }
  }

\NewDocumentCommand \fjern { m }
  {
    \IfInsideQuestionT
      { \holene_addto_fillin_list:n {#1} }
    \blank {#1}
  }

\cs_new_protected:Npn \holene_write_fillins:
  {
    \textbf{Sett~ inn~ ordene:}~
    % remove duplicate entries:
    \seq_remove_duplicates:N \g_holene_fillin_list_seq
    % and sort alphabetically:
    \seq_sort:Nn \g_holene_fillin_list_seq
      {
        % \tl_to_lowercase:n ensures that uppercase and lowercase variants are
        % treated the same when ordered (unnecessary when it is used in
        % \holene_addto_fillin_list:n already):
        % \tl_to_lowercase:n {
          \int_compare:nTF { \pdftex_strcmp:D { ##1 } { ##2 } = -1 }
            { \sort_ordered: }
            { \sort_reversed: }
        % }
      }
    \seq_use:Nnnn \g_holene_fillin_list_seq
      { ,~ }
      { ,~ }
      { ,~ }
    \seq_gclear:N \g_holene_fillin_list_seq
  }

\NewDocumentCommand \printfillins { }
  { \holene_write_fillins: }
\ExplSyntaxOff

\begin{document}
\LARGE


\section*{Vokabular} % (fold)
\label{sec:vokabular}
\begin{question}
  Et \fjern{atom} består av \fjern{protoner} og \fjern{n\o ytroner} i kjernen,
  med \fjern{elektroner} som kretser rundt. \fjern{Protoner} har en positiv
  ladning, \fjern{n\o ytroner} er nøytralt ladet og \fjern{elektroner} har en
  negativ ladning.\par
  \printfillins
\end{question}

\begin{solution}[print]
  Et \fjern{atom} består av \fjern{protoner} og \fjern{n\o ytroner} i kjernen,
  med \fjern{elektroner} som kretser rundt. \fjern{Protoner} har en positiv
  ladning, \fjern{n\o ytroner} er nøytralt ladet og \fjern{elekt\-roner} har en
  negativ ladning.
\end{solution}

% section vokabular (end)
\end{document}
5
  • This is very nice! Exercise = oppgave, solution=løsning =) You'll need utf8 for the funky non-ascii letters æ,ø,å. – Holene Oct 7 '13 at 19:27
  • @Holene There's »Exercise« (German: »Übung«), »Question« (German: »Aufgabe«) and »Solution«. If »Exercise« is »oppgave« what is »Question«? BTW: I did use utf8 (I always do)... – cgnieder Oct 7 '13 at 19:32
  • "Question" is "spørsmål", but it could also be "oppgave". Depends on the setting. More like: I give you an exercise/task (oppgave), but I ask you a question (spørsmål). – Holene Oct 7 '13 at 19:58
  • @Holene The sense behind is the following: exsheets-exercise-name is used for exercise sheets and exsheets-question-name in exams. Are both the same in Norwegian (oppgave)? – cgnieder Oct 7 '13 at 20:15
  • Yes, I would write "oppgave" for both. In exams in Norwegian you could use both, but I've mostly seen "oppgave", not "spørsmål" (question). In English you would use "problem", which would be "oppgave" in that context – Holene Oct 7 '13 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.