%%
%% This is file `cloze.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% cloze.dtx  (with options: `latex')
%% 
%% This is a generated file.
%% 
%% 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.3c 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.3c or later is part of all distributions of LaTeX
%% version 2008/05/05 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{cloze}
    [2020/06/60 v1.6 Package to typeset cloze worksheets or cloze tests]
\input{cloze.tex}
\RequirePackage{fontspec}
\RequirePackage{luatexbase-mcb}
\RequirePackage{kvoptions}
\RequirePackage{setspace}
\RequirePackage{xcolor}
\RequirePackage{xparse}
\RequirePackage{stackengine}
\RequirePackage{ulem}
\normalem
\RequirePackage{transparent}
\let\clozesetoption=\undefined
\newcommand{\clozesetoption}[2]{%
  \directlua{cloze.set_option('#1', '#2')}%
}
\def\ClozeSetLocalOptions#1{%
  \ClozeSetToLocal%
  \kvsetkeys{CLZ}{#1}%
}
\ClozeSetToGlobal
\SetupKeyvalOptions{
  family=CLZ,
  prefix=CLZ@
}
\DeclareStringOption{align}
\define@key{CLZ}{align}[]{\clozesetoption{align}{#1}}
\DeclareStringOption{boxheight}
\define@key{CLZ}{boxheight}[]{\clozesetoption{boxheight}{#1}}
\DeclareStringOption{boxwidth}
\define@key{CLZ}{boxwidth}[]{\clozesetoption{boxwidth}{#1}}
\DeclareStringOption{distance}
\define@key{CLZ}{distance}[]{\clozesetoption{distance}{#1}}
\DeclareVoidOption{hide}{%
  \clozeshowfalse%
  \clozesetoption{hide}{true}%
  \clozesetoption{show}{false}%
}
\DeclareStringOption{linecolor}
\define@key{CLZ}{linecolor}[]{%
  \clozesetoption{linecolor}{\ClozeColor{#1}}%
  \clozesetoption{linecolor_name}{#1}%
}
\DeclareStringOption{margin}
\define@key{CLZ}{margin}[]{\clozesetoption{margin}{#1}}
\DeclareVoidOption{show}{%
  \clozeshowtrue%
  \clozesetoption{show}{true}%
  \clozesetoption{hide}{false}%
}
\DeclareStringOption{spacing}
\define@key{CLZ}{spacing}[]{\clozesetoption{spacing}{#1}}
\DeclareStringOption{textcolor}
\define@key{CLZ}{textcolor}[]{%
  \clozesetoption{textcolor}{\ClozeColor{#1}}%
  \clozesetoption{textcolor_name}{#1}%
}
\DeclareStringOption{thickness}
\define@key{CLZ}{thickness}[]{\clozesetoption{thickness}{#1}}
\DeclareStringOption{width}
\define@key{CLZ}{width}[]{\clozesetoption{width}{#1}}
\ProcessKeyvalOptions{CLZ}
\newcommand{\clozeset}[1]{%
  \ClozeSetToGlobal%
  \kvsetkeys{CLZ}{#1}%
}
\let\clozeshow=\undefined
\newcommand{\clozeshow}{%
  \clozeset{show}
}
\let\clozehide=\undefined
\newcommand{\clozehide}{%
  \clozeset{hide}
}
\let\clozeplain=\cloze
\let\cloze=\undefined
\newcommand{\cloze}[2][]{%
  \ClozeSetLocalOptions{#1}%
  \clozeplain{#2}%
}
\let\clozefixplain=\clozefix
\let\clozefix=\undefined
\newcommand{\clozefix}[2][]{%
  \ClozeSetLocalOptions{#1}%
  \clozefixplain{#2}%
}
\let\clozenolplain=\clozenol
\let\clozenol=\undefined
\newcommand{\clozenol}[2][]{%
  \ClozeSetLocalOptions{#1}%
  \clozenolplain{#2}%
}
\newenvironment{clozepar}[1][]%
{%
  \par%
  \ClozeSetLocalOptions{#1}%
  \ClozeStartMarker{par}%
  \clozefont\relax%
}%
{%
  \ClozeStopMarker{par}%
  \par%
  \directlua{cloze.unregister('par')}%
}
\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}}}%
}{}
\newenvironment{clozespace}[1][]%
{%
  \ClozeSetLocalOptions{#1}%
  \begin{spacing}{\directlua{tex.print(cloze.get_value('spacing'))}}%
}{\end{spacing}}
\let\clozelineplain=\clozeline
\let\clozeline=\undefined
\newcommand{\clozeline}[1][]{%
  \ClozeSetLocalOptions{#1}%
  \clozelineplain%
}
\let\clozelinefilplain=\clozelinefil
\let\clozelinefil=\undefined
\newcommand{\clozelinefil}[1][]{%
  \ClozeSetLocalOptions{#1}%
  \clozelinefilplain%
}
\let\clozefil=\undefined
\newcommand{\clozefil}[2][]{%
  \cloze[#1]{#2}\clozelinefil[#1]%
}
\newcommand{\clozeextend}[1][1]{%
  \directlua{
    local loop = #1
    for variable = 1, loop do
      tex.print(' \string\\hspace{1em} \string\\strut')
    end
  }
}
\newcommand{\ClozeTextColor}[1]{%
  \textcolor%
    {\directlua{tex.print(cloze.get_value('textcolor_name'))}}%
    {#1}%
}
\newcommand\ClozeStrikeLine{%
  \bgroup%
  \markoverwith{%
    \ClozeTextColor{%
      \rule[0.5ex]{2pt}{1pt}%
    }%
  }%
  \ULon%
}
\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%
}
\endinput
%%
%% End of file `cloze.sty'.
