%======================================================================
% Collected separately so I can override for LaTeXML
%======================================================================
\usepackage{latexml}
\usepackage{color}
%======================================================================
\def\toctitle#1{}

%======================================================================

\let\@@LaTeXML\LaTeXML
\def\LaTeXML{\ifHy@pdfstring LaTeXML\else\@@LaTeXML\fi}
\def\BibTeX{{\rm B}{\sc ib}\TeX}

\let\@title\@empty
\def\subtitle#1{\gdef\@subtitle{#1}}
\def\@maketitle{%
  \newpage
  \null
  \vskip 2em%
  \begin{center}%
  \let \footnote \thanks
    {\LARGE \@title \par}%
    \ifx\@subtitle\@empty\else
      \vskip 1.0em%
      {\large \@subtitle \par}%
    \fi
    \vskip 1.5em%
    {\large
      \lineskip .5em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
    \vskip 1em%
    {\large \@date}%
  \end{center}%
  \par
  \vskip 1.5em}
\renewcommand\maketitle{\begin{titlepage}%
  \let\footnotesize\small
  \let\footnoterule\relax
  \let \footnote \thanks
  \null\vfil
  \vskip 60\p@
  \begin{center}%
    {\LARGE \@title \par}%
    \ifx\@subtitle\@empty\else
      \vskip 1.0em%
      {\large \@subtitle \par}%
    \fi
    \vskip 3em%
    {\large
     \lineskip .75em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
      \vskip 1.5em%
    {\large \@date \par}%       % Set date in \large size.
  \end{center}\par
  \@thanks
  \vfil\null
  \end{titlepage}%
}
\usepackage{graphicx}

%======================================================================
% Containers for advanced material, examples, ...

% Sort of a "double bend" thing?
%\newenvironment{advanced}{\vskip 2ex\textcolor{red}{\LARGE !!}}{\vskip 1ex}
\newenvironment{advanced}{%
%\vskip 2ex
\medbreak
\noindent\hangindent=1cm\hangafter=-3\relax
\hbox to 0pt{\hskip-1.1cm\vbox to 12pt{\noindent\includegraphics{../graphics/scratch.png}}\hfill}%
}{\medbreak}

%======================================================================
% Phrase-level markup semantic or otherwise

\def\perlfont{\ttfamily}
\def\shellfont{\ttfamily}
\def\latexfont{\ttfamily}
\def\schemafont{\sffamily}
\def\patternfont{\sffamily\slshape}

\def\@@ltxprefix{LaTeXML}
\def\@@pkgprefix#1::#2\end{#1}
\def\@@latexmlcmd{latexml}
\def\@@latexmlpostcmd{latexmlpost}
\def\@@latexmlmathcmd{latexmlmath}
\newcommand{\pod}[1]{%
  {\edef\@prefix{\@@pkgprefix#1::\end}
   \edef\@podcmd{#1}
  \ifx\@@ltxprefix\@prefix
     \htmlref{{\perlfont #1}}{#1}%
  \else\ifx\@podcmd\@@latexmlcmd
     \htmlref{{\perlfont #1}}{#1}%
  \else\ifx\@podcmd\@@latexmlpostcmd
     \htmlref{{\perlfont #1}}{#1}%
  \else\ifx\@podcmd\@@latexmlmathcmd
     \htmlref{{\perlfont #1}}{#1}%
  \else
     \href{http://search.cpan.org/search?query=#1&mode=module}{{\perlfont #1}}%
  \fi\fi\fi\fi}}


\newcommand{\ltxcmd}[1]{\htmlref{{\latexfont #1}}{#1}}
% The idea here is that since the class names are so long, LaTeXML::Core::Definition::Expandable;
% Show the long form first, but then abbreviate to just the last name.
% Of course, there are eventually, potential ambiguities;  We COULD adapt to that,
% abbreviating only to the most recent usage?
\newcommand{\ltxpod}[1]{%
\@ifundefined{podseen@#1}{%
  \ltxpod@long{#1}%
  \expandafter\def\csname podseen@#1\endcsname{seen}%
}{%
  \ltxpod@short{#1}%
}}

\def\ltxpod@long#1{%
   \ltxpod@ref{(\ltxpod@@pre LaTeXML::#1::\end)\allowbreak\ltxpod@@short#1::\end}{#1}}
\def\ltxpod@short#1{%
   \ltxpod@ref{\ltxpod@@short#1::\end}{#1}}
\def\ltxpod@@short#1::#2\end{\ifx.#2.#1\else\ltxpod@@short#2\end\fi}
\def\ltxpod@@pre#1::#2\end{\ifx.#2.\else#1::\allowbreak\ltxpod@@pre#2\end\fi}
\def\ltxpod@ref#1#2{\htmlref{\perlfont #1}{LaTeXML::#2}}

\newcommand{\cmd}[1]{{\shellfont #1}}
\newcommand{\code}[1]{{\perlfont #1}}
\newcommand{\codevar}[1]{{\perlfont\itshape #1}}
\newcommand{\method}[1]{{\perlfont ->#1}}
\newcommand{\attr}[1]{{\schemafont #1}}
\newcommand{\attrval}[1]{{\perlfont #1}}

\newcommand{\varfile}[2][]{{\shellfont \textit{#2}\if.#1.\else.#1\fi}}
\newcommand{\cs}[1]{{\latexfont $\backslash$#1}}

%======================================================================
% For generated documentation of Schema.

\newenvironment{moduledescription}{\begin{description}}{\end{description}}%
\newenvironment{elementdescription}{\begin{description}}{\end{description}}%
\newenvironment{patterndescription}{\begin{description}}{\end{description}}%

%\newcommand{\typename}[1]{{\perlfont #1}}
\newcommand{\typename}[1]{\textit{#1}}

\newenvironment{schemamodule}[1]{%
  \section{Module {\perlfont #1}}\label{schema.#1}
   \raggedright
  \begin{moduledescription}}{\end{moduledescription}}

%\def\cleanhypername#1{{\def\_{\string_}\@cleanhypername#1:\end}}
%\def\cleanhypername#1{\@cleanhypername#1:\end}
% \def\cleanhypername#1{\expandafter\@@cleanhypername\@cleanhypername#1:\end\_\end}
% \def\@cleanhypername#1:#2\end{\ifx.#2.#1\else#1..\@cleanhypername#2\end\fi}
% %%%\def\@@cleanhypername#1\_#2\end{\ifx.#2.#1\else#1\string_\@@cleanhypername#2\end\fi}
% \def\@@cleanhypername#1\_#2\end{\ifx.#2.#1\else#1-\@@cleanhypername#2\end\fi}


\def\cleanhypername#1{\@cleanhypername#1:\end}
\def\@cleanhypername#1:#2\end{%
\ifx.#2.\@@cleanhypername#1\_\end
\else\@@cleanhypername#1\_\end..\@cleanhypername#2\end\fi}
\def\@@cleanhypername#1\_#2\end{\ifx.#2.#1\else#1\string_\@@cleanhypername#2\end\fi}

% \elementdef{name}{doc}{body}
\newcommand{\elementdef}[3]{
  \item[\textit{Element }{\bfseries\schemafont #1}]
        \hspace{1em}
        \hypertarget{\cleanhypername{schema.#1}}{}%
        \index{#1@{\schemafont #1}!element}%
        #2
    \ifx.#3.\else\begin{elementdescription}#3\end{elementdescription}\fi
}

% \attrdef{name}{doc}{content}
\newcommand{\attrdef}[3]{
  \item[\textit{Attribute }{\bfseries\schemafont #1}]
         =\
        \index{#1@{\schemafont #1}!attribute}%
        #3\par\noindent #2
}

\newif\if@elpattern\@elpatternfalse
\def\test@elpattern#1{%
  \@elpatternfalse
  \test@model@pattern#1\_model\end%
  \test@attributes@pattern#1\_attributes\end}
\def\test@model@pattern#1\_model#2\end{\if.#2.\else\@elpatterntrue\fi}
\def\test@attributes@pattern#1\_attributes#2\end{\if.#2.\else\@elpatterntrue\fi}

% \patterndef{name}{doc}{body}
\newcommand{\patterndef}[3]{
   \item[\textit{Pattern }{\bfseries\patternfont #1}]
      \hspace{1em} 
      \hypertarget{\cleanhypername{schema.#1}}{}%
      \test@elpattern{#1}\if@elpattern\else
         \index{#1@{\patternfont #1}!schema pattern}\fi
      #2
    \ifx.#3.\else\begin{patterndescription}#3\end{patterndescription}\fi
}

% \patternadd{name}{doc}{body}
\newcommand{\patternadd}[3]{
  \item[\textit{Add to }{\bfseries\patternfont #1}] \hspace{1em} #2
%%  \item[\textit{Add to }%
%%    \@ifundefined{defined.schema.#1}{\hypertarget{schema.#1}{{\bfseries\patternfont #1}}}{{\bfseries\patternfont #1}}
%%    ]  \hspace{1em} #2
    \ifx.#3.\else\begin{patterndescription}#3\end{patterndescription}\fi
}

\newcommand{\patterndefadd}[3]{
  \item[\textit{Add to }{\bfseries\patternfont #1}]
     \hspace{1em}
     \hypertarget{\cleanhypername{schema.#1}}{}%
      #2
     \ifx.#3.\else\begin{patterndescription}#3\end{patterndescription}\fi
}

\newcommand{\moduleref}[1]{\htmlref{{\perlfont #1}}{\cleanhypername{schema.#1}}}
\newcommand{\patternref}[1]{\hyperlink{\cleanhypername{schema.#1}}{{\patternfont #1}}}
\newcommand{\elementref}[1]{\hyperlink{\cleanhypername{schema.#1}}{{\schemafont #1}}}

%======================================================================
\definecolor{linkblue}{cmyk}{1.0,0.2,0.0,0.50}%
\usepackage[colorlinks=true, linkcolor=linkblue, citecolor=linkblue, urlcolor=blue,
            plainpages=false, pdfpagelabels]{hyperref}
%======================================================================
