\ProvidesPackage{hidoc}
\RequirePackage{xcolor}
\RequirePackage{fontspec}
\RequirePackage{unicode-math}
\setmainfont{Libertinus Serif}
\setmathfont{Libertinus Math}
\setsansfont[Scale=MatchLowercase]{Source Sans 3}
\setmonofont[Scale=MatchLowercase]{Source Code Pro}
\RequirePackage{etoolbox}
\RequirePackage{histrings}
\sloppy
\def\hia*{\emph{Hereinafter}}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Doc options
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\PageIndex
\NewDocElement{File}{fileenv}
\def\PrintDescribeFile#1{%
    {\footnotesize\sffamily\color{gray} For more information,\\see
    \emph{doc/#1.pdf}.\par}%
}
\NewDocElement{Param}{parameter}
\def\PrintDescribeParam#1{}
\NewDocElement{Opt}{option}
\def\PrintDescribeOpt#1{{\sffamily\bfseries#1}}
\NewDocElement{RefType}{reference type}
\let\PrintDescribeRefType\@gobble
\NewDocElement{Abb}{abbreviation scheme}
\let\PrintDescribeAbb\@gobble
%
\def\PrintDescribeMacro#1{%
    {\ttfamily\color{blue}\string#1}%
}
%
% This macro enables a doctools-like form in which the marginal macro name is
% used as part of a specification for the macro's usage.
%
\def\MacroSpec#1{%
    \ifdim\lastskip>\z@\else \vskip 6pt \fi
    \noindent\DescribeMacro#1\ignorespaces
}
%
\def\main#1{#1}
\def\usage#1{\textbf{\underline{#1}}}
\def\IndexPrologue{Underlined page numbers describe where a command, parameter,
reference type, or other item is described in detail. Other page numbers
identify where the item is used.}
\setcounter{IndexColumns}{2}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Macros for cross-referencing
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\def\pt#1{the main documentation}
\def\param#1{\hyperref[param:#1]{\textsf{%
    \SpecialMainParamIndex{#1}%
    \color{blue}#1%
}}}
\def\opt#1{\hyperref[opt:#1]{\textsf{%
    \SpecialMainOptIndex{#1}%
    \color{violet}#1%
}}}
\def\rtype#1{\hyperref[rtype:#1]{\textsf{%
    \SpecialMainRefTypeIndex{#1}%
    \color{red}#1%
}}}
\def\abbscheme#1{\hyperref[abbscheme:#1]{\textsf{%
    \SpecialMainAbbIndex{#1}%
    \color{brown}#1%
}}}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Code blocks
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\def\@xobeysp{\leavevmode\spacefactor1000\relax\space}
\begingroup
    \catcode`\<=\active
    \gdef\ActivateBracket{%
        \catcode`\<=\active
        \def<{\futurelet\next\hidoc@check@bracket}%
    }%
