% \iffalse meta-comment
%
% Copyright (C) 2015-2020 by Josef Friedrich <josef@friedrich.rocks>
% ----------------------------------------------------------------------
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, either version 1.3 of this license
% or (at your option) any later version.  The latest version of this
% license is in:
%
%   http://www.latex-project.org/lppl.txt
%
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Josef Friedrich.
%
% This work consists of the files cloze.dtx and cloze.ins
% and the derived filebase cloze.sty and cloze.lua.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{cloze.dtx}
%</driver>
%<latex>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<latex>\ProvidesPackage{cloze}
%<*latex>
    [2020/06/60 v1.6 Package to typeset cloze worksheets or cloze tests]
%</latex>
% \fi
%
% \CheckSum{0}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{v0.1}{2015/06/16}{Converted to DTX file}
%
% \changes{v1.0}{2015/07/08}{Inital release}
%
% \changes{v1.1}{2016/06/13}{Make cloze compatible to LuaTeX version
% 0.95}
%
% \changes{v1.2}{2016/06/23}{The cloze makros are now working in
% tabular, tabbing and picture environments}
%
% \changes{v1.3}{2017/03/13}{Add the new macros \cmd{\clozenol} and
% \cmd{\clozeextend} and the environments \texttt{clozebox} and
% \texttt{clozespace} (This version was not published on CTAN.)}
%
% \changes{v1.4}{2020/05/20}{Add the new macro \cmd{\clozestrike} and
% improve the documentation}
%
% \changes{v1.5}{2020/05/27}{
% * The Lua part of the package (cloze.lua) is now being developed in a
% separate file.
% * The readme file is now a standalone mardown file and not embedded in
% the dtx file any more.
% * \href{https://github.com/stevedonovan/LDoc}{LDoc} is being used
% to generate
% \href{https://josef-friedrich.github.io/cloze}{source code documentation}.
% * This version fixes two bugs (cloze in display math, line color and
% hide).
% }
%
% \changes{v1.6}{2020/06/30}{
% * Implement basic plain \TeX{} respectively plain Lua\TeX{} interface.
% * Fix issue: Duplicate line generation on the second line in cloze.
% * Fix issue: width of first line wrong in itemize, mdframed.
% * Fix issue \#4: \texttt{\string\clozenol} not transparent.
% * Fix issue: \texttt{clozebox} not transparent.
% }
%
% \DoNotIndex{\newcommand,\newenvironment,\def,\directlua}
%
% \StopEventually{}
% \pagebreak
% \section{Implementation}
%
% \iffalse
%<*plaintex>
% \fi
% \MacroTopsep = 10pt plus 2pt minus 2pt
% \MacrocodeTopsep = 10pt plus 1.2pt minus 1pt
%
% \makeatletter
% \c@CodelineNo 25 \relax
% \makeatother
%
% \subsection{The file \tt{cloze.tex}}
%
% The cloze package uses following naming conventions: Internal / private
% macros / commands / envirnoments are written in PascalCase, public
% ones are written in lowercase. Earlier versions of this package used
% @ characters for private macros. The lower level / private macros
% are now defined in the plain Lua\TeX{} version of the package and
% used to set cloze text in plain Lua\TeX{}.
%
%    \begin{macrocode}
\directlua{
  cloze = require('cloze')
}
%    \end{macrocode}
%
%    \begin{macrocode}
\newif\ifclozeshow\clozeshowtrue
%    \end{macrocode}
%
% \subsubsection{Internal macros}
%
% \begin{macro}{\ClozeSetToGlobal}
% Set the Lua variable |registry.is_global| to |true|. All options
% are then stored in the variable |registry.global_options|.
%    \begin{macrocode}
\def\ClozeSetToGlobal{%
  \directlua{cloze.set_is_global(true)}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ClozeSetToLocal}
% First unset the variable |registry.local_options|. Now set the Lua
% variable |registry.is_global| to |false|. All options are then stored
% in the variable |registry.local_options|.
%    \begin{macrocode}
\def\ClozeSetToLocal{%
  \directlua{
    cloze.unset_local_options()
    cloze.set_is_global(false)
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ClozeGetOption}
% This macro is used in the documentation to show the default values
% of some options.
%    \begin{macrocode}
\def\ClozeGetOption#1{%
  \directlua{
    tex.print(cloze.get_value('#1'))
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ClozeColor}
% Convert a color definiton name to a PDF colorstack string, for example
% convert the color name |blue| to the colorstack string
% |0 0 1 rg 0 0 1 RG|. The macro definition |\ClozeColor{blue}|
% builds itself the macro |\color@blue|, which expands to the PDF
% colorstack string. The colorstack string is necessary to generate a
% PDF colorstack whatsit.
%    \begin{macrocode}
\def\ClozeColor#1{\csname\string\color@#1\endcsname}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ClozeStartMarker}
% At the begining |\ClozeStartMarker| registers the required Lua
% callbacks. Then it inserts a whatsit marker which marks the begin of a
% gap.
%    \begin{macrocode}
\def\ClozeStartMarker#1{%
  \strut\directlua{
    cloze.register('#1')
    cloze.marker('#1', 'start')
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ClozeStopMarker}
% \cmd{\ClozeStopMarker} inserts a whatsit marker that marks the end
% of gap.
%    \begin{macrocode}
\def\ClozeStopMarker#1{%
  \strut\directlua{
    cloze.marker('#1', 'stop')
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ClozeMargin}
% \cmd{\ClozeMargin} surrounds a text in a gap with two |kerns|.
%    \begin{macrocode}
\def\ClozeMargin#1{%
  \directlua{cloze.margin()}%
  #1%
  \directlua{cloze.margin()}%
}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Public plain \TeX{} macros}
%
% \begin{macro}{\clozesetoption}
% \cmd{\clozesetoption} is a wrapper for the Lua function
% |registry.set_option|. \cmd{\clozesetoption}\marg{key}\marg{value}
% sets a key \meta{key} to the value \meta{value}.
%    \begin{macrocode}
\def\clozesetoption#1#2{%
  \ClozeSetToGlobal%
  \directlua{cloze.set_option('#1', '#2')}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozereset}
