% mystyletau.sty
% Copyright 2026 Antonello Meccariello & Francesco Meccariello
%
% 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.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mystyletau}[2026/11/25 v2.3 Custom Tau glyphs for topology]

\RequirePackage{iftex}
\RequirePackage{amsmath}
\RequirePackage{amssymb}
\RequirePackage{graphicx}

\makeatletter

% --- LUNGHEZZA DI RIFERIMENTO LEGATA ALLA X MATEMATICA ---
\newlength{\mytau@ht}

% --- SELEZIONE DINAMICA DEL MOTORE ---
\iftutex
  % Motori Unicode (LuaLaTeX / XeLaTeX)
  \RequirePackage{fontspec}
  \IfFileExists{mytautwo.ttf}{%
    \newfontfamily{\mytaufont}{mytautwo.ttf}[Path=./]%
  }{%
    \newfontfamily{\mytaufont}{mytautwo.ttf}%
  }
  \newcommand{\vtau@base}{%
    \text{%
      \settoheight{\mytau@ht}{$X$}%
      \raisebox{-0.22\mytau@ht}{\resizebox{!}{1.29\mytau@ht}{\mytaufont\symbol{"E901}}}%
    }%
  }
  \newcommand{\atau@base}{%
    \text{%
      \settoheight{\mytau@ht}{$X$}%
      \raisebox{-0.22\mytau@ht}{\resizebox{!}{1.29\mytau@ht}{\mytaufont\symbol{"E900}}}%
    }%
  }
\else
  % Motore 8-bit classico (pdfLaTeX)
  \newcommand{\vtau@base}{%
    \text{%
      \settoheight{\mytau@ht}{$X$}%
      \raisebox{-0.26\mytau@ht}{\includegraphics[height=1.35\mytau@ht]{mystyletau-vtau.pdf}}%
    }%
  }
  \newcommand{\atau@base}{%
    \text{%
      \settoheight{\mytau@ht}{$X$}%
      \raisebox{-0.26\mytau@ht}{\includegraphics[height=1.35\mytau@ht]{mystyletau-atau.pdf}}%
    }%
  }
\fi

% --- HELPER PER ESTRARRE LA PRIMA LETTERA PER IL KERNING ---
\def\vtau@check@first#1#2\@nil#3{%
  \ifx X#1_{\mkern -2.2mu #3}%
  \else\ifx A#1_{\mkern -2.5mu #3}%
  \else\ifx B#1_{\mkern -2mu #3}%
  \else\ifx D#1_{\mkern -2mu #3}%
  \else\ifx E#1_{\mkern -2mu #3}%
  \else\ifx F#1_{\mkern -2mu #3}%
  \else\ifx H#1_{\mkern -2mu #3}%
  \else\ifx I#1_{\mkern -2mu #3}%
  \else\ifx L#1_{\mkern -2mu #3}%
  \else\ifx M#1_{\mkern -2mu #3}%
  \else\ifx N#1_{\mkern -2mu #3}%
  \else\ifx P#1_{\mkern -2mu #3}%
  \else\ifx R#1_{\mkern -2mu #3}%
  \else\ifx S#1_{\mkern -2mu #3}%
  \else\ifx T#1_{\mkern -2mu #3}%
  \else\ifx Z#1_{\mkern -1.8mu #3}%
  \else\ifx \beta#1_{\mkern -1.8mu #3}%
  \else\ifx \rho#1_{\mkern -1.8mu #3}%
  \else\ifx \alpha#1_{\mkern -1.5mu #3}%
  \else_{#3}\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi%
}

\def\atau@check@first#1#2\@nil#3{%
  \ifx X#1_{\mkern -2.2mu #3}%
  \else\ifx A#1_{\mkern -2.5mu #3}%
  \else\ifx B#1_{\mkern -2mu #3}%
  \else\ifx D#1_{\mkern -2mu #3}%
  \else\ifx E#1_{\mkern -2mu #3}%
  \else\ifx F#1_{\mkern -2mu #3}%
  \else\ifx H#1_{\mkern -2mu #3}%
  \else\ifx I#1_{\mkern -2mu #3}%
  \else\ifx L#1_{\mkern -2mu #3}%
  \else\ifx M#1_{\mkern -2mu #3}%
  \else\ifx N#1_{\mkern -2mu #3}%
  \else\ifx P#1_{\mkern -2mu #3}%
  \else\ifx R#1_{\mkern -2mu #3}%
  \else\ifx S#1_{\mkern -2mu #3}%
  \else\ifx T#1_{\mkern -2mu #3}%
  \else\ifx Z#1_{\mkern -1.8mu #3}%
  \else\ifx \beta#1_{\mkern -1.8mu #3}%
  \else\ifx \rho#1_{\mkern -1.8mu #3}%
  \else\ifx \alpha#1_{\mkern -1.5mu #3}%
  \else_{#3}\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi%
}

% --- LOGICA DI SPAZIATURA ---
\newcommand{\vtau@kern@check}[1]{\vtau@check@first#1\relax\relax\@nil{#1}}
\newcommand{\atau@kern@check}[1]{\atau@check@first#1\relax\relax\@nil{#1}}

% --- DEFINIZIONE \vtau E \atau CON XPARSE ---
\NewDocumentCommand{\vtau}{ e{_^} }{%
  \ensuremath{%
    \vtau@base
    \IfValueT{#1}{\vtau@kern@check{#1}}%
    \IfValueT{#2}{^{\mkern 3mu #2}}%
  }%
}

\NewDocumentCommand{\atau}{ e{_^} }{%
  \ensuremath{%
    \atau@base
    \IfValueT{#1}{\atau@kern@check{#1}}%
    \IfValueT{#2}{^{\mkern 3mu #2}}%
  }%
}

% --- SHORTCUTS AUSILIARI ---
\newcommand{\pt}[1]{\left(#1\right)}

\makeatother

\endinput