%%
%% This is file `synthslant.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% synthslant.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.3c of this
%% license or (at your option) any later version.  The latest version
%% of this license is in
%%     https://www.latex-project.org/lppl.txt
%% and version 1.3c 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 synthslant.dtx and synthslant.ins
%% and the derived files synthslant.sty, synthslant-gauge.tex,
%% shear-transform.mp, and title.mp.
%% 
%% 
\NeedsTeXFormat{LaTeX2e}[2005/12/01]
\ProvidesPackage{synthslant}
                [2024/07/08  v0.1a  Synthetically Slant glyphs]

\RequirePackage{etoolbox}
\RequirePackage{iftex}
\RequirePackage{xkeyval}

\providecommand*{\synthslant}{.2}
\providecommand*{\synthnegslant}{-.2}

\def\synthslant@engine{-1}

\DeclareOptionX{slant}{%
  \xdef\synthslant{\fpeval{#1}}%
  \xdef\synthnegslant{\fpeval{-(#1)}}}
\DeclareOptionX{negslant}{\xdef\synthnegslant{\fpeval{#1}}}
\DeclareOptionX{posslant}{\xdef\synthslant{\fpeval{#1}}}

\DeclareOptionX{auto}{\def\synthslant@engine{-1}}
\DeclareOptionX{PDF}{\def\synthslant@engine{0}}
\DeclareOptionX{pdf}{\def\synthslant@engine{0}}
\DeclareOptionX{l3draw}{\def\synthslant@engine{1}}
\DeclareOptionX{ps}{\def\synthslant@engine{2}}
\DeclareOptionX{PS}{\def\synthslant@engine{2}}
\DeclareOptionX{tikz}{\def\synthslant@engine{3}}
\DeclareOptionX{TikZ}{\def\synthslant@engine{3}}
\DeclareOptionX{fontspec}{\def\synthslant@engine{4}}
\DeclareOptionX{disable}{\def\synthslant@engine{10000}}

\ProcessOptionsX\relax

\ExplSyntaxOn
\fp_compare:nNnTF {\synthslant} < {.0}
  {\PackageError{synthslant}
                {\string\synthslant\space <\space 0}
                {Pass\space a\space value\space that\space
                 is\space nonnegative.}}
  {}
\fp_compare:nNnTF {\synthnegslant} > {.0}
  {\PackageError{synthslant}
                {\string\synthnegslant\space >\space 0}
                {Pass\space a\space value\space that\space
                 is\space nonpositive.}}
  {}
\ExplSyntaxOff

\PackageInfo{synthslant}{\string\synthslant=\synthslant}
\PackageInfo{synthslant}{\string\synthnegslant=\synthnegslant}

\ifnum\synthslant@engine<0
  \PackageInfo{synthslant}{auto-selecting slant engine}

  \ifpdftex
    \ifnum\pdfoutput>0
      \def\synthslant@engine{0}
    \else
      \def\synthslant@engine{1}
    \fi
  \else
    \ifluatex
      \def\synthslant@engine{4}
    \else
      \def\synthslant@engine{1}
    \fi
  \fi
\fi

\newcommand*{\synthslant@engine@name}{%
  \ifcase\synthslant@engine
    PDF%
  \or% 1
    l3draw%
  \or% 2
    PSTricks%
  \or% 3
    TikZ%
  \or% 4
    fontspec%
  \else
    null-implementation%
  \fi
}

\ifcase\synthslant@engine%  0: PDF
  \PackageInfo{synthslant}{shearing done by PDF}

  \newbox{\synthslant@box}

  \newcommand*{\synthslant@pdf@shear@box}[2]{%
    \mbox{\sbox{\synthslant@box}{#2}%
          \hskip\wd\synthslant@box
          \pdfsave
          \pdfsetmatrix{1 0 #1 1}%
          \llap{\usebox{\synthslant@box}}%
          \pdfrestore}%
  }

  \let\synthslant@shear@box=\synthslant@pdf@shear@box
\or%  1: LaTeX3 draw subsystem
  \PackageInfo{synthslant}{shearing delegated to l3draw}

  \RequirePackage{l3draw}

  \ExplSyntaxOn
  \NewDocumentCommand{\synthslant@latex@shear@box}{mm}{
    \hbox_set:Nn \l_tmpa_box {#2}
    \dim_set:Nn \l_tmpa_dim {\box_wd:N \l_tmpa_box}
    \dim_set:Nn \l_tmpb_dim {\box_ht:N \l_tmpa_box}
    \draw_begin:
      \draw_transform_xslant:n {#1}
      \box_set_dp:Nn \l_tmpa_box {\z@}
      \fp_compare:nNnTF {#1} >= {.0}
        {
          \box_set_wd:Nn \l_tmpa_box
              {\l_tmpa_dim - #1\l_tmpb_dim}
        }
        {
          \draw_suspend_begin:
            \kern#1\l_tmpb_dim
          \draw_suspend_end:
          \box_set_wd:Nn \l_tmpa_box
              {\l_tmpa_dim + #1\l_tmpb_dim}
        }
      \draw_box_use:N \l_tmpa_box
    \draw_end:
  }
  \ExplSyntaxOff

  \let\synthslant@shear@box=\synthslant@latex@shear@box
\or%  2: PSTricks
  \PackageInfo{synthslant}
              {shearing deferred to PostScript via PSTricks}

  \RequirePackage{pst-3d}% \pstilt

  \newcommand*{\synthslant@pstricks@shear@box}[2]{%
    \pstilt{\fpeval{57.2958 * acos(#1)}}{#2}%
  }

  \let\synthslant@shear@box=\synthslant@pstricks@shear@box
\or%  3: TikZ
  \PackageInfo{synthslant}{shearing by TikZ}

  \RequirePackage{tikz}

  \newcommand*{\synthslant@tikz@shear@box}[2]{%
    \tikz[baseline = (ANCHOR.base), xslant = #1]
    \node[inner sep = 0pt, xslant = #1] (ANCHOR) {#2};
  }

  \let\synthslant@shear@box=\synthslant@tikz@shear@box
\or%  4: fontspec
  \PackageInfo{synthslant}
              {use fontspec's artificial font transformations}

  \RequirePackage{fontspec}

  \ExplSyntaxOn
  \newcommand*{\synthslantbox@fontspect@shear@box}[2]{
    \begingroup
    \expandafter
    \fontspec[FakeSlant=#1]{\l_fontspec_family_tl}
    #2
    \endgroup
  }
  \ExplSyntaxOff

  \let\synthslant@shear@box=\synthslantbox@fontspect@shear@box
\else%  >=5: Null implementation
  \PackageWarning{synthslant}{shearing disabled}

  \newcommand*{\synthslant@identity@shear@box}[2]{#2}

  \let\synthslant@shear@box=\synthslant@identity@shear@box
\fi

\def\synthslant@nolinebreak{%
  \ifnum\synthslant@engine=1% l3draw
    \nolinebreak
  \else
    \ifnum\synthslant@engine=3% TikZ
      \nolinebreak
    \fi
  \fi
}

\def\synthslantbox@soft@hyphen#1\-#2\relax{%
  \synthslant@shear@box{\synthslant@slant@value}{#1}%
  \ifx\relax#2%
    \relax
  \else
    \synthslant@nolinebreak
    \discretionary{-}{}{}%
    \synthslantbox@soft@hyphen#2\relax
  \fi
}

\def\synthslantbox@hard@hyphen#1-#2\relax{%
  \synthslantbox@soft@hyphen#1\-\relax
  \ifx\relax#2%
    \relax
  \else
    \synthslant@nolinebreak
    \synthslant@shear@box{\synthslant@slant@value}{-}%
    \synthslant@nolinebreak
    \discretionary{}{}{}%
    \synthslantbox@hard@hyphen#2\relax
  \fi
}

\def\synthslantbox@space#1 #2\relax{%
  \synthslantbox@hard@hyphen#1-\relax
  \ifx\relax#2%
    \relax
  \else
    \space
    \synthslantbox@space#2\relax
  \fi
}

\ifnum\synthslant@engine=4% fontspec
  \newrobustcmd*{\synthslantbox}[2]{%
    \edef\synthslant@slant@value{#1}
    \synthslantbox@fontspect@shear@box{\synthslant@slant@value}
                                      {#2}%
  }
\else
  \newrobustcmd*{\synthslantbox}[2]{%
    \edef\synthslant@slant@value{#1}%
    \expandafter\synthslantbox@space#2 \relax\relax
  }
\fi

\newcommand*{\synthslantbox@right@slant@correction}{%
  \dimen0=\fontdimen5\font
  \kern\synthslant\dimen0\relax
}

\newcommand*{\slantcontext}{tracking=synthslant}

\NewDocumentEnvironment{slantenvironment}{}
  {\upshape
   \ifcsdef{microtypecontext}
           {\expandafter\microtypecontext
            \expandafter{\slantcontext}}
           {}}
  {\ifcsdef{endmicrotypecontext}
           {\endmicrotypecontext}
           {}%
   \synthslantbox@right@slant@correction}

\NewDocumentCommand{\textsynthslant}{m}
  {\ifmmode
     \synthslantbox{\synthslant}{#1}%
   \else
     {\slantenvironment
      \synthslantbox{\synthslant}{#1}%
      \endslantenvironment}%
   \fi}

\newcommand*{\synthslantbox@right@negslant@correction}{}

\newcommand*{\negslantcontext}{tracking=synthnegslant}

\NewDocumentEnvironment{negslantenvironment}{}
  {\itshape
   \ifcsdef{microtypecontext}
           {\expandafter\microtypecontext
            \expandafter{\negslantcontext}}
           {}}
  {\ifcsdef{endmicrotypecontext}
           {\endmicrotypecontext}
           {}%
   \synthslantbox@right@negslant@correction}

\NewDocumentCommand{\textsynthuprightitalic}{m}
  {\ifmmode
     \synthslantbox{\synthnegslant}{#1}%
   \else
     {\negslantenvironment
      \synthslantbox{\synthnegslant}{#1}%
      \endnegslantenvironment}%
   \fi}

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