% The usage of the command \cmd{\clozereset} is described in detail in
% section \TmpSecRef{sec:command-clozereset}.
%    \begin{macrocode}
\def\clozereset{%
  \ClozeSetToGlobal%
  \directlua{cloze.reset()}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozeshow}
% The usage of the command \cmd{\clozeshow} is described in detail in
% section \TmpSecRef{sec:command-clozeshow}.
%    \begin{macrocode}
\def\clozeshow{%
  \clozeshowtrue%
  \ClozeSetToGlobal%
  \clozesetoption{show}{true}%
  \clozesetoption{hide}{false}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozehide}
% The usage of the command \cmd{\clozehide} is described in detail in
% section \TmpSecRef{sec:command-clozehide}.
%    \begin{macrocode}
\def\clozehide{%
  \clozeshowfalse%
  \ClozeSetToGlobal%
  \clozesetoption{hide}{true}%
  \clozesetoption{show}{false}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\clozefont}
% The usage of the command \cmd{\clozefont} is described in detail in
% section \TmpSecRef{sec:command-clozefont}.
%    \begin{macrocode}
\def\clozefont{\it}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozesetfont}
% The usage of the command \cmd{\clozesetfont} is described in detail in
% section \TmpSecRef{sec:command-clozesetfont}.
%    \begin{macrocode}
\def\clozesetfont#1{%
  \def\clozefont{%
    #1%
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cloze}
% This is the plain Lua\TeX-Version of the macro \cmd{\cloze}.
%    \begin{macrocode}
\def\cloze#1{%
  \ClozeStartMarker{basic}%
  {%
    \clozefont\relax%
    \ClozeMargin{#1}%
  }%
  \ClozeStopMarker{basic}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozefix}
