%%
%% This is file `dashundergaps.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% dashundergaps.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright 2018-2021 Frank Mittelbach
%% 
%% This file was generated from file(s) of the LaTeX `dashundergaps Bundle'.
%% --------------------------------------------------------------------------
%% 
%% It 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 2005/12/01 or later.
%% 
%% This file may only be distributed together with a copy of the LaTeX
%% `dashundergaps Bundle'. You may however distribute the `dashundergaps Bundle'
%% without such generated files.
%% 
%% The newest sources can be found below
%% 
%%    https://github.com/FrankMittelbach/fmitex/
%% 
%% where one can also log issues in case there are any.
%% 
%% 
%% File: dashundergaps.dtx (C) Copyright 2018-2021 Frank Mittelbach

\def\dashundergapsdate   {2021-03-05}    % don't forget to also adjust build.lua!
\def\dashundergapsversion{v2.0h}

\RequirePackage[normalem]{ulem}
\protected\def\dotuline{\leavevmode\bgroup
  \UL@setULdepth
  \ifx\UL@on\UL@onin \advance\ULdepth2\p@\fi
  \markoverwith{\begingroup
     \lower\ULdepth\hbox{\normalfont \kern.1em .\kern.04em}%
     \endgroup}%
  \ULon}
\protected\def\uwave{\leavevmode\bgroup
  \UL@setULdepth
  \advance\ULdepth 0.6\p@
  \markoverwith{\lower\ULdepth\hbox{\sixly \char58}}\ULon}
\def\fmdug@ublank{\bgroup\let\UL@leadtype\@empty\ULon}
\def\UL@dischyp{\global\setbox\UL@hyphenbox\hbox
   {\ifnum \hyphenchar\font<\z@ \string-\else \char\hyphenchar\font \fi}%
   \kern\wd\UL@hyphenbox \LA@penalty\@M
   \UL@stop \kern-\wd\UL@hyphenbox
   \discretionary{\fmdug@box\UL@hyphenbox}{}{}\UL@start}
\def\UL@putbox{\ifx\UL@start\@empty \else % not inner
  \vrule\@width\z@ \LA@penalty\@M
  {\UL@skip\wd\UL@box \UL@leaders \kern-\UL@skip}%
  \fmdug@box\UL@box  \fi}
\let\fmdug@box\box

\RequirePackage{l3keys2e}
\@ifpackagelater{expl3}{2018-06-24}
  {}
  {%
    \PackageError{dashundergaps}{Support package l3kernel too old}
      {%
        Please install an up to date version of l3kernel\MessageBreak
        using your TeX package manager or from CTAN.\MessageBreak
        \MessageBreak
        Loading dashundergaps will abort!%
      }%
    \endinput
  }
\ProvidesExplPackage{dashundergaps}
                    {\dashundergapsdate}
                    {\dashundergapsversion}
                    {Dashing and underlining phantom text}

