%% texi.hva: Semantically meaningful macros inspired from Texinfo.

%% This file is read by HeVeA and LaTeX.

%% The following Texinfo-like macros are provided:
%% \code, \env, \command, \samp, \file, \option, \kbd, \key, \var, \dfn.

%% In addition, the following macros are provided:
%% - \link{URL}: format a cliquable link URL.
%% - \link[TEXT]{URL}: display TEXT with an associated cliquable footnote
%%                     displaying URL.
%% - \email{EMAIL}: format a cliquable email link EMAIL.
%% - \email[TEXT]{EMAIL}: display TEXT with an associated cliquable footnote
%%                        displaying EMAIL.

%% Note that with \link, you have to specify the locator's header: http, ftp
%% etc. However, \email adds the "mailto:" part for you. See also the hyperref
%% macro \href, and the url macro \url. "hyperref" requires "url".

\RequirePackage{myhyperref}
\RequirePackage{myifthen}
\RequirePackage{myindex}

\newcommand\strong[1]{\textbf{#1}}

\newcommand\code[1]{\texttt{#1}}
\newcommand\env[1]{\code{#1}}
\newcommand\command[1]{\code{#1}}

\newcommand\samp[1]{`\texttt{#1}'}
\newcommand\file[1]{\samp{#1}}
\newcommand\option[1]{\samp{#1}}

\newcommand\kbd[1]{\textsl{\texttt{#1}}}

\newcommand\key[1]{\textrm{#1}}

\newcommand\http[1]{%
  \href{http://#1}{\nolinkurl{#1}}%
}

\newcommand\link[2][\empty]{%
  \ifx#1\empty%
    \url{#2}%
  \else%
    #1\footnote{\url{#2}}%
  \fi}

% Override HeVeA's \mailto which is not nice-looking.
\ifx\mailto\undefined
  \newcommand{\mailto}[1]{%
    \href{mailto:#1}{\nolinkurl{#1}}%
  }
\else
  % \renewcommand does not work in HeVeA (does not replace #1 etc. by
  % actual arguments), and \newcommand is ignored.
  %
  \ifhevea\else
    \renewcommand{\mailto}[1]{%
      \href{mailto:#1}{\nolinkurl{#1}}%
    }
  \fi
\fi


\ifx\email\undefined
\newcommand\email[2][\empty]{%
  \ifx#1\empty%
    \mailto{#2}%
  \else%
    #1\footnote{\url{mailto:#2}}%
  \fi}
\fi

\newcommand\var[1]{\textsf{#1}}

% \dfn[index entry]{defined word}
% -------------------------------
% Introduce new terminology (for the index).
% If not supplied [index entry] defaults to {defined word}
%
% The trick given at
%     http://www.tex.ac.uk/cgi-bin/texfaq2html?label=oarglikesect
% does not work, because the argument given of \index is sent
% *unevaluated* into the ind file, i.e., we get \DefaultOpt in the
% index instead of the value of \DefaultOpt.
%
% For the same reason, the \index cannot be factored with an
% ifthenelse *inside*, because the \ifthenelse then appear unevaluated
% in the *.ind file.
\newcommand{\dfn}[2][]{%
  \emph{#2}%
  \ifthenelse{\equal{#1}{}}{\myindex{#2}}{\index{#1}}%
}

\newcommand{\use}[2]{%
  #2%
  \ifthenelse{\equal{#1}{}}{\myindex{#2}}{\index{#1}}%
}

% We can't have two "|command"s with \index, so make our own
% composition of \hyperpage and \textbf (for definitions).
\newcommand{\hyperpagebf}[1]{%
  \ifthenelse{%
    \isdefined{\hyperpage}%
  }{%
    \textbf{\hyperpage{#1}}%
  }{%
    \textbf{#1}%
  }%
}
\endinput

%% Local Variables:
%% mode: latex
%% End:
%% texi.sty ends here.