% This is the plain Lua\TeX-Version of \cmd{\clozefix}. The usage of the
% command \cmd{\clozefix} is described in detail in
% section \TmpSecRef{sec:command-clozefix}.
%    \begin{macrocode}
\def\clozefix#1{%
  \ClozeStartMarker{fix}%
  {%
    \clozefont\relax%
    \ClozeMargin{#1}%
  }%
  \ClozeStopMarker{fix}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozenol}
% This is the plain Lua\TeX-Version of the macro \cmd{\clozenol}. The
% usage of the command \cmd{\clozenol} is described in detail in
% section \TmpSecRef{sec:command-clozenol}.
%    \begin{macrocode}
\def\clozenol#1{%
  \clozesetoption{thickness}{0pt}%
  \ClozeStartMarker{basic}%
  {%
    \clozefont\relax%
    \ClozeMargin{#1}%
  }%
  \ClozeStopMarker{basic}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozeline}
% This is the plain Lua\TeX-Version of the macro \cmd{\clozeline}. The
% usage of the command \cmd{\clozeline} is described in detail in
% section \TmpSecRef{sec:command-clozeline}.
%    \begin{macrocode}
\def\clozeline{%
  \directlua{cloze.line()}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozelinefil}
% This is the plain Lua\TeX-Version of the macro \cmd{\clozelinefil}.
% The usage of the command \cmd{\clozelinefil} is described in detail in
% section \TmpSecRef{sec:command-clozelinefil}.
%    \begin{macrocode}
\def\clozelinefil{%
  \strut%
  \directlua{cloze.linefil()}%
  \strut%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozefil}
