\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{mathpunctspace}
   [2017/04/03 v1.0 style file ``mathpunctspace.sty''^^J
    by Yuwsuke Kieda]

\RequirePackage{xkeyval}

\newif\if@postspace@comma@natural \@postspace@comma@naturaltrue
\newif\if@postspace@semicolon@natural \@postspace@semicolon@naturaltrue
\newif\if@unit@mu \@unit@mutrue
\DeclareOptionX{comma}[natural]{\def\@temp@comma@postskip{#1}}
\DeclareOptionX{semicolon}[natural]{\def\@temp@semicolon@postskip{#1}}
\DeclareOptionX{unit}[mu]{\def\@unit@space{#1}}
\DeclareOptionX{latexorg}{\endinput}

\ProcessOptionsX

\@ifundefined{@temp@comma@postskip}{\def\@temp@comma@postskip{natural}}{}
\@ifundefined{@temp@semicolon@postskip}{\def\@temp@semicolon@postskip{natural}}{}
\@ifundefined{@unit@space}{\def\@unit@space{mu}}{}

\def\@tmp@unit@mu{mu}
\ifx\@unit@space\@tmp@unit@mu\@unit@mutrue\else\@unit@mufalse\fi

\setbox\@tempboxa\hbox{$\mskip\thinmuskip$}%
\def\@temp@comma@postskip@natural{natural}
\ifx\@temp@comma@postskip\@temp@comma@postskip@natural
  \newskip\postspace@comma
  \def\@temp@comma@postskip{%
    \dimexpr\fontdimen2\the\font-\wd\@tempboxa\relax
    plus  \fontdimen3\the\font
    minus \fontdimen4\the\font}
\else
  \@postspace@comma@naturalfalse
  \if@unit@mu
    \newmuskip\postspace@comma
  \else
    \newskip\postspace@comma
  \fi
\fi

\def\@semicolon@postskip@natural{natural}
\ifx\@temp@semicolon@postskip\@semicolon@postskip@natural
  \newskip\postspace@semicolon
  \def\@temp@semicolon@postskip{%
    \dimexpr\fontdimen2\the\font-\wd\@tempboxa\relax
    plus  \fontdimen3\the\font
    minus \fontdimen4\the\font}
\else
  \@postspace@semicolon@naturalfalse
  \if@unit@mu
    \newmuskip\postspace@semicolon
  \else
    \newskip\postspace@semicolon
  \fi
\fi

\postspace@comma\@temp@comma@postskip\relax
\postspace@semicolon\@temp@semicolon@postskip\relax

\begingroup
\catcode`\,=\active
\if@postspace@comma@natural
  \def\@x@{\def,{\normalcomma\hskip\postspace@comma}}
\else
  \if@unit@mu
    \def\@x@{\def,{\normalcomma\mskip\postspace@comma}}
  \else
    \def\@x@{\def,{\normalcomma\hskip\postspace@comma}}
  \fi
\fi
\expandafter\endgroup\@x@%
% *only* in math-mode are made active...
\mathcode`\,="8000
% last space is *necessary*
\def\normalcomma{\mathchar"613B }

\begingroup
\catcode`\;=\active
\if@postspace@semicolon@natural
  \def\@x@{\def;{\normalsemicolon\hskip\postspace@semicolon}}
\else
  \if@unit@mu
    \def\@x@{\def;{\normalsemicolon\mskip\postspace@semicolon}}
  \else
    \def\@x@{\def;{\normalsemicolon\hskip\postspace@semicolon}}
  \fi
\fi
\expandafter\endgroup\@x@%
% *only* in math-mode are made active...
\mathcode`\;="8000
% last space is *necessary*
\def\normalsemicolon{\mathchar"603B }

\endinput