\DeclareDocumentCommand \gap { som }
   {
     \protected@edef\next{#3}
     \__fmdug_gap:nno {#1}{#2}{ \next } }
\NewDocumentCommand \dashundergapssetup { m }
  { \keys_set:nn {fmdug} {#1} \ignorespaces }
\DeclareDocumentCommand \TeacherModeOn  {}
                        { \bool_set_true:N \l__fmdug_teacher_bool }
\DeclareDocumentCommand \TeacherModeOff {}
                        { \bool_set_false:N \l__fmdug_teacher_bool }
\newcounter{gapnumber}
\newcounter{totalgapnumber}

\dim_new:N \l__fmdug_extend_dim
\tl_new:N \l__fmdug_extra_left_gap_tl
\tl_new:N \l__fmdug_extra_right_gap_tl
\tl_new:N \l__fmdug_gap_format_tl
\tl_new:N \l__fmdug_teacher_gap_format_tl
\msg_new:nnn {dashundergaps} {deprecated}
  { The~ #1~ `#2'~ you~ used~ \msg_line_context: \ is~ deprecated~ and~
    there~ is~ no~ replacement.~ Since~ I~ will~ not~ guarantee~ that~
    #1~ `#2'~ will~ be~ kept~ forever~ I~ strongly~ encourage~ you~
    to~ remove~ it~ from~ your~ document. }
\msg_new:nnnn {dashundergaps} {nested}
  { The~ \gap command~ can't~ be~ nested! }
  { Nesting~ doesn't~ make~ much~ sense~ as~ the~ inner~ one~
    wouldn't~ be~ visible.~ ~ To~ allow~ further~ processing~ it~ is~
    handled~ as~ if~ it~ hasn't~ been~ asked~ for. }
\msg_new:nnnn {dashundergaps} {gap-format-value}
  { Unknown~ value~ for~ key~ '#1 gap-format'! }
  { Supported~ values~ are~ 'underline',~ 'double-underline',\\
    'dash',~ 'dot',~ 'wave'~ or~ 'blank'. }
\keys_define:nn {fmdug}
     {
       % ====================================
      ,teacher-mode      .bool_set:N = \l__fmdug_teacher_bool
      ,teacher-mode      .default:n  = true
      ,teacher-mode      .initial:n  = false
       % ------------------
      ,gap-mode  .bool_set_inverse:N = \l__fmdug_teacher_bool
       % ====================================
      ,gap-format
         .choice:
      ,gap-format / underline
         .code:n = \tl_set:Nn \l__fmdug_gap_format_tl
                              { \__fmdug_gap_format_adjust:n{.4pt} \uline }
      ,gap-format / double-underline
         .code:n = \tl_set:Nn \l__fmdug_gap_format_tl
                              { \__fmdug_gap_format_adjust:n{2pt} \uuline }
      ,gap-format / dash
         .code:n = \tl_set:Nn \l__fmdug_gap_format_tl
                           { \__fmdug_gap_format_adjust:n{0pt} \dashuline }
      ,gap-format / dot
         .code:n = \tl_set:Nn \l__fmdug_gap_format_tl
                         { \__fmdug_gap_format_adjust:n{-.08ex} \dotuline }
      ,gap-format / wave
         .code:n = \tl_set:Nn \l__fmdug_gap_format_tl
                              { \__fmdug_gap_format_adjust:n{1pt} \uwave }
      ,gap-format / blank
         .code:n = \tl_set:Nn \l__fmdug_gap_format_tl { \fmdug@ublank  }
      ,gap-format / unknown
         .code:n = \msg_error:nnn{dashundergaps}{gap-format-value}{}
      ,gap-format
         .initial:n = underline
       % ====================================
       ,gap-format-adjust
         .choice:
       ,gap-format-adjust / true
         .code:n = \cs_set:Npn \__fmdug_gap_format_adjust:n ##1
                               { \setlength\ULdepth {##1} }
       ,gap-format-adjust / false
         .code:n = \cs_set_eq:NN \__fmdug_gap_format_adjust:n \use_none:n
      ,gap-format-adjust
         .default:n = true
      ,gap-format-adjust
         .initial:n = true
      ,adjust .meta:n = { gap-format-adjust }
       % ====================================
      ,teacher-gap-format
         .choice:
     ,teacher-gap-format / underline
         .code:n = \tl_set:Nn \l__fmdug_teacher_gap_format_tl { \uline }
      ,teacher-gap-format / double-underline
         .code:n = \tl_set:Nn \l__fmdug_teacher_gap_format_tl { \uuline }
      ,teacher-gap-format / dash
         .code:n = \tl_set:Nn \l__fmdug_teacher_gap_format_tl { \dashuline }
      ,teacher-gap-format / dot
         .code:n = \tl_set:Nn \l__fmdug_teacher_gap_format_tl { \dotuline }
      ,teacher-gap-format / wave
         .code:n = \tl_set:Nn \l__fmdug_teacher_gap_format_tl { \uwave }
      ,teacher-gap-format / blank
         .code:n = \tl_set:Nn \l__fmdug_teacher_gap_format_tl { \fmdug@ublank }
      ,teacher-gap-format / unknown
         .code:n = \msg_error:nnn{dashundergaps}{gap-format-value}{teacher-}
      ,teacher-gap-format
         .initial:n = blank
       % ====================================
      ,gap-widen         .bool_set:N = \l__fmdug_gap_widen_bool
      ,gap-widen         .default:n  = true
      ,gap-widen         .initial:n  = false
       % ------------------
      ,widen                 .meta:n = { gap-widen }
       % ------------------
      ,gap-extend-minimum .dim_set:N = \l__fmdug_gap_min_dim
      ,gap-extend-minimum .initial:n = 20pt
       % ------------------
      ,gap-extend-percent .tl_set:N  = \l__fmdug_gap_percent_tl
      ,gap-extend-percent .initial:n = 20
       % ====================================
      ,gap-numbers        .bool_set:N = \l__fmdug_number_bool
      ,gap-numbers        .default:n  = true
      ,gap-numbers        .initial:n  = true
       % ------------------
      ,numbers                .meta:n = { gap-numbers }
       % ------------------
      ,gap-number-format .tl_set:N    = \l__fmdug_gapnum_format_tl
      ,gap-number-format .initial:n   = \textnormal{\space (\thegapnumber)}
       % ====================================
      ,display-total-gaps .bool_gset:N = \g__fmdug_display_total_gaps_bool
      ,display-total-gaps   .default:n = true
      ,display-total-gaps   .initial:n = false
       % ====================================
      ,gap-font    .tl_set:N = \l__fmdug_font_tl
      ,gap-font   .default:n =
      ,gap-font   .initial:n = \bfseries
       % ====================================
      ,teachermode   .meta:n =  { teacher-mode }
      ,dash          .meta:n =  { gap-format = dash }
      ,dot           .meta:n =  { gap-format = dot }
      ,displaynbgaps .meta:n =  { display-total-gaps }
       % ------------------
      ,phantomtext
         .code:n = \msg_warning:nnnn{dashundergaps}{deprecated}
                                    {option}{phantomtext}
       % ====================================
     }
\cs_new:Npn\__fmdug_gap:nnn #1#2#3 {
  \group_begin:
    \l__fmdug_font_tl
    \cs_set:Npn \__fmdug_gap:nnn ##1##2##3
      {
        \msg_error:nn{dashundergaps}{nested}
        ##3
      }
    \stepcounter{totalgapnumber}
    \bool_xor:nnT { #1 } { \l__fmdug_number_bool }
      { \refstepcounter{gapnumber} }
    \bool_if:NTF \l__fmdug_gap_widen_bool
      {
        \settowidth \l__fmdug_extend_dim {#3}
        \dim_set:Nn \l__fmdug_extend_dim
                  { \l__fmdug_gap_percent_tl \l__fmdug_extend_dim / 200 }
       \dim_compare:nNnT \l__fmdug_extend_dim < { .5\l__fmdug_gap_min_dim }
          { \dim_set:Nn \l__fmdug_extend_dim { .5\l__fmdug_gap_min_dim } }
       \tl_set:Nn \l__fmdug_extra_left_gap_tl
          { \hbox_to_wd:nn\l__fmdug_extend_dim{} \allowbreak }
       \tl_set:Nn \l__fmdug_extra_right_gap_tl
          { \allowbreak \hbox_to_wd:nn\l__fmdug_extend_dim{} }
      }
      {
        \tl_clear:N \l__fmdug_extra_left_gap_tl
        \tl_clear:N \l__fmdug_extra_right_gap_tl
      }
    \bool_if:NTF \l__fmdug_teacher_bool
      { \l__fmdug_teacher_gap_format_tl }
      {
        \cs_set:Npn   \fmdug@box ##1 {\hbox_to_wd:nn{\box_wd:N ##1}{}}
        \str_case:nnF {#2}
            {
              {u} { \__fmdug_gap_format_adjust:n{.4pt}   \uline  }
              {d} { \__fmdug_gap_format_adjust:n{2pt}    \uuline }
              {w} { \__fmdug_gap_format_adjust:n{1pt}    \uwave  }
              {b} { \fmdug@ublank }
              {.} { \__fmdug_gap_format_adjust:n{-.08ex} \dotuline }
              {-} { \__fmdug_gap_format_adjust:n{0pt}   \dashuline }
            }
            { \l__fmdug_gap_format_tl }
      }
    {\l__fmdug_extra_left_gap_tl #3 \l__fmdug_extra_right_gap_tl }
    \bool_xor:nnT { #1 } { \l__fmdug_number_bool }
                  { \l__fmdug_gapnum_format_tl }
  \group_end:
}
\cs_generate_variant:Nn \__fmdug_gap:nnn {nno}
\cs_new:Npn \__fmdug_display_total_gaps: {
  \vfill \centering
  \bfseries Total~ Gaps:~ \thetotalgapnumber
}
\AtEndDocument{
  \bool_if:NT \g__fmdug_display_total_gaps_bool
              \__fmdug_display_total_gaps:
}
\ProcessKeysPackageOptions{fmdug}
\endinput
%%
%% End of file `dashundergaps.sty'.
