%%
%% LaTeX package `bt-isodiff'
%% Upright differential operator compliant with ISO 80000-2
%%
%% Copyright 2026 by Werner Fink
%%
\NeedsTeXFormat{LaTeX2e}[2020/10/01]
\ProvidesPackage{bt-isodiff}[2026/05/21 v1.2 ISO Upright Differential Operator]

\RequirePackage{iftex}

\ifluatex
  % LuaLaTeX/unicode-math overwrites all mathcodes at \begin{document}.
  % Be sure that bt-isodiff will be loaded after unicode-math
  \AtBeginDocument{%
    \@ifpackageloaded{unicode-math}{%
      \AddToHook{begindocument/end}{%
        \mathcode`d="8000
        \begingroup\lccode`~=`d \lowercase{\endgroup\def~}{\symrm{d}}%
      }%
    }{%
      % Fallback if LuaLaTeX is used without unicode-math
      \DeclareMathSymbol{d}{\mathord}{operators}{`d}%
    }%
  }
\else
  % Define 'd' as a mathematical symbol from the 'operators' font (OT1/roman)
  % This maintains the character as an unboxed \mathord, preserving perfect kerning.
  \DeclareMathSymbol{d}{\mathord}{operators}{`d}
\fi

\endinput