\endgroup
\def\hidoc@check@bracket{%
    \if*\next \let\next\hidoc@star
    \else \if/\next \let\next\hidoc@slash
    \else \def\next{<}%
    \fi\fi
    \next
}
\def\hidoc@star*#1>{%
    \@ifundefined{hidoc@module@\detokenize{#1}}{}{%
        \begin{hidoc@module@\detokenize{#1}}%
    }%
}
\def\hidoc@slash/#1>{%
    \@ifundefined{hidoc@module@\detokenize{#1}}{}{%
        \end{hidoc@module@\detokenize{#1}}%
    }%
}
\newenvironment{hidoc@module@package}{%
    \vskip 6pt\relax
    \footnotesize \sffamily
    \color{violet}%
}{}
\newenvironment{hidoc@module@test}{%
    \hidoc@eattoendtest
}{}
\begingroup
    \catcode`\<=\active
    \MakePercentIgnore
    \long\gdef\hidoc@eattoendtest#1%</test>{\hidoc@slash/test>}
\endgroup
\def\MacroFont{%
    \fontencoding\encodingdefault
    \fontfamily\ttdefault
    \fontseries\mddefault
    \fontshape\shapedefault
    \def\@xobeysp{~}%
    \tiny\color{gray}%
}
\MacroIndent=3em
\AtBeginDocument{%
    \ActivateBracket
}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Sectioning.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\setcounter{secnumdepth}{100}
\renewcommand\part{%
   \if@noskipsec \leavevmode \fi
   \clearpage
   \hrule \@height \z@
   \vskip 0.1\textheight
   \@afterindentfalse
   \secdef\@part\@spart}
\def\@part[#1]#2{%
    \ifnum \c@secnumdepth >\m@ne
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    {\parindent \z@ \raggedright
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >\m@ne
       \Large\bfseries \partname\nobreakspace\thepart
       \par\nobreak
     \fi
     \huge \bfseries #2%
     \markboth{}{}\par}%
    \nobreak
    \vskip 24pt
    \hidoc@line
    \vskip 40pt
    \@afterheading}
\renewcommand\section{%
    \clearpage
    \@startsection
        {section}{1}{\z@}%
        {-3.5ex \@plus -1ex \@minus -.2ex}%
        {16pt}%
        {%
            \aftergroup\hidoc@line
            \normalfont\LARGE\bfseries
        }%
}
\def\hidoc@line{%
    \vskip 16pt
    \hrule \@width 0.25\textwidth
}
\renewcommand\theparagraph{%
    \ifnum\c@subsubsection>\z@
        \thesubsubsection
    \else
        \ifnum\c@subsection>\z@
            \thesubsection
        \else
            \thesection
        \fi
    \fi
    (\@alph\c@paragraph)%
}
\def\sec#1{\find@in{-}{#1}{\@tworun\sec\@gobble}{\texttt{#1.dtx}}}
\make@find@in{-}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Parameter lists.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\def\parameterlist#1#2#3\@stop{%
    \par\hangindent=2\parindent\indent
    \textbf{\parameterlist@params#1, \@stop}: #2\par
    \ifblank{#3}{}{\parameterlist#3\@stop}%
}
\def\parameterlist@params#1, #2\@stop{%
    \param{#1}%
    \ifblank{#2}{}{, \parameterlist@params#2\@stop}%
}
\def\keyparameters#1{%
    \par\vskip.5\baselineskip\noindent\textbf{Key Parameters:}\par
    \parameterlist#1\@stop
}
\def\optparameters#1{%
    \par\vskip.5\baselineskip\noindent\textbf{Optional Parameters:}\par
    \parameterlist#1\@stop
}
\def\ExplainOption#1{%
    \ifdim\lastskip>\z@\else \vskip 6pt \fi
    \noindent \DescribeOpt{#1}\label{opt:#1}\ignorespaces
}
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Informational boxes.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\renewenvironment{quote}{%
    \list{}{%
        \rightmargin=\leftmargin
        \@rightskip=\fill
        \hyphenpenalty=\@M
    }%
    \item\relax
}{\endlist}
\newenvironment{hi@boxmaker}[1]{%
    \par
    \def\hi@color{#1}%
    \setbox\@tempboxa=\vbox\bgroup
        \advance\hsize-4em
        \parindent\z@ \parskip\z@
        \hyphenpenalty\@M
        \raggedright
}{%
    \egroup
    \vskip\topsep
    \@@line{%
        \hss
        \expandafter\colorbox\hi@color{\box\@tempboxa}%
        \hss
    }%
    \vskip\topsep
    \@endpetrue
}
\newenvironment{demo}{%
    \def\MacroFont{%
        \fontencoding\encodingdefault
        \fontfamily\ttdefault
        \fontseries\mddefault
        \fontshape\shapedefault
        \small\def\@xobeysp{~}%
        % Suppress spacing around verbatim resulting from \verbatim's use of
        % \trivlist
        \vskip-\@topsep
        \@topsep\z@ \@topsepadd\z@
    }%
    \begin{hi@boxmaker}{[gray]{0.9}}%
}{\end{hi@boxmaker}}
\newenvironment{grammar}{\begin{hi@boxmaker}{[rgb]{0.9,0.9,1}}}%
    {\end{hi@boxmaker}}
\def\Example{%
    \par\vskip 6pt\relax\textsf{\small\textit{\color{blue}{Example:}}}\par
}
\def\Examples{%
    \par\vskip 6pt\relax\textsf{\small\textit{\color{blue}{Examples:}}}\par
}
\def\Produces{%
    \par\vskip 6pt\relax\textsf{\small\textit{\color{blue}{Produces:}}}\par
}
\def\littext#1{\underline{\texttt{#1}}}
\def\grammarparen#1{\grammarparens{\meta{#1}}}
\def\grammarparens#1{\littext{ (} #1 \littext{)}}
\def\inputtext#1{\texttt{\detokenize{#1}}}
