%\RequirePackage{xcolor}
\RequirePackage{pdfcomment}
\RequirePackage{l3keys2e}
\ExplSyntaxOn

\keys_define:nn { stexhighlighting / pkg}{
  boxes   .default:n = {true},
  boxes   .bool_set:N = \c_stexhighlighting_boxes_bool,
}

\ProcessKeysOptions{ stexhighlighting / pkg}

\ExplSyntaxOff

\def\compemph#1{%
  \ifcsname textcolor\endcsname
    \textcolor{blue}{#1}%
  \else
    #1%
  \fi
}
\def\symrefemph#1{%
  \ifcsname textcolor\endcsname
    \textcolor{teal}{#1}%
  \else#1\fi
}
\def\defemph#1{%
  \ifcsname textcolor\endcsname
    \textcolor{magenta}{%
      \ifmmode
      \else\expandafter\textbf
      \fi{#1}%
    }%
  \else
    \ifmmode
    \else\expandafter\textbf
    \fi{#1}%
  \fi
}
\def\varemph#1{\ifcsname textcolor\endcsname\textcolor{gray}{#1}\else#1\fi}

\ExplSyntaxOn

\bool_if:NTF\c_stexhighlighting_boxes_bool{
  \protected\def\compemph@uri#1#2{
    \pdftooltip{
      \srefsymuri{#2}{\compemph{#1}}
    }{
      URI:~\detokenize{#2}
    }
  }
  \protected\def\symrefemph@uri#1#2{
    \pdftooltip{
      \srefsymuri{#2}{\symrefemph{#1}}
    }{
      URI:~\detokenize{#2}
    }
  }
}{
  \protected\def\compemph@uri#1#2{
    \pdftooltip{{\hypersetup{pdfborder={0~0~0}}
      \srefsymuri{#2}{\compemph{#1}}
    }}{
      URI:~\detokenize{#2}
    }
  }
  \protected\def\symrefemph@uri#1#2{
    \pdftooltip{{\hypersetup{pdfborder={0~0~0}}
      \srefsymuri{#2}{\symrefemph{#1}}
    }}{
      URI:~\detokenize{#2}
    }
  }
}

\protected\def\defemph@uri#1#2{%
   \pdftooltip{%
     \defemph{#1}%
   }{%
     URI:~\detokenize{#2}%
   }%
}
\protected\def\varemph@uri#1#2{%
   \pdftooltip{%
     \varemph{#1}%
   }{%
     Variable~\detokenize{#2}%
   }%
}

\ExplSyntaxOff