I am preparing cloze ("fill in the gaps") worksheets for my students. They contain texts with gaps that have to be filled in using words from a list below the text (either with or without duplicates). For obvious reasons the list should not be in the order of appearance in the text, so I would like to have it in alphabetical order.
I have copy-pasted (and slightly modified) some code found on this forum. I am really a very basic LaTeX user and don't understand that code in the slightest, but it seems to be working perfectly for me ... except for the order, which is chronological not alphabetical. Before using this code, which is based on /addmark
and /printmarks
, I had tried using index
and glossary
, but didn't manage to get them working the way I wanted to.
I don't know if this is likely to make any difference, but I use XeLaTeX and Japanese characters.
\documentclass{article}
\usepackage{xcolor}
\usepackage{framed}
\usepackage[parfill]{parskip}
\usepackage{xeCJK}
\usepackage{expl3}
\usepackage{xparse}
\definecolor{shadecolor}{RGB}{210,210,210}
\ExplSyntaxOn
\seq_new:N \g_khaurum_wordlist_seq
\NewDocumentCommand{ \addmark }{ m }{
\seq_gput_right:Nn \g_khaurum_wordlist_seq { #1 }
#1
}
\NewDocumentCommand{ \printmarks }{s}{
% \seq_gremove_duplicates:N \g_khaurum_wordlist_seq % removes duplicates
\seq_use:Nnnn \g_khaurum_wordlist_seq { ~ -- ~ } { ~ -- ~ } { ~ -- ~ }
\IfBooleanT { #1 } {
\seq_gclear:N \g_khaurum_wordlist_seq
}
}
\ExplSyntaxOff
%\newcommand\gap[1]{{\colorbox{white}{\textcolor{white}{#1}}}} %this makes a gap
\newcommand\gap[1]{{\colorbox{white}{\textcolor{red}{#1}}}} %this makes red letters
\begin{document}
\begin{snugshade*}
\begin{framed}
\begingroup\ttfamily
The marked \gap{\addmark{words}} should appear in \gap{\addmark{alphabetical}} order, not in the order they occur in.
\endgroup
\end{framed}
\end{snugshade*}
\printmarks
\end{document}