%%
%% This is file `typog.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% typog.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2024 by Ch. L. Spiel
%% 
%% 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 2003/12/01 or later.
%% 
%% This work has the LPPL maintenance status `maintained'.
%% 
%% The Current Maintainer of this work is Ch. L. Spiel.
%% 
%% This work consists of the files typog.dtx and typog.ins
%% and the derived files typog.sty, slant-angle.mp,
%% crooked-paragraphs.mp, smooth-parshapes.mp, title.mp,
%% typog-example.tex, typog-nomt.tex, typog-grep.pl,
%% typog-grep.pod, and teximan2latex.sed.
%% 
%% 
\NeedsTeXFormat{LaTeX2e}[2005/12/01]
\ProvidesPackage{typog}
                [2024/05/07  v0.3  TypoGraphic extensions]

\RequirePackage{etoolbox}
\RequirePackage{everyhook}
\RequirePackage{xkeyval}

\newcommand*{\typog@TYPOG}{}
\newcommand*{\typoglogo}{\textsf{T\itcorr*{-5}\textsl{y}poG}}
\newif\iftypog@debug
\newcommand*{\typog@typeout}[1]
  {\iftypog@debug
     \typeout{typog: #1}%
   \fi}

\ExplSyntaxOn
\let\typog@trim@spaces=\tl_trim_spaces:o
\ExplSyntaxOff

\newcommand{\typog@register@pdfsubstitute}[1]{%
  \AtBeginDocument{%
    \ifdefined\pdfstringdefDisableCommands
      \pdfstringdefDisableCommands{#1}%
    \fi}}

\newif\iftypog@microtype@preloaded

\ifdefined\MT@MT
  \typog@typeout{package microtype preloaded}%
  \typog@microtype@preloadedtrue
  \def\typog@require@preloaded@microtype{\relax}
\else
  \typog@microtype@preloadedfalse
  \def\typog@require@preloaded@microtype
    {\PackageError{typog}%
                  {package microtype not (pre-)loaded}%
                  {package microtype must be loaded before package typog}}
\fi

\newif\iftypog@microtype@loaded

\AtBeginDocument{
  \ifdefined\MT@MT
    \typog@typeout{package microtype loaded}%
    \typog@microtype@loadedtrue
    \def\typog@require@microtype{\relax}
  \else
    \typog@microtype@loadedfalse
    \def\typog@require@microtype
      {\PackageError{typog}%
                    {package microtype not loaded}%
                    {require package microtype before package typog}}%
  \fi
}

\newmuskip\typog@mathitalicscorrection
\newlength{\typog@textitalicscorrection}
\newlength{\typog@ligaturekern}
\newlength{\typog@raisecapitaldash}
\newlength{\typog@raisecapitalguillemets}
\newlength{\typog@raisecapitalhyphen}
\newlength{\typog@raisecapitaltimes}
\newlength{\typog@raiseguillemets}
\newlength{\typog@raisefiguredash}
\newlength{\typog@slashkern}
\newcommand*{\typog@breakpenalty}{\exhyphenpenalty}
\newlength{\typog@dim@unit}
\setlength{\typog@dim@unit}{.001em}
\newcommand*{\typog@trackingttspacing}{300, 90, 60}
\newcommand*{\typog@default@shrink@i}{5}
\newcommand*{\typog@default@shrink@ii}{10}
\newcommand*{\typog@default@shrink@iii}{20}
\newcommand*{\typog@shrink@i}{}
\newcommand*{\typog@shrink@ii}{}
\newcommand*{\typog@shrink@iii}{}
\newcommand*{\typog@default@stretch@i}{5}
\newcommand*{\typog@default@stretch@ii}{10}
\newcommand*{\typog@default@stretch@iii}{20}
\newcommand*{\typog@stretch@i}{}
\newcommand*{\typog@stretch@ii}{}
\newcommand*{\typog@stretch@iii}{}

\def\typog@one@of@three#1,#2,#3\relax{\typog@trim@spaces{#1}}
\def\typog@two@of@three#1,#2,#3\relax{\typog@trim@spaces{#2}}
\def\typog@three@of@three#1,#2,#3\relax{\typog@trim@spaces{#3}}

\newcommand*{\typog@triple@get@i}[1]{\expandafter\typog@one@of@three #1\relax}
\newcommand*{\typog@triple@get@ii}[1]{\expandafter\typog@two@of@three #1\relax}
\newcommand*{\typog@triple@get@iii}[1]{\expandafter\typog@three@of@three #1\relax}

\newcommand*{\typog@set@shrink@limits}
  {\edef\typog@@star{*}%
   \edef\typog@@limit{\typog@triple@get@i{\typog@shrinklimits}}%
   \unless\ifx\typog@@limit\typog@@star\edef\typog@shrink@i{\number\typog@@limit}\fi
   \edef\typog@@limit{\typog@triple@get@ii{\typog@shrinklimits}}%
   \unless\ifx\typog@@limit\typog@@star\edef\typog@shrink@ii{\number\typog@@limit}\fi
   \edef\typog@@limit{\typog@triple@get@iii{\typog@shrinklimits}}%
   \unless\ifx\typog@@limit\typog@@star\edef\typog@shrink@iii{\number\typog@@limit}\fi}

\newcommand*{\typog@set@stretch@limits}
  {\edef\typog@@star{*}%
   \edef\typog@@limit{\typog@triple@get@i{\typog@stretchlimits}}%
   \unless\ifx\typog@@limit\typog@@star\edef\typog@stretch@i{\number\typog@@limit}\fi
   \edef\typog@@limit{\typog@triple@get@ii{\typog@stretchlimits}}%
   \unless\ifx\typog@@limit\typog@@star\edef\typog@stretch@ii{\number\typog@@limit}\fi
   \edef\typog@@limit{\typog@triple@get@iii{\typog@stretchlimits}}%
   \unless\ifx\typog@@limit\typog@@star\edef\typog@stretch@iii{\number\typog@@limit}\fi}

\DeclareOptionX<typog>{breakpenalty}%
  {\renewcommand*{\typog@breakpenalty}{#1}}
\DeclareOptionX<typog>{debug}{\typog@debugtrue}
\DeclareOptionX<typog>{mathitalicscorrection}[.4mu]%
  {\typog@mathitalicscorrection=#1\relax}%
\DeclareOptionX<typog>{nodebug}{\typog@debugfalse}
\DeclareOptionX<typog>{textitalicscorrection}[.02em]%
  {\setlength{\typog@textitalicscorrection}{#1}}
\DeclareOptionX<typog>{ligaturekern}[.033333em]%
  {\setlength{\typog@ligaturekern}{#1}}
\DeclareOptionX<typog>{raisecapitaldash}[\z@]%
  {\setlength{\typog@raisecapitaldash}{#1}}
\DeclareOptionX<typog>{raisecapitalguillemets}[\z@]%
  {\setlength{\typog@raisecapitalguillemets}{#1}}
\DeclareOptionX<typog>{raisecapitalhyphen}[\z@]%
  {\setlength{\typog@raisecapitalhyphen}{#1}}
\DeclareOptionX<typog>{raisecapitaltimes}[\z@]%
  {\setlength{\typog@raisecapitaltimes}{#1}}
\DeclareOptionX<typog>{raiseguillemets}[\z@]%
  {\setlength{\typog@raiseguillemets}{#1}}
\DeclareOptionX<typog>{raisefiguredash}[\z@]%
  {\setlength{\typog@raisefiguredash}{#1}}
\DeclareOptionX<typog>{raise*}[\z@]%
  {\setlength{\typog@raisecapitaldash}{#1}%
   \setlength{\typog@raisecapitalhyphen}{#1}%
   \setlength{\typog@raisecapitaltimes}{#1}%
   \setlength{\typog@raisefiguredash}{#1}}
\DeclareOptionX<typog>{shrinklimits}%
  [\typog@default@shrink@i, \typog@default@shrink@ii, \typog@default@shrink@iii]%
  {\typog@require@preloaded@microtype
   \ifx\@onlypreamble\@notprerr
     \PackageWarning{typog}{option `shrinklimits' can only be used in the preamble}%
   \else
     \edef\typog@shrinklimits{#1}%
     \typog@set@shrink@limits
   \fi}
\DeclareOptionX<typog>{slashkern}[.05em]%
  {\setlength{\typog@slashkern}{#1}}
\DeclareOptionX<typog>{stretchlimits}%
  [\typog@default@stretch@i, \typog@default@stretch@ii, \typog@default@stretch@iii]%
  {\typog@require@preloaded@microtype
   \ifx\@onlypreamble\@notprerr
     \PackageWarning{typog}{option `stretchlimits' can only be used in the preamble}%
   \else
     \edef\typog@stretchlimits{#1}%
     \typog@set@stretch@limits
   \fi}
\DeclareOptionX<typog>{trackingttspacing}[\typog@trackingttspacing]%
  {\typog@require@preloaded@microtype
   \ifx\@onlypreamble\@notprerr
     \PackageWarning{typog}{option `trackingttspacing' can only be used in the preamble}%
   \else
     \typog@typeout{trackingttspacing=#1}%
     \SetTracking[outer spacing={#1}]{encoding=*, family=tt*}{0}%
   \fi}

\newcommand*{\typog@initialize@options}
  {\ExecuteOptionsX<typog>{
     ligaturekern,
     mathitalicscorrection, textitalicscorrection,
     raisecapitaldash, raisecapitalhyphen, raisecapitaltimes,
     raiseguillemets, raisecapitalguillemets,
     raisefiguredash,
     slashkern}
   \ifdefined\MT@MT
     \unless\ifx\@onlypreamble\@notprerr
       \ExecuteOptionsX<typog>{shrinklimits, stretchlimits}
     \fi
   \fi}

\typog@initialize@options
\ProcessOptionsX<typog>

\NewDocumentEnvironment{typogsetup}{m}
  {\def\typog@@arg{#1}%
   \ifx\typog@@arg\empty
     \typog@initialize@options
   \else
     \setkeys{typog}{#1}%
   \fi
   \ignorespaces}
  {\ignorespacesafterend}
\NewDocumentCommand{\typogget}{m}{\csname typog@#1\endcsname}

\ExplSyntaxOn
\newcommand*{\typog@round@dim@to@tenths}[1]
  {\fp_to_decimal:n {round(10 * \dim_to_fp:n{#1} / 1\p@) / 10}}
\ExplSyntaxOff

\newcommand*{\typog@formatsizeinfo}[3]
  {#1#3\kernedslash #2#3}

\NewDocumentCommand{\fontsizeinfo}{s m}
  {\global\expandafter\edef\csname typog@fontsize@#2\endcsname
     {\typog@round@dim@to@tenths{\fontdimen6\font}}%
   \global\expandafter\edef\csname typog@linespacing@#2\endcsname
     {\typog@round@dim@to@tenths{\baselineskip}}%
   \protected\expandafter\gdef\csname #2\endcsname
     {\@ifnextchar*{\typog@formatsizeinfo
                      {\csname typog@fontsize@#2\endcsname}%
                      {\csname typog@linespacing@#2\endcsname}%
                      {}% no unit
                      \ignorespaces % eat spaces after star
                      \@gobble}     % consume the star itself
                   {\typog@formatsizeinfo
                      {\csname typog@fontsize@#2\endcsname}%
                      {\csname typog@linespacing@#2\endcsname}%
                      {\,pt}% decorative unit `pt'
  }}}

\newcommand*{\typog@default@inspect@id@prefix}{a-}
\newcounter{typog@inspect@count}
\define@key[typog]{typoginspect}{tracingboxes}[\maxdimen]%
           {\def\typog@@typoginspect@tracingboxes{#1}}
\NewDocumentEnvironment{typoginspect}{O{} m}
  {\def\typog@@typoginspect@tracingboxes{\m@ne}%
   \setkeys[typog]{typoginspect}{#1}%
   \edef\typog@@arg{#2}%
   \ifx\typog@@arg\empty
     \stepcounter{typog@inspect@count}%
     \edef\typog@@id{\typog@default@inspect@id@prefix\arabic{typog@inspect@count}}%
   \else
     \edef\typog@@id{\typog@trim@spaces{\typog@@arg}}%
   \fi
   \typeout{<typog-inspect id="\typog@@id" job="\jobname" line="\the\inputlineno" page="\the\value{page}">}%
   \hbadness=\m@ne
   \vbadness=\m@ne
   \tracingnone
   \tracingpages=\@ne
   \tracingparagraphs=\@ne
   \showboxbreadth=\typog@@typoginspect@tracingboxes
   \showboxdepth=\typog@@typoginspect@tracingboxes}
  {\typeout{</typog-inspect>}%
   \ignorespacesafterend}
\NewDocumentEnvironment{typoginspectpar}{m}
  {\typoginspect{#1}}
  {\par\endtypoginspect}

\newcommand*{\typog@allowhyphenation}
  {\ifvmode
     \relax
   \else
     \nobreak
     \hskip\z@skip
   \fi}

\unless\ifdefined\allowhyphenation
  \let\allowhyphenation=\typog@allowhyphenation
\fi

\NewDocumentCommand{\breakpoint}{s}
  {\discretionary{}{}{}%
   \IfBooleanTF{#1}%
     {\ignorespaces}%
     {\typog@allowhyphenation}}

\typog@register@pdfsubstitute{
  \def\breakpoint#1{\if*\detokenize{#1}\ignorespaces\fi}%
}

\NewDocumentEnvironment{hyphenmin}{o m}
  {\lefthyphenmin=\IfNoValueTF{#1}{#2}{#1}%
   \righthyphenmin=#2}
  {}

\newcommand*{\typog@hyphen}{\char`-}

\NewDocumentCommand{\nolig}{s o}
  {\dimen0=\IfNoValueTF{#2}{\typog@ligaturekern}{#2\typog@dim@unit}%
   \IfBooleanTF{#1}%
     {\kern\dimen0\ignorespaces}%
     {\discretionary{\typog@hyphen}{}{\kern\dimen0}%
      \typog@allowhyphenation
      \IfNoValueF{#2}{\ignorespaces}}}

\typog@register@pdfsubstitute{
  \RenewExpandableDocumentCommand{\nolig}{s o m}{%
    \ifx\typog@TYPOG#3\typog@TYPOG
      \relax
    \else
      \ifx\relax#3\relax
        \relax
      \else
        \PackageError{typog}
                     {Missing third argument of \nolig}
                     {Append empty group or \relax after macro invocation}
      \fi
    \fi}
}

\newcommand*{\typog@itcorr@text@unconditional}[1]
  {\kern#1\typog@textitalicscorrection}
\newcommand*{\typog@itcorr@text}[1]
  {\def\typog@@strength{#1}%
   \dimen0=\fontdimen1\font
   \ifdim\dimen0=\z@
     \typog@itcorr@text@unconditional{\typog@@strength}%
   \else
     \kern\typog@@strength\dimen0
   \fi}
\newcommand*{\typog@itcorr@math}[1]
  {\mkern#1\typog@mathitalicscorrection}
\NewDocumentCommand{\itcorr}{s m}
  {\ifmmode
     \typog@itcorr@math{#2}%
   \else
     \IfBooleanTF{#1}%
       {\typog@itcorr@text{#2}}%
       {\typog@itcorr@text@unconditional{#2}}%
   \fi}
\typog@register@pdfsubstitute{
  \RenewExpandableDocumentCommand{\itcorr}{s m}{}
}

\newcommand*{\typog@forwardslash}{\char`/}
\NewDocumentCommand{\kernedslash}{s}
  {\hspace*{\typog@slashkern}%
   \typog@forwardslash
   \IfBooleanTF{#1}%
     {\hspace*{\typog@slashkern}\ignorespaces}%
     {\typog@breakpoint\typog@allowhyphenation\hspace*{\typog@slashkern}}}
\typog@register@pdfsubstitute{
  \def\kernedslash#1{\if*\detokenize{#1}/\ignorespaces\else/#1\fi}%
}

\NewDocumentCommand{\kernedhyphen}{s O{0} m m}
  {\ifmmode
     \mspace{\muexpr(#3 mu) * 18 / 1000}%
     \raisebox{#2\typog@dim@unit}{$\m@th\mathord{-}$}%
     \mspace{\muexpr(#4 mu) * 18 / 1000}%
   \else
     \def\typog@@auto{*}%
     \def\typog@@optarg{#2}%
     \hspace*{#3\typog@dim@unit}%
     \raisebox{\ifx\typog@@optarg\typog@@auto
                 \typog@raisecapitalhyphen
               \else
                 \typog@@optarg\typog@dim@unit
               \fi}{\typog@hyphen}%
     \hspace{#4\typog@dim@unit}%
     \IfBooleanT{#1}{\nobreak}%
   \fi}
\typog@register@pdfsubstitute{
  \RenewExpandableDocumentCommand{\kernedhyphen}{s o m m}{-}
}
\NewDocumentCommand{\leftkernedhyphen}{s O{0} m}
  {\IfBooleanTF{#1}%
     {\kernedhyphen*[#2]{#3}{0}\ignorespaces}%
     {\kernedhyphen[#2]{#3}{0}}}
\typog@register@pdfsubstitute{
  \RenewExpandableDocumentCommand{\leftkernedhyphen}{s o m}{-}
}

\NewDocumentCommand{\rightkernedhyphen}{s O{0} m}
  {\IfBooleanTF{#1}%
     {\kernedhyphen*[#2]{0}{#3}\ignorespaces}%
     {\kernedhyphen[#2]{0}{#3}}}
\typog@register@pdfsubstitute{
  \RenewExpandableDocumentCommand{\rightkernedhyphen}{s o m}{-}
}

\newcommand*{\typog@breakpoint}
  {\penalty\typog@breakpenalty}
\NewDocumentCommand{\capitalhyphen}{s}
  {\raisebox{\typog@raisecapitalhyphen}{\typog@hyphen}%
   \IfBooleanTF{#1}%
     {\ignorespaces}%
     {\typog@breakpoint\typog@allowhyphenation}}
\typog@register@pdfsubstitute{
  \def\capitalhyphen#1{%
    \if*\detokenize{#1}%
      -\ignorespaces
    \else
      -#1%
    \fi}
}

\NewDocumentCommand{\capitalendash}{s}
  {\raisebox{\typog@raisecapitaldash}{\textendash}%
   \IfBooleanTF{#1}%
     {\ignorespaces}%
     {\typog@breakpoint\typog@allowhyphenation}}
\let\capitaldash=\capitalendash
\typog@register@pdfsubstitute{
  \def\capitalendash#1{%
    \if*\detokenize{#1}%
      \textendash\ignorespaces
    \else
      \textendash#1%
    \fi}
  \let\capitaldash=\capitalendash
}

\NewDocumentCommand{\capitalemdash}{s}
  {\raisebox{\typog@raisecapitaldash}{\textemdash}%
   \IfBooleanTF{#1}%
     {\ignorespaces}%
     {\typog@breakpoint\typog@allowhyphenation}}
\typog@register@pdfsubstitute{
  \def\capitalemdash#1{%
    \if*\detokenize{#1}%
      \textemdash\ignorespaces
    \else
      \textemdash#1%
    \fi}
}

\NewDocumentCommand{\figuredash}{s}
  {\raisebox{\typog@raisefiguredash}{\textendash}%
   \IfBooleanTF{#1}%
     {\ignorespaces}%
     {\typog@breakpoint\typog@allowhyphenation}}
\typog@register@pdfsubstitute{\let\figuredash=\capitaldash}

\NewDocumentCommand{\capitaltimes}{}
  {\ifmmode
     \mathbin{\raisebox{\typog@raisecapitaltimes}{$\m@th\times$}}%
   \else
     \raisebox{\typog@raisecapitaltimes}{\texttimes}%
   \fi}
\typog@register@pdfsubstitute{
  \RenewExpandableDocumentCommand{\capitaltimes}{}{\texttimes}
}

\NewDocumentCommand{\singleguillemetleft}{}
  {\typog@allowhyphenation
   \raisebox{\typog@raiseguillemets}{\guilsinglleft}}
\typog@register@pdfsubstitute{\let\singleguillemetleft\guilsinglleft}
\NewDocumentCommand{\singleguillemetright}{}
  {\raisebox{\typog@raiseguillemets}{\guilsinglright}%
   \typog@allowhyphenation}
\typog@register@pdfsubstitute{\let\singleguillemetright\guilsinglright}
\NewDocumentCommand{\doubleguillemetleft}{}
  {\typog@allowhyphenation
   \raisebox{\typog@raiseguillemets}{\guillemotleft}}
\typog@register@pdfsubstitute{\let\doubleguillemetleft\guillemotleft}
\NewDocumentCommand{\doubleguillemetright}{}
  {\raisebox{\typog@raiseguillemets}{\guillemotright}%
   \typog@allowhyphenation}
\typog@register@pdfsubstitute{\let\doubleguillemetright\guillemotright}
\NewDocumentCommand{\Singleguillemetleft}{}
  {\typog@allowhyphenation
   \raisebox{\typog@raisecapitalguillemets}{\guilsinglleft}}
\typog@register@pdfsubstitute{\let\Singleguillemetleft\guilsinglleft}
\NewDocumentCommand{\Singleguillemetright}{}
  {\raisebox{\typog@raisecapitalguillemets}{\guilsinglright}%
   \typog@allowhyphenation}
\typog@register@pdfsubstitute{\let\Singleguillemetright\guilsinglright}
\NewDocumentCommand{\Doubleguillemetleft}{}
  {\typog@allowhyphenation
   \raisebox{\typog@raisecapitalguillemets}{\guillemotleft}}
\typog@register@pdfsubstitute{\let\Doubleguillemetleft\guillemotleft}
\NewDocumentCommand{\Doubleguillemetright}{}
  {\raisebox{\typog@raisecapitalguillemets}{\guillemotright}%
   \typog@allowhyphenation}
\typog@register@pdfsubstitute{\let\Doubleguillemetright\guillemotright}

\NewDocumentEnvironment{lastlineraggedleftpar}{}
  {\lastlinefit=0%
   \setlength{\leftskip}{\z@ \@plus 1fil}%
   \setlength{\rightskip}{-\leftskip}%
   \setlength{\parfillskip}{\leftskip}}
  {\par}
\let\lastlineflushrightpar=\lastlineraggedleftpar
\let\endlastlineflushrightpar=\endlastlineraggedleftpar

\NewDocumentEnvironment{lastlinecenteredpar}{}
  {\lastlinefit=0%
   \setlength{\leftskip}{\z@ \@plus .5fil}%
   \setlength{\rightskip}{-\leftskip}%
   \setlength{\parfillskip}{\z@ \@plus 1fil}}
  {\par}

\NewDocumentEnvironment{shortenpar}{}
  {\advance\looseness by -1
   \ifnum\tracingparagraphs>0
     \typeout{@ looseness \the\looseness}%
   \fi}
  {\par}

\NewDocumentEnvironment{prolongpar}{}
  {\finalhyphendemerits=100000001
   \advance\looseness by 1
   \ifnum\tracingparagraphs>0
     \typeout{@ looseness \the\looseness}%
   \fi}
  {\par}

\newcommand*{\typog@covernextindentpar@zero@parindent}{2em}
\newcommand*{\typog@covernextindentpar@nonzero@parindent}{2\parindent}
\NewDocumentEnvironment{covernextindentpar}{o}
  {\IfNoValueTF{#1}
     {\ifdim\parindent=\z@
        \dimen0=\dimexpr\linewidth - \typog@covernextindentpar@zero@parindent
      \else
        \dimen0=\dimexpr\linewidth - \typog@covernextindentpar@nonzero@parindent
      \fi}
     {\dimen0=\dimexpr\linewidth - (#1)}%
   \parfillskip=\dimen0 \@minus \dimen0
   \relax}
  {\par}

\newcommand*{\typog@openlastlinepar@zero@parindent}{2em}
\newcommand*{\typog@openlastlinepar@nonzero@parindent}{2\parindent}
\NewDocumentEnvironment{openlastlinepar}{o}
  {\IfNoValueTF{#1}
     {\ifdim\parindent=\z@
        \skip0=\typog@openlastlinepar@zero@parindent
               \@plus 1fil
               \@minus \typog@openlastlinepar@zero@parindent
      \else
        \skip0=\typog@openlastlinepar@nonzero@parindent
               \@plus 1fil
               \@minus \typog@openlastlinepar@nonzero@parindent
      \fi}
     {\dimen0=\dimexpr#1\relax
      \skip0=\dimen0 \@plus 1fil \@minus \dimen0}
   \parfillskip=\skip0}
  {\par}

\newcommand*{\widespacestrength}{1.}
\newcommand*{\widespacescale}{1.125}
\NewDocumentCommand{\widespace}{s}
  {\IfBooleanTF{#1}%
    {\dimen0=\widespacescale\fontdimen2\font}%
    {\ifdim\fontdimen7\font=\z@
       \dimen0=\widespacescale\fontdimen2\font
     \else
       \dimen0=\dimexpr\fontdimen2\font +
               \widespacestrength\fontdimen7\font
     \fi}%
   \hskip \glueexpr\dimen0
          \@plus \widespacescale\fontdimen3\font
          \@minus \widespacescale\fontdimen4\font
   \ignorespaces}

\newcommand*{\narrowspacestrength}{.5}
\newcommand*{\narrowspacescale}{.9375}
\NewDocumentCommand{\narrowspace}{s}
  {\IfBooleanTF{#1}%
     {\dimen0=\narrowspacescale\fontdimen2\font}%
     {\ifdim\fontdimen7\font=\z@
        \dimen0=\narrowspacescale\fontdimen2\font
      \else
        \dimen0=\dimexpr\fontdimen2\font -
                \narrowspacestrength\fontdimen7\font
      \fi}%
   \hskip \glueexpr\dimen0
          \@plus \narrowspacescale\fontdimen3\font
          \@minus \narrowspacescale\fontdimen4\font
   \ignorespaces}

\NewDocumentEnvironment{loosespacing}{O{1}}
  {\dimen2=\fontdimen2\font
   \ifcase #1
     \spaceskip=\z@
   \or % 1         +5%
     \spaceskip=1.05\dimen2 \@plus .5\dimen2 \@minus .1\dimen2
   \or % 2         +10%
     \spaceskip=1.1\dimen2 \@plus .5\dimen2 \@minus .1\dimen2
   \or % 3         +20%
     \spaceskip=1.2\dimen2 \@plus .6\dimen2 \@minus .2\dimen2
   \else % >= 4    +30%
     \spaceskip=1.3\dimen2 \@plus .8\dimen2 \@minus .3\dimen2
   \fi
   \ignorespaces}
  {\ignorespacesafterend}

\NewDocumentEnvironment{tightspacing}{O{1}}
  {\dimen2=\fontdimen2\font
   \ifcase #1
     \spaceskip=\z@
   \or % 1          -1.25%
     \spaceskip=.9875\dimen2 \@plus .0125\dimen2 \@minus .5\dimen2
   \or % 2          -2.5%
     \spaceskip=.975\dimen2 \@plus .025\dimen2 \@minus .5\dimen2
   \or % 3          -5%
     \spaceskip=.95\dimen2 \@plus .05\dimen2 \@minus .5\dimen2
   \else % >= 4    -10%
     \spaceskip=.9\dimen2 \@plus .1\dimen2 \@minus .5\dimen2
   \fi
   \ignorespaces}
  {\ignorespacesafterend}

\NewDocumentEnvironment{setfonttracking}{m}
  {\edef\MT@letterspace@{#1}%
   \lsstyle
   \ignorespaces}
  {\ignorespacesafterend}

\newcommand*{\typog@setup@font@expansion}
  {\SetExpansion
     [context = typog@shrink1,
      shrink = \typog@shrink@i,
      stretch = 0]%
     {encoding = {*}}%
     {}
   \SetExpansion
     [context = typog@shrink2,
      shrink = \typog@shrink@ii,
      stretch = 0]%
     {encoding = {*}}%
     {}
   \SetExpansion
     [context = typog@shrink3,
      shrink = \typog@shrink@iii,
      stretch = 0]%
     {encoding = {*}}%
     {}

   \SetExpansion
     [context = typog@stretch1,
      shrink = 0,
      stretch = \typog@stretch@i]%
     {encoding = {*}}%
     {}
   \SetExpansion
     [context = typog@stretch2,
      shrink = 0,
      stretch = \typog@stretch@ii]%
     {encoding = {*}}%
     {}
   \SetExpansion
     [context = typog@stretch3,
      shrink = 0,
      stretch = \typog@stretch@iii]%
     {encoding = {*}}%
     {}

   \SetExpansion
     [context = typog@expand1,
      shrink = \typog@shrink@i,
      stretch = \typog@stretch@i]%
     {encoding = {*}}%
     {}
   \SetExpansion
     [context = typog@expand2,
      shrink = \typog@shrink@ii,
      stretch = \typog@stretch@ii]%
     {encoding = {*}}%
     {}
   \SetExpansion
     [context = typog@expand3,
      shrink = \typog@shrink@iii,
      stretch = \typog@stretch@iii]%
     {encoding = {*}}%
     {}}
\newcommand*{\typog@test@microtype@expansion@feature}
  {\ifMT@expansion
     \typog@typeout{microtype preloaded -- font expansion features available}%
     \def\typog@require@microtype@expansion{\relax}
     \typog@setup@font@expansion
   \else
     \PackageWarning{typog}{microtype preloaded,\space
                            but font expansion is disabled}%
     \def\typog@require@microtype@expansion
       {\PackageError{typog}
                     {microtype font expansion disabled}
                     {pass option `expansion' to package microtype}}
   \fi}
\iftypog@microtype@preloaded
  \typog@test@microtype@expansion@feature
\else
  \def\typog@require@microtype@expansion
    {\PackageError{typog}%
                  {package microtype not (pre-)loaded, %
                   which is required for typog's font expansion}%
                  {require package microtype before package typog}}
\fi

\NewDocumentEnvironment{setfontshrink}{O{1}}
  {\typog@require@microtype@expansion
   \ifcase#1% 0
     \relax
   \or % 1
     \microtypecontext{expansion=typog@shrink1}%
   \or % 2
     \microtypecontext{expansion=typog@shrink2}%
   \else % >= 3
     \microtypecontext{expansion=typog@shrink3}%
   \fi
   \ignorespaces}
  {\ignorespacesafterend}

\NewDocumentEnvironment{setfontstretch}{O{1}}
  {\typog@require@microtype@expansion
   \ifcase#1% 0
     \relax
   \or % 1
     \microtypecontext{expansion=typog@stretch1}%
   \or % 2
     \microtypecontext{expansion=typog@stretch2}%
   \else % >= 3
     \microtypecontext{expansion=typog@stretch3}%
   \fi
   \ignorespaces}
  {\ignorespacesafterend}

\NewDocumentEnvironment{setfontexpand}{O{1}}
  {\typog@require@microtype@expansion
   \ifcase#1% 0
     \relax
   \or % 1
     \microtypecontext{expansion=typog@expand1}%
   \or % 2
     \microtypecontext{expansion=typog@expand2}%
   \else % >= 3
     \microtypecontext{expansion=typog@expand3}%
   \fi
   \ignorespaces}
  {\ignorespacesafterend}

\NewDocumentEnvironment{nofontexpansion}{}
  {\ifdefined\microtypesetup
     \microtypesetup{expansion=false}%
   \fi
   \ignorespaces}
  {\ignorespacesafterend}
\let\nofontexpand=\nofontexpansion
\let\endnofontexpand=\endnofontexpansion

\NewDocumentEnvironment{nocharprotrusion}{}
  {\ifdefined\microtypesetup
     \microtypesetup{protrusion=false}%
   \fi
   \ignorespaces}
  {\ignorespacesafterend}

\newcommand*{\typog@scaled@emergencystretch}[1]
  {\emergencystretch=\ifdim\linewidth=\z@
                       #1%
                     \else
                       \dimexpr (#1) * \linewidth / \textwidth
                     \fi}

\NewDocumentCommand{\slightlysloppy}{O{1}}
  {\ifcase #1% 0
     % \tolerance=200
     % \emergencystretch=\z@
     % \hfuzz=.1\p@
     % \vfuzz=\hfuzz
     \fussy
   \or % 1
     \pretolerance=165%
     \tolerance=330%
     \typog@scaled@emergencystretch{.375em}%
     \hfuzz=.15\p@
     \vfuzz=\hfuzz
   \or % 2
     \pretolerance=265%
     \tolerance=530%
     \typog@scaled@emergencystretch{.75em}%
     \hfuzz=.15\p@
     \vfuzz=\hfuzz
   \or % 3
     \pretolerance=435%
     \tolerance=870%
     \typog@scaled@emergencystretch{1.125em}%
     \hfuzz=.2\p@
     \vfuzz=\hfuzz
   \or % 4
     \pretolerance=705%
     \tolerance=1410%
     \typog@scaled@emergencystretch{1.5em}%
     \hfuzz=.3\p@
     \vfuzz=\hfuzz
   \or % 5
     \pretolerance=1155%
     \tolerance=2310%
     \typog@scaled@emergencystretch{1.875em}%
     \hfuzz=.35\p@
     \vfuzz=\hfuzz
   \or % 6
     \pretolerance=1880%
     \tolerance=3760%
     \typog@scaled@emergencystretch{2.25em}%
     \hfuzz=.4\p@
     \vfuzz=\hfuzz
   \or % 7
     \pretolerance=3065%
     \tolerance=6130%
     \typog@scaled@emergencystretch{2.625em}%
     \hfuzz=.45\p@
     \vfuzz=\hfuzz
   \else % >= 8
     % \tolerance=9999
     % \emergencystretch=3em
     % \hfuzz=.5\p@
     % \vfuzz=\hfuzz
     \sloppy
   \fi
   \ignorespaces}
\NewDocumentEnvironment{slightlysloppypar}{O{1}}
  {\par\slightlysloppy[#1]\ignorespaces}
  {\par}

\ExplSyntaxOn
\newcommand*{\typog@geometric@mean}[2]
            {\fp_to_int:n {sqrt((#1) * (#2))}}
\ExplSyntaxOff

\newcounter{typog@mean@penalty}

\NewDocumentCommand{\vtietop}{O{3}}
  {\setcounter{typog@mean@penalty}
              {\typog@geometric@mean{\@M}{\clubpenalty}}%
   \typog@typeout{vtietop: penalties \the\@M--\the\value{typog@mean@penalty}--\the\clubpenalty}%
   \unless\ifnum\clubpenalty<\@M
     \PackageWarning{typog}{vtietop: clubpenalty=\the\clubpenalty\space>= 10000}%
   \fi
   \ifcase#1% 0
     \relax
   \or % 1
     \relax
   \or % 2
     \clubpenalties 3
         \@M
         \value{typog@mean@penalty}
         \clubpenalty
   \or % 3
     \clubpenalties 4
         \@M \@M
         \value{typog@mean@penalty}
         \clubpenalty
   \or % 4
     \clubpenalties 5
         \@M \@M \@M
         \value{typog@mean@penalty}
         \clubpenalty
   \or % 5
     \clubpenalties 6
         \@M \@M \@M \@M
         \value{typog@mean@penalty}
         \clubpenalty
   \or % 6
     \clubpenalties 7
         \@M \@M \@M \@M \@M
         \value{typog@mean@penalty}
         \clubpenalty
   \or % 7
     \clubpenalties 8
         \@M \@M \@M \@M \@M
         \value{typog@mean@penalty}
         \clubpenalty
   \or % 8
     \clubpenalties 9
         \@M \@M \@M \@M \@M
         \value{typog@mean@penalty}
         \clubpenalty
   \else % >= 9
     \clubpenalties 10
         \@M \@M \@M \@M \@M \@M \@M \@M
         \value{typog@mean@penalty}
         \clubpenalty
   \fi}

\NewDocumentEnvironment{vtietoppar}{O{3}}
  {\vtietop[#1]}
  {\par
   \ignorespacesafterend}

\NewDocumentCommand{\splicevtietop}{O{3}}
  {\let\typog@old@item=\@item
   \def\@item[##1]{\typog@old@item[##1]\vtietop[#1]}%
   \ignorespaces}

\ifdefined\SetEnumitemKey
  \SetEnumitemKey{vtietop}{first=\splicevtietop}
\fi

\NewDocumentCommand{\vtiebot}{O{3}}
  {\setcounter{typog@mean@penalty}
              {\typog@geometric@mean{\@M}{\widowpenalty}}%
   \typog@typeout{vtiebot: penalties \the\@M--\the\value{typog@mean@penalty}--\the\widowpenalty}%
   \unless\ifnum\widowpenalty<\@M
     \PackageWarning{typog}{vtiebot: widowpenalty=\the\widowpenalty\space>= 10000}%
   \fi
   \ifcase#1% 0
     \relax
   \or % 1
     \relax
   \or % 2
     \widowpenalties 3
         \@M
         \value{typog@mean@penalty}
         \widowpenalty
   \or % 3
     \widowpenalties 4
         \@M \@M
         \value{typog@mean@penalty}
         \widowpenalty
   \or % 4
     \widowpenalties 5
         \@M \@M \@M
         \value{typog@mean@penalty}
         \widowpenalty
   \or % 5
     \widowpenalties 6
         \@M \@M \@M \@M
         \value{typog@mean@penalty}
         \widowpenalty
   \or % 6
     \widowpenalties 7
         \@M \@M \@M \@M \@M
         \value{typog@mean@penalty}
         \widowpenalty
   \or % 7
     \widowpenalties 8
         \@M \@M \@M \@M \@M \@M
         \value{typog@mean@penalty}
         \widowpenalty
   \or % 8
     \widowpenalties 9
         \@M \@M \@M \@M \@M \@M \@M
         \value{typog@mean@penalty}
         \widowpenalty
   \else % >= 9
     \widowpenalties 10
         \@M \@M \@M \@M \@M \@M \@M \@M
         \value{typog@mean@penalty}
         \widowpenalty
   \fi}

\NewDocumentEnvironment{vtiebotpar}{O{3}}
  {\vtiebot[#1]}
  {\par
   \ignorespacesafterend}

\NewDocumentCommand{\typog@vtiebotdisp}{m}
  {\setcounter{typog@mean@penalty}
              {\typog@geometric@mean{\@M}{\displaywidowpenalty}}%
   \typog@typeout{vtiebotdisp: penalties \the\@M--\the\value{typog@mean@penalty}--\the\displaywidowpenalty}%
   \unless\ifnum\displaywidowpenalty<\@M
     \PackageWarning{typog}{vtiebotdisp: displaywidowpenalty=\the\displaywidowpenalty\space>= 10000}%
   \fi
   \ifcase#1% 0
     \relax
   \or % 1
     \relax
   \or % 2
     \displaywidowpenalties 3
         \@M
         \value{typog@mean@penalty}
         \displaywidowpenalty
   \or % 3
     \displaywidowpenalties 4
         \@M \@M
         \value{typog@mean@penalty}
         \displaywidowpenalty
   \or % 4
     \displaywidowpenalties 5
         \@M \@M \@M
         \value{typog@mean@penalty}
         \displaywidowpenalty
   \or % 5
     \displaywidowpenalties 6
         \@M \@M \@M \@M
         \value{typog@mean@penalty}
         \displaywidowpenalty
   \or % 6
     \displaywidowpenalties 7
         \@M \@M \@M \@M \@M
         \value{typog@mean@penalty}
         \displaywidowpenalty
   \or % 7
     \displaywidowpenalties 8
         \@M \@M \@M \@M \@M \@M
         \value{typog@mean@penalty}
         \displaywidowpenalty
   \or % 8
     \displaywidowpenalties 9
         \@M \@M \@M \@M \@M \@M \@M
         \value{typog@mean@penalty}
         \displaywidowpenalty
   \else % >= 9
     \displaywidowpenalties 10
         \@M \@M \@M \@M \@M \@M \@M \@M
         \value{typog@mean@penalty}
         \displaywidowpenalty
   \fi}

\NewDocumentEnvironment{vtiebotdisp}{O{3}}
  {\typog@vtiebotdisp{#1}}
  {\ignorespacesafterend}

\NewDocumentEnvironment{vtiebotdisptoppar}{O{3}o}
  {\postdisplaypenalty=\@M
   \predisplaypenalty=10001% in accordance with package `widows-and-orphans'
   \edef\typog@@top@lines{\IfNoValueTF{#2}{#1}{#2}}%
   \edef\typog@@after@display@math{\vtietop[\typog@@top@lines]}%
   \PushPostHook{display}{\aftergroup\typog@@after@display@math}%
   \vtiebotdisp[#1]}
  {\par
   \PopPostHook{display}%
   \ignorespacesafterend}

\newenvironment*{breakabledisplay}[1][3]
  {\allowdisplaybreaks[#1]}
  {\ignorespacesafterend}

\newcommand*{\typog@setbaselineskip@iter@limit}{10}
\newcommand*{\typog@setbaselineskip@relative@error}{.001}
\ExplSyntaxOn
\cs_new:Npn \typog@setbaselineskip #1
{
  \int_set:Nn \l_tmpa_int {1}
  \int_set:Nn \l_tmpb_int {\typog@setbaselineskip@iter@limit}
  \dim_set:Nn \l_tmpa_dim {\glueexpr #1}

  \typog@typeout{\string\setbaselineskip:\space
    initial\space baselineskip:\space \the\baselineskip}
  \typog@typeout{\string\setbaselineskip:\space
    target\space baselineskip:\space \dim_use:N \l_tmpa_dim}

  \dim_compare:nNnTF {\baselineskip} > {\c_zero_dim}
  {}
  {
    \PackageError{typog}
                 {\string\setbaselineskip:\space
                   baselineskip\space not\space positive}
                 {}
  }

  \dim_compare:nNnTF {\l_tmpa_dim} > {\c_zero_dim}
  {}
  {
    \PackageError{typog}
                 {\string\setbaselineskip:\space target\space
                   baselineskip\space must\space be\space
                   positive}
                 {}
  }

  \skip_if_eq:nnTF {\l_tmpa_dim} {\glueexpr #1}
  {}
  {
    \PackageWarning{typog}
                   {\string\setbaselineskip:\space argument\space
                     is\space a\space skip;\space
                     will\space ignore\space glue}
                   {}
  }

  \fp_set:Nn \l_tmpa_fp {\l_tmpa_dim / \baselineskip}
  \fp_until_do:nNnn {abs(\l_tmpa_dim / \baselineskip - 1)} <
                    {\typog@setbaselineskip@relative@error}
  {
    \setstretch{\fp_use:N \l_tmpa_fp}
    \fp_set:Nn \l_tmpa_fp
               {\l_tmpa_fp * \l_tmpa_dim / \baselineskip}

    \int_incr:N \l_tmpa_int
    \int_compare:nNnTF {\l_tmpa_int} > {\l_tmpb_int}
    {
      \PackageError{typog}
                   {\string\setbaselineskip:\space excessive\space
                     number\space of\space iterations:\space
                     \int_use:N \l_tmpa_int\space >\space
                     \int_use:N \l_tmpb_int}
                   {}
    }
    {}
  }

  \typog@typeout{\string\setbaselineskip:\space
    final\space \string\setstretch\space argument:\space
    \fp_use:N \l_tmpa_fp}
  \typog@typeout{\string\setbaselineskip:\space
    final\space baselineskip:\space \the\baselineskip}
}

\cs_new:Npn \setbaselineskip #1
{
  \AfterPreamble{\typog@setbaselineskip{#1}}
  \ignorespaces
}

\cs_new:Npn \resetbaselineskip
{
  \AfterPreamble{\setstretch{1}}
}

\dim_new:N \typogfontsize
\AfterEndPreamble{
  \dim_set:Nn \typogfontsize {\fontdimen6\font}
  \typog@typeout{\string\typogfontsize =
    \dim_use:N \typogfontsize\space
    (at\space begin\space of\space document)}
}

\cs_new:Npn \setbaselineskippercentage #1
{
  \AfterPreamble{
    \dim_compare:nNnTF {\typogfontsize} > {\c_zero_dim}
    {
      \typog@setbaselineskip{
        \fp_eval:n {(#1) / 100} \typogfontsize}
    }
    {
      \PackageError{typog}
                   {\string\setbaselineskippercentage:\space
                    \string\typogfontsize <= 0}
                   {Maybe\space \string\typogfontsize\space
                     is\space uninitialized?}
    }
  }
  \ignorespaces
}

\cs_new:Npn \setleading #1
{
  \AfterPreamble{
    \dim_compare:nNnTF {\typogfontsize} > {\c_zero_dim}
    {
      \typog@setbaselineskip{\typogfontsize + \dimexpr #1}
    }
    {
      \PackageError{typog}
                   {\string\setleading:\space
                    \string\typogfontsize <= 0}
                   {Maybe\space \string\typogfontsize\space
                     is\space uninitialized?}
    }
  }
  \ignorespaces
}

\cs_new:Npn \setleadingpercentage #1
{
  \AfterPreamble{
    \dim_compare:nNnTF {\typogfontsize} > {\c_zero_dim}
    {
      \typog@setbaselineskip{
        \fp_eval:n {1 + (#1) / 100} \typogfontsize}
    }
    {
      \PackageError{typog}
                   {\string\setleadingpercentage:\space
                    \string\typogfontsize <= 0}
                   {Maybe\space \string\typogfontsize\space
                     is\space uninitialized?}
    }
  }
  \ignorespaces
}
\ExplSyntaxOff

\ExplSyntaxOn
\cs_new_eq:NN \typog@repeat \prg_replicate:nn

\newcommand*{\typog@mod}[2]{\int_mod:nn{#1}{#2}}
\ExplSyntaxOff

\newcommand*{\typog@triplet@max@lines}{99}

\define@key[typog]{smoothraggedrightshapetriplet}{leftskip}%
           {\def\typog@@triplet@leftskip{#1}}
\define@key[typog]{smoothraggedrightshapetriplet}{parindent}%
           {\def\typog@@triplet@parindent{#1}}
\NewDocumentEnvironment{smoothraggedrightshapetriplet}{O{} m m m}
  {\def\typog@@triplet@leftskip{\z@}%
   \def\typog@@triplet@parindent{\z@}%
   \setkeys*[typog]{smoothraggedrightshapetriplet}{#1}%
   \skip0=\typog@@triplet@leftskip\relax
   \skip1=#2\relax
   \skip2=#3\relax
   \skip3=#4\relax
   \typog@typeout{smoothraggedrightshapetriplet: skip0=\the\skip0}%
   \typog@typeout{smoothraggedrightshapetriplet: skip1=\the\skip1}%
   \typog@typeout{smoothraggedrightshapetriplet: skip2=\the\skip2}%
   \typog@typeout{smoothraggedrightshapetriplet: skip3=\the\skip3}%
   \unless\ifnum\typog@mod{\typog@triplet@max@lines}{3}=0
     \PackageError{typog}
                  {Line number of triplet generator %
                    (\typog@triplet@max@lines) not divisible by 3}
                  {}
   \fi
   \edef\typog@@triplet@linespecs{%
     \glueexpr \skip0 + \typog@@triplet@parindent\relax
            \glueexpr \skip1 - \typog@@triplet@parindent\relax
                    \skip0 \skip2  \skip0 \skip3
     \typog@repeat{\numexpr\typog@triplet@max@lines / 3 - 1}
                  {\skip0 \skip1  \skip0 \skip2  \skip0 \skip3}}
   \parshape=\typog@triplet@max@lines\typog@@triplet@linespecs\relax}
  {\par}

\newcommand*{\typog@quintuplet@max@lines}{95}

\define@key[typog]{smoothraggedrightshapequintuplet}{leftskip}
           {\def\typog@@quintuplet@leftskip{#1}}
\define@key[typog]{smoothraggedrightshapequintuplet}{parindent}
           {\def\typog@@quintuplet@parindent{#1}}
\NewDocumentEnvironment{smoothraggedrightshapequintuplet}{O{} m m m m m}
  {\def\typog@@quintuplet@leftskip{\z@}%
   \def\typog@@quintuplet@parindent{\z@}%
   \setkeys*[typog]{smoothraggedrightshapequintuplet}{#1}%
   \skip0=\typog@@quintuplet@leftskip
   \skip1=#2\relax
   \skip2=#3\relax
   \skip3=#4\relax
   \skip4=#5\relax
   \skip5=#6\relax
   \typog@typeout{smoothraggedrightshapequintuplet: skip0=\the\skip0}%
   \typog@typeout{smoothraggedrightshapequintuplet: skip1=\the\skip1}%
   \typog@typeout{smoothraggedrightshapequintuplet: skip2=\the\skip2}%
   \typog@typeout{smoothraggedrightshapequintuplet: skip3=\the\skip3}%
   \typog@typeout{smoothraggedrightshapequintuplet: skip4=\the\skip4}%
   \typog@typeout{smoothraggedrightshapequintuplet: skip5=\the\skip5}%
   \unless\ifnum\typog@mod{\typog@quintuplet@max@lines}{5}=0
     \PackageError{typog}
                  {Line number of quintuplet generator %
                    (\typog@quintuplet@max@lines) not divisible by 5}
                  {}
   \fi
   \edef\typog@@quintuplet@linespecs{%
     \glueexpr \skip0 + \typog@@quintuplet@parindent\relax
            \glueexpr \skip1 - \typog@@quintuplet@parindent\relax
                    \skip0 \skip2  \skip0 \skip3  \skip0 \skip4  \skip0 \skip5
     \typog@repeat{\numexpr\typog@quintuplet@max@lines / 5 - 1}
                  {\skip0 \skip1  \skip0 \skip2  \skip0 \skip3  \skip0 \skip4  \skip0 \skip5}}
   \parshape=\typog@quintuplet@max@lines\typog@@quintuplet@linespecs\relax}
  {\par}

\newcommand*{\typog@septuplet@max@lines}{98}

\define@key[typog]{smoothraggedrightshapeseptuplet}{leftskip}%
           {\def\typog@@septuplet@leftskip{#1}}
\define@key[typog]{smoothraggedrightshapeseptuplet}{parindent}%
           {\def\typog@@septuplet@parindent{#1}}
\NewDocumentEnvironment{smoothraggedrightshapeseptuplet}{O{} m m m m m m m}
  {\def\typog@@septuplet@leftskip{\z@}%
   \def\typog@@septuplet@parindent{\z@}%
   \setkeys*[typog]{smoothraggedrightshapeseptuplet}{#1}%
   \skip0=\typog@@septuplet@leftskip
   \skip1=#2\relax
   \skip2=#3\relax
   \skip3=#4\relax
   \skip4=#5\relax
   \skip5=#6\relax
   \skip6=#7\relax
   \skip7=#8\relax
   \typog@typeout{smoothraggedrightshapeseptuplet: skip0=\the\skip0}%
   \typog@typeout{smoothraggedrightshapeseptuplet: skip1=\the\skip1}%
   \typog@typeout{smoothraggedrightshapeseptuplet: skip2=\the\skip2}%
   \typog@typeout{smoothraggedrightshapeseptuplet: skip3=\the\skip3}%
   \typog@typeout{smoothraggedrightshapeseptuplet: skip4=\the\skip4}%
   \typog@typeout{smoothraggedrightshapeseptuplet: skip5=\the\skip5}%
   \typog@typeout{smoothraggedrightshapeseptuplet: skip6=\the\skip6}%
   \typog@typeout{smoothraggedrightshapeseptuplet: skip7=\the\skip7}%
   \unless\ifnum\typog@mod{\typog@septuplet@max@lines}{7}=0
     \PackageError{typog}
                  {Line number of septuplet generator %
                    (\typog@septuplet@max@lines) not divisible by 7}
                  {}
   \fi
   \edef\typog@@septuplet@linespecs{%
     \glueexpr \skip0 + \typog@@septuplet@parindent\relax
            \glueexpr \skip1 - typog@@septuplet@parindent\relax
                    \skip0 \skip2  \skip0 \skip3  \skip0 \skip4  \skip0 \skip5  \skip0 \skip6  \skip0 \skip7
     \typog@repeat{\numexpr\typog@septuplet@max@lines / 7 - 1}
                  {\skip0 \skip1  \skip0 \skip2  \skip0 \skip3  \skip0 \skip4  \skip0 \skip5  \skip0 \skip6  \skip0 \skip7}}
   \parshape=\typog@septuplet@max@lines\typog@@septuplet@linespecs\relax}
  {\par}

\newcommand*{\smoothraggedrightfuzzfactor}{1.0}
\newcommand*{\smoothraggedrightgenerator}{triplet}
\newlength{\smoothraggedrightleftskip}
\newlength{\smoothraggedrightparindent}
\newlength{\smoothraggedrightragwidth}
\setlength{\smoothraggedrightragwidth}{2em}

\newdimen{\typog@fuzzwidth}

\define@key[typog]{smoothraggedrightpar}{linewidth}%
           {\def\typog@@linewidth{#1}}

\NewDocumentEnvironment{smoothraggedrightpar}{O{}}
  {\edef\typog@@linewidth{\linewidth}%
   \setkeys[typog]{smoothraggedrightpar}{#1}%
   \edef\typog@@generatorchoice{%
     \ifnum\pdf@strcmp{\smoothraggedrightgenerator}{triplet}=\z@
       0%
     \else
       \ifnum\pdf@strcmp{\smoothraggedrightgenerator}{quintuplet}=\z@
         1%
       \else
         \ifnum\pdf@strcmp{\smoothraggedrightgenerator}{septuplet}=\z@
           2%
         \else
           \PackageError{typog}
                        {smoothraggedright: unknown generator name}
                        {valid generator names are triplet, quintuplet, and septuplet}%
         \fi
       \fi
     \fi}%
   \let\typog@@smoothraggedrightleftskip=\smoothraggedrightleftskip
   \ifnum\@listdepth>0
     \addtolength{\typog@@smoothraggedrightleftskip}{\leftmargin}%
   \fi
   \typog@fuzzwidth=\smoothraggedrightfuzzfactor\smoothraggedrightragwidth
   \ifcase\typog@@generatorchoice
     \typog@fuzzwidth=.25\smoothraggedrightragwidth
     \typog@typeout{smoothraggedright: generator=triplet, typog@fuzzwidth=\the\typog@fuzzwidth}%
     \smoothraggedrightshapetriplet[leftskip=\typog@@smoothraggedrightleftskip,
                                    parindent=\glueexpr\smoothraggedrightparindent + \parindent,
                                    #1]%
        {\glueexpr \typog@@linewidth - \smoothraggedrightragwidth
                   + \glueexpr \z@ \@plus \typog@fuzzwidth\relax}% (1)
        {\glueexpr \typog@@linewidth \@minus \typog@fuzzwidth}% (3)
        {\glueexpr (\typog@@linewidth * 2 - \smoothraggedrightragwidth) / 2
                   + \glueexpr \z@ \@plus \typog@fuzzwidth \@minus \typog@fuzzwidth\relax}% (2)
   \or
     \typog@fuzzwidth=.125\smoothraggedrightragwidth
     \typog@typeout{smoothraggedright: generator=quintuplet, typog@fuzzwidth=\the\typog@fuzzwidth}%
     \smoothraggedrightshapequintuplet[leftskip=\typog@@smoothraggedrightleftskip,
                                       parindent=\glueexpr\smoothraggedrightparindent + \parindent,
                                       #1]%
        {\glueexpr (\typog@@linewidth * 4 - \smoothraggedrightragwidth * 3) / 4
                   + \glueexpr \z@ \@plus \typog@fuzzwidth \@minus \typog@fuzzwidth\relax}% (2)
        {\glueexpr \typog@@linewidth \@minus \typog@fuzzwidth\relax}% (5)
        {\glueexpr (\typog@@linewidth * 2 - \smoothraggedrightragwidth) / 2
                   + \glueexpr \z@ \@plus \typog@fuzzwidth \@minus \typog@fuzzwidth\relax}% (3)
        {\glueexpr (\typog@@linewidth * 4 - \smoothraggedrightragwidth) / 4
                   + \glueexpr \z@ \@plus \typog@fuzzwidth \@minus \typog@fuzzwidth\relax}% (4)
        {\glueexpr \typog@@linewidth - \smoothraggedrightragwidth
                   + \glueexpr \z@ \@plus \typog@fuzzwidth\relax}% (1)
   \or
     \typog@fuzzwidth=.08333\smoothraggedrightragwidth
     \typog@typeout{smoothraggedright: generator=septuplet, typog@fuzzwidth=\the\typog@fuzzwidth}%
     \smoothraggedrightshapeseptuplet[leftskip=\typog@@smoothraggedrightleftskip,
                                      parindent=\glueexpr\smoothraggedrightparindent + \parindent,
                                      #1]%
        {\glueexpr (\typog@@linewidth * 3 - \smoothraggedrightragwidth * 2) / 3
                   + \glueexpr \z@ \@plus \typog@fuzzwidth \@minus \typog@fuzzwidth\relax}% (3)
        {\glueexpr (\typog@@linewidth * 6 - \smoothraggedrightragwidth) / 6
                   + \glueexpr \z@ \@plus \typog@fuzzwidth \@minus \typog@fuzzwidth\relax}% (6)
        {\glueexpr \typog@@linewidth - \smoothraggedrightragwidth +
                   + \glueexpr \z@ \@plus \typog@fuzzwidth\relax}% (1)
        {\glueexpr (\typog@@linewidth * 3 - \smoothraggedrightragwidth) / 3
                   + \glueexpr \z@ \@plus \typog@fuzzwidth \@minus \typog@fuzzwidth\relax}% (5)
        {\glueexpr (\typog@@linewidth * 6 - \smoothraggedrightragwidth * 5) / 6
                   + \glueexpr \z@ \@plus \typog@fuzzwidth \@minus \typog@fuzzwidth\relax}% (2)
        {\glueexpr \typog@@linewidth \@minus \typog@fuzzwidth\relax}% (7)
        {\glueexpr (\typog@@linewidth * 2 - \smoothraggedrightragwidth) / 2
                   + \glueexpr \z@ \@plus \typog@fuzzwidth \@minus \typog@fuzzwidth\relax}% (4)
   \fi}
  {\ifcase\typog@@generatorchoice
     \endsmoothraggedrightshapetriplet
   \or
     \endsmoothraggedrightshapequintuplet
   \or
     \endsmoothraggedrightshapeseptuplet
   \fi}

\NewDocumentEnvironment{smoothraggedright}{O{}}
  {\PushPostHook{par}{\hskip-\parindent\smoothraggedrightpar[#1]\relax}}
  {\par\PopPostHook{par}}

\endinput
%%
%% End of file `typog.sty'.