% This is the plain Lua\TeX-Version of the macro \cmd{\clozefil}.
% The usage of the command \cmd{\clozefil} is described in detail in
% section \TmpSecRef{sec:command-clozefil}.
%    \begin{macrocode}
\def\clozefil#1{%
  \cloze{#1}\clozelinefil%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozeparcmd}
% The usage of the macro \cmd{\clozeparcmd} is described in detail in
% section \TmpSecRef{sec:command-clozeparcmd}.
%    \begin{macrocode}
\def\clozeparcmd#1\par {%
  \par%
  \ClozeStartMarker{par}%
  \clozefont\relax%
  #1%
  \ClozeStopMarker{par}%
  \par%
  \directlua{cloze.unregister('par')}%
}
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%</plaintex>
% \fi
%
% \iffalse
%<*latex>
% \fi
% \MacroTopsep = 10pt plus 2pt minus 2pt
% \MacrocodeTopsep = 10pt plus 1.2pt minus 1pt
%
% \makeatletter
% \c@CodelineNo 25 \relax
% \makeatother
%
% \subsection{The file \tt{cloze.sty}}
%
%    \begin{macrocode}
\input{cloze.tex}
%    \end{macrocode}
%
% This packages are used to build \emph{cloze}:
%
% \subsubsection{Dependencies}
%
% The package \href{https://www.ctan.org/pkg/fontspec}{fontspec} is not
% necessarily required. When using Lua\LaTeX{} it is good form to load
% it. Apart from this the package supplies helpful messages, when you
% compile a Lua\LaTeX{} document with pdf\LaTeX{}.
%    \begin{macrocode}
\RequirePackage{fontspec}
%    \end{macrocode}
% The package \href{https://www.ctan.org/pkg/luatexbase}{luatexbase}
% allows to register multiple Lua callbacks.
%    \begin{macrocode}
\RequirePackage{luatexbase-mcb}
%    \end{macrocode}
% The package \href{https://www.ctan.org/pkg/kvoptions}{kvoptions}
% takes the handling of the options.
%    \begin{macrocode}
\RequirePackage{kvoptions}
%    \end{macrocode}
% The package \href{https://www.ctan.org/pkg/setspace}{setspace} is used
% by the environment |clozespace|.
%    \begin{macrocode}
\RequirePackage{setspace}
%    \end{macrocode}
% The package \href{https://www.ctan.org/pkg/xcolor}{xcolor} is required
% to colorize the text and the line of a gap.
%    \begin{macrocode}
\RequirePackage{xcolor}
%    \end{macrocode}
% The package \href{https://www.ctan.org/pkg/xcolor}{xparse} is used by
% the environment |clozebox|.
%    \begin{macrocode}
\RequirePackage{xparse}
%    \end{macrocode}
% The package \href{https://www.ctan.org/pkg/stackengine}{stackengine}
% is required by the command |\clozestrike{}{}|.
%    \begin{macrocode}
\RequirePackage{stackengine}
%    \end{macrocode}
% The package \href{https://www.ctan.org/pkg/ulem}{ulem} is required by
% the command |\clozestrike{}{}|.
%    \begin{macrocode}
\RequirePackage{ulem}
\normalem
%    \end{macrocode}
%
%    \begin{macrocode}
\RequirePackage{transparent}
%    \end{macrocode}
%
% Load the cloze lua module and put all return values in the variable
% |cloze|.
%
% \begin{macro}{\clozesetoption}
% \cmd{\clozesetoption} is a wrapper for the Lua function
% |registry.set_option|. \cmd{\clozesetoption}\marg{key}\marg{value}
% sets a key \meta{key} to the value \meta{value}. The plain Lua\TeX{}
% version always sets to the global options. The Lua\LaTeX-version
% can set values both to the local and the global options store.
%    \begin{macrocode}
\let\clozesetoption=\undefined
\newcommand{\clozesetoption}[2]{%
  \directlua{cloze.set_option('#1', '#2')}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ClozeSetLocalOptions}
% This macro is used in all cloze commands to handle the optional
% arguments. First it sets the option storage to local and then it
% commits the options to the package \emph{kvoptions} via the macro
% |\kvsetkeys{CLZ}{}|.
%    \begin{macrocode}
\def\ClozeSetLocalOptions#1{%
  \ClozeSetToLocal%
  \kvsetkeys{CLZ}{#1}%
}
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Options}
%
% \emph{cloze} offers key-value pairs to use as options. For processing
% the key-value pairs we use the package
% \href{https://www.ctan.org/pkg/kvoptions}{kvoptions}.
% To make all key-value pairs accessibly to Lua code, we use the
% declaration
% \cmd{\define@key}\marg{CLZ}\marg{option}\oarg[]\marg{\dots}. This
% declaration comes from the package
% \href{https://www.ctan.org/pkg/keyval}{keyval}.
%
% At start all values are declared as global options. At the Lua side
% all values are now stored in the |registry.global_options| table.
%
%    \begin{macrocode}
\ClozeSetToGlobal
%    \end{macrocode}
%
% We use the abbreviation |CLZ| for \emph{cloze} as family name and
% prefix.
%
%    \begin{macrocode}
\SetupKeyvalOptions{
  family=CLZ,
  prefix=CLZ@
}
%    \end{macrocode}
%
% \paragraph{\tt{align}}
%
% \noindent Please read the section \TmpSecRef{sec:option-align} how to use
% the option |align|. |align| affects only the command \cmd{\clozefix}
% \TmpSecRef{sec:command-clozefix}.
%
%    \begin{macrocode}
\DeclareStringOption{align}
\define@key{CLZ}{align}[]{\clozesetoption{align}{#1}}
%    \end{macrocode}
%
% \paragraph{\tt{boxheight}}
%
% \noindent Please read the section \TmpSecRef{sec:command-clozebox}
% how to use the option |boxheight|. |boxheight| affects only the
% environment |clozebox|.
% \TmpSecRef{sec:command-clozefix}.
%
%    \begin{macrocode}
\DeclareStringOption{boxheight}
\define@key{CLZ}{boxheight}[]{\clozesetoption{boxheight}{#1}}
%    \end{macrocode}
%
% \paragraph{\tt{boxwidth}}
%
% \noindent Please read the section \TmpSecRef{sec:command-clozebox}
% how to use the option |boxwidth|. |boxwidth| affects only the
% environment |clozebox|.
% \TmpSecRef{sec:command-clozefix}.
%
%    \begin{macrocode}
\DeclareStringOption{boxwidth}
\define@key{CLZ}{boxwidth}[]{\clozesetoption{boxwidth}{#1}}
%    \end{macrocode}
%
% \paragraph{\tt{distance}}
%
% \noindent Please read the section \TmpSecRef{sec:option-distance} how to
% use the option |distance|.
%
%    \begin{macrocode}
\DeclareStringOption{distance}
\define@key{CLZ}{distance}[]{\clozesetoption{distance}{#1}}
%    \end{macrocode}
%
% \paragraph{\tt{hide}}
%
% \noindent If the option |hide| appears in the commands, |hide| will be
% set to \emph{true} and |show| to \emph{false} on the Lua side. Please
% read the section \TmpSecRef{sec:option-hide} how to use the option
% |hide|.
%
%    \begin{macrocode}
\DeclareVoidOption{hide}{%
  \clozeshowfalse%
  \clozesetoption{hide}{true}%
  \clozesetoption{show}{false}%
}
%    \end{macrocode}
%
% \paragraph{\tt{linecolor}}
%
% \noindent Please read the section \TmpSecRef{sec:option-linecolor} how to
% use the option |linecolor|.
%
%    \begin{macrocode}
\DeclareStringOption{linecolor}
\define@key{CLZ}{linecolor}[]{%
  \clozesetoption{linecolor}{\ClozeColor{#1}}%
  \clozesetoption{linecolor_name}{#1}%
}
%    \end{macrocode}
%
% \paragraph{\tt{margin}}
%
% \noindent Please read the section \TmpSecRef{sec:option-margin} how to
% use the option |margin|.
%
%    \begin{macrocode}
\DeclareStringOption{margin}
\define@key{CLZ}{margin}[]{\clozesetoption{margin}{#1}}
%    \end{macrocode}
%
% \paragraph{\tt{show}}
%
% \noindent If the option |show| appears in the commands, |show| will be
% set to \emph{true} and |true| to \emph{false} on the Lua side. Please
% read the section \TmpSecRef{sec:option-show} how to use the option
% |show|.
%
%    \begin{macrocode}
\DeclareVoidOption{show}{%
  \clozeshowtrue%
  \clozesetoption{show}{true}%
  \clozesetoption{hide}{false}%
}
%    \end{macrocode}
%
% \paragraph{\tt{spacing}}
%
% \noindent Please read the section \TmpSecRef{sec:option-spacing} how to
% use the option |spacing|.
%
%    \begin{macrocode}
\DeclareStringOption{spacing}
\define@key{CLZ}{spacing}[]{\clozesetoption{spacing}{#1}}
%    \end{macrocode}
%
% \paragraph{\tt{textcolor}}
%
% \noindent Please read the section \TmpSecRef{sec:option-textcolor} how to
% use the option |textcolor|.
%
%    \begin{macrocode}
\DeclareStringOption{textcolor}
\define@key{CLZ}{textcolor}[]{%
  \clozesetoption{textcolor}{\ClozeColor{#1}}%
  \clozesetoption{textcolor_name}{#1}%
}
%    \end{macrocode}
%
% \paragraph{\tt{thickness}}
%
% \noindent Please read the section \TmpSecRef{sec:option-thickness} how to
% use the option |thickness|.
%
%    \begin{macrocode}
\DeclareStringOption{thickness}
\define@key{CLZ}{thickness}[]{\clozesetoption{thickness}{#1}}
%    \end{macrocode}
%
% \paragraph{\tt{width}}
%
% \noindent Please read the section \TmpSecRef{sec:option-width} how to use
% the option |width|. |width| affects only the command \cmd{\clozefix}
% \TmpSecRef{sec:command-clozefix}.
%
%    \begin{macrocode}
\DeclareStringOption{width}
\define@key{CLZ}{width}[]{\clozesetoption{width}{#1}}
%    \end{macrocode}
%
%    \begin{macrocode}
\ProcessKeyvalOptions{CLZ}
%    \end{macrocode}
%
% \subsubsection{Public macros}
%
% All public macros are prefixed with |\cloze|.
%
% \begin{macro}{\clozeset}
% The usage of the command \cmd{\clozeset} is described in detail in
% section \TmpSecRef{sec:command-clozeset}.
%    \begin{macrocode}
\newcommand{\clozeset}[1]{%
  \ClozeSetToGlobal%
  \kvsetkeys{CLZ}{#1}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozeshow}
% The usage of the command \cmd{\clozeshow} is described in detail in
% section \TmpSecRef{sec:command-clozeshow}.
%    \begin{macrocode}
\let\clozeshow=\undefined
\newcommand{\clozeshow}{%
  \clozeset{show}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozehide}
% The usage of the command \cmd{\clozehide} is described in detail in
% section \TmpSecRef{sec:command-clozehide}.
%    \begin{macrocode}
\let\clozehide=\undefined
\newcommand{\clozehide}{%
  \clozeset{hide}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\cloze}
% The usage of the command \cmd{\cloze} is described in detail in
% section \TmpSecRef{sec:command-cloze}.
%    \begin{macrocode}
\let\clozeplain=\cloze
\let\cloze=\undefined
\newcommand{\cloze}[2][]{%
  \ClozeSetLocalOptions{#1}%
  \clozeplain{#2}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozefix}
% The usage of the command \cmd{\clozefix} is described in detail in
% section \TmpSecRef{sec:command-clozefix}.
%    \begin{macrocode}
\let\clozefixplain=\clozefix
\let\clozefix=\undefined
\newcommand{\clozefix}[2][]{%
  \ClozeSetLocalOptions{#1}%
  \clozefixplain{#2}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozenol}
% The usage of the command \cmd{\clozenol} is described in detail in
% section \TmpSecRef{sec:command-clozenol}.
%    \begin{macrocode}
\let\clozenolplain=\clozenol
\let\clozenol=\undefined
\newcommand{\clozenol}[2][]{%
  \ClozeSetLocalOptions{#1}%
  \clozenolplain{#2}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{environment}{clozepar}
% The usage of the environment |clozepar| is described in detail in
% section \TmpSecRef{sec:command-clozepar}.
%    \begin{macrocode}
\newenvironment{clozepar}[1][]%
{%
  \par%
  \ClozeSetLocalOptions{#1}%
  \ClozeStartMarker{par}%
  \clozefont\relax%
}%
{%
  \ClozeStopMarker{par}%
  \par%
  \directlua{cloze.unregister('par')}%
}
%    \end{macrocode}
% \end{environment}
%
% \begin{environment}{clozebox}
% The usage of the environment |clozebox| is described in detail in
% section \TmpSecRef{sec:command-clozebox}.
% TODO: Realize this macro with lua code, without ugly |\color{white}|
% command.
%    \begin{macrocode}
\newsavebox{\ClozeBox}%
\NewDocumentEnvironment{clozebox}{ s O{} +b}{%
  \ClozeSetLocalOptions{#2}%
  \noindent%
  \begin{lrbox}{\ClozeBox}%
  \directlua{
    local boxheight = cloze.get_value('boxheight')
    local boxwidth = cloze.get_value('boxwidth')
    if boxheight then
      tex.print('\\begin{minipage}[t][' .. boxheight .. '][t]{' .. boxwidth .. '}')
    else
      tex.print('\\begin{minipage}[t]{' .. boxwidth .. '}')
    end
  }%
  \setlength{\parindent}{0pt}%
  \clozenol[margin=0pt]{#3}%
  \end{minipage}%
  \end{lrbox}%
  \IfBooleanTF{#1}%
    {\usebox{\ClozeBox}}%
    {\fbox{\usebox{\ClozeBox}}}%
}{}
%    \end{macrocode}
% \end{environment}
%
% \begin{environment}{clozespace}
% The usage of the environment |clozespace| is described in detail in
% section \TmpSecRef{sec:command-clozespace}.
% TODO: Realization without setspace package.
%    \begin{macrocode}
\newenvironment{clozespace}[1][]%
{%
  \ClozeSetLocalOptions{#1}%
  \begin{spacing}{\directlua{tex.print(cloze.get_value('spacing'))}}%
}{\end{spacing}}
%    \end{macrocode}
% \end{environment}
%
% \begin{macro}{\clozeline}
% The usage of the command \cmd{\clozeline} is described in detail in
% section \TmpSecRef{sec:command-clozeline}.
%    \begin{macrocode}
\let\clozelineplain=\clozeline
\let\clozeline=\undefined
\newcommand{\clozeline}[1][]{%
  \ClozeSetLocalOptions{#1}%
  \clozelineplain%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozelinefil}
% The usage of the command \cmd{\clozelinefil} is described in detail in
% section \TmpSecRef{sec:command-clozelinefil}.
%    \begin{macrocode}
\let\clozelinefilplain=\clozelinefil
\let\clozelinefil=\undefined
\newcommand{\clozelinefil}[1][]{%
  \ClozeSetLocalOptions{#1}%
  \clozelinefilplain%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozefil}
% The usage of the command \cmd{\clozefil} is described in detail in
% section \TmpSecRef{sec:command-clozefil}.
%    \begin{macrocode}
\let\clozefil=\undefined
\newcommand{\clozefil}[2][]{%
  \cloze[#1]{#2}\clozelinefil[#1]%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozeextend}
% TODO: Use node library to create kern nodes.
%    \begin{macrocode}
\newcommand{\clozeextend}[1][1]{%
  \directlua{
    local loop = #1
    for variable = 1, loop do
      tex.print(' \string\\hspace{1em} \string\\strut')
    end
  }
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ClozeTextColor}
%    \begin{macrocode}
\newcommand{\ClozeTextColor}[1]{%
  \textcolor%
    {\directlua{tex.print(cloze.get_value('textcolor_name'))}}%
    {#1}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ClozeStrikeLine}
%    \begin{macrocode}
\newcommand\ClozeStrikeLine{%
  \bgroup%
  \markoverwith{%
    \ClozeTextColor{%
      \rule[0.5ex]{2pt}{1pt}%
    }%
  }%
  \ULon%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\clozestrike}
%    \begin{macrocode}
\newcommand{\clozestrike}[3][]{%
  \ClozeSetLocalOptions{#1}%
  \ifclozeshow%
    \stackengine%
      {\Sstackgap}% \Sstackgap or \Lstackgap or \stackgap or stacklength
      {\ClozeStrikeLine{#2}}% anchor
      {\ClozeTextColor{\clozefont{}#3}}% item
      {O}% O or U
      {c}% \stackalignment or l or c or r
      {\quietstack}% \quietstack or T or F
      {T}% \useanchorwidth or T or F
      {\stacktype}% \stacktype or S or L
  \else%
    \stackengine%
      {\Sstackgap}% \Sstackgap or \Lstackgap or \stackgap or stacklength
      {#2}% anchor
      {\texttransparent{0}{\clozefont{}#3}}% item
      {O}% O or U
      {c}% \stackalignment or l or c or r
      {\quietstack}% \quietstack or T or F
      {T}% \useanchorwidth or T or F
      {\stacktype}% \stacktype or S or L
  \fi%
}
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%</latex>
% \fi
%
% \Finale
\endinput
