% EQBuilder PDF tooltip support for generated eqbuilder-latex/v1 fragments.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{eqbuilder}[2026/08/06 v0.1.2 EQBuilder PDF tooltip support]

\RequirePackage{amsmath}
\RequirePackage{tikz}
\RequirePackage{xcolor}
\IfFileExists{pdfcomment.sty}{%
  \RequirePackage{pdfcomment}%
}{%
  \PackageError{eqbuilder}{Missing pdfcomment dependency}{%
    Install a TeX distribution that includes pdfcomment, then compile with PDFLaTeX.
  }%
  \endinput
}

\makeatletter
\def\eqbuilder@schema{eqbuilder-latex/v1}
\definecolor{eqbuilderhintblue}{HTML}{66809C}

% Reject incompatible generated output rather than compiling it silently.
\newcommand{\eqbuilderexportversion}[1]{%
  \def\eqbuilder@requested{#1}%
  \ifx\eqbuilder@requested\eqbuilder@schema
  \else
    \PackageError{eqbuilder}{Unsupported EQBuilder export schema #1}{%
      Update eqbuilder.sty or regenerate the equation from EQBuilder.
    }%
  \fi
}

% #1 optional RRGGBB atom colour; #2 plain tooltip text; #3 maths content.
\newcommand{\eqbuildertooltip}[3][]{%
  \begingroup
  \def\eqbuilder@colour{#1}%
  \ifx\eqbuilder@colour\@empty
    \pdftooltip{#3}{#2}%
  \else
    \textcolor[HTML]{#1}{\pdftooltip{#3}{#2}}%
  \fi
  \endgroup
}

% Optional visual cue for the Builder's "Include tooltip hint icon" setting.
% It is not itself a PDF annotation.
\newcommand{\eqbuildertooltiphint}{%
  \mathord{\vcenter{\hbox{%
    \tikz[x=1em,y=1em,inner sep=0pt,outer sep=0pt]{%
      \path[use as bounding box] (-0.39,-0.39) rectangle (0.39,0.39);%
      \draw[eqbuilderhintblue,line width=0.07em] (0,0) circle[radius=0.31];%
      \fill[eqbuilderhintblue] (0,0.135) circle[radius=0.045];%
      \draw[eqbuilderhintblue,line width=0.07em,line cap=round] (0,0.01) -- (0,-0.17);%
    }%
  }}}%
}
\makeatother
