%% Copyright (c) 2004 Integre Technical Publishing.  All Rights Reserved.
\windowTitle{Examples of Context Menus}%
\pagecolor{black}\nocaret\color{white}%
% --------------------------------------------------------------------
\chapter{\sf\color{yellow}Examples of Context Menus}
% --------------------------------------------------------------------
\def\TE{{\bf techexplorer}}
This \TE{} document shows how to use {\it pop-up context menus}
in your own documents.

\bigskip
We've done a few other things  to illustrate some of \TE's features:
\begin{itemize}
\item We set the background color to black by using \verb+\pagecolor{black}+.
\item The main text was set to white using \verb+\color{white}+.
\item We defined a macro so that we wouldn't have to keep typing
``techexplorer'':
\centerline{\verb+\def\TE{{\bf techexplorer}}+}
\end{itemize}

\def\sectionCM#1{\section{\usemenu{document-menu}{\sf\color{yellow}#1}}}
% --------------------------------------------------------------------
\sectionCM{Context Menus}\label{context-menus}
% --------------------------------------------------------------------

A {\it context menu} is a popup menu that appears when you click the
alternate mouse button. For most people, this will be the right mouse
button. For this reason, we'll refer to clicking the alternate
mouse button as ``right-clicking.''

A standard context menu is defined by \TE{} to allow you access to user
options, hierarchical document navigation, and version information. Try
right-clicking on an empty area of this document to see the default menu.

Context menus can contain any kind of link, including audio and video links,
but they are most frequently used for hyperlinking
to the beginnings of sections, theorems, and so forth.

For later examples, here are some dummy theorems:

\def\beginThmLike#1#2#3{\par\colorbox{silver}{\color{black}\usemenu{document-m
enu}{\bf
#1 #2.}}\label{#3}\bgroup\it}
\def\beginThm#1{\beginThmLike{Theorem}{#1}{theorem-#1}}
\def\endThm{\egroup\par}
%
\beginThm{1}
Theorem 2 implies Theorem 3.
\endThm{}
\beginThm{2}
Theorem 1 implies Theorem 3.
\endThm{}
\beginThm{3}
Theorem 2 implies Theorem 1.
\endThm{}

% --------------------------------------------------------------------
\sectionCM{Defining Context Menus}\label{defining-context-menus}
% --------------------------------------------------------------------
\def\Syntax#1{\centerline{{\tt #1}}}

The \verb+\newmenu+ control sequence assigns a menu definition
to a name for later use with \verb+\usemenu+:
\Syntax{\verb+\newmenu{+ {\it menuName} \}\{ {\it menuDefinition} \}}

A menu definition is a sequence of links, rules
and \verb+\usemenu+ submenu entries
for previously defined menus.
Anything else in the definition is discarded.

Here is a menu definition for the theorems above.
Each theorem display was created with a macro that automatically
created a label like ``theorem-1'', etc..

\bgroup\small
\begin{verbatim}
\newmenu{theorem-menu}{
\labelLink{theorem-1}{Theorem 1}
\labelLink{theorem-2}{Theorem 2}
\labelLink{theorem-3}{Theorem 3} }
\end{verbatim}
\egroup
%
\newmenu{theorem-menu}{
\labelLink{theorem-1}{Theorem 1}
\labelLink{theorem-2}{Theorem 2}
\labelLink{theorem-3}{Theorem 3} }

Now we'll add a menu for the sections:

\bgroup\small
\begin{verbatim}
\newmenu{section-menu}{
\labelLink{context-menus}{Context Menus}
\labelLink{defining-context-menus}{Defining Context Menus}
\labelLink{using-context-menus}{Using Context Menus}
\labelLink{summary}{Summary} }
\end{verbatim}
\egroup
\newmenu{section-menu}{
\labelLink{context-menus}{Context Menus}
\labelLink{defining-context-menus}{Defining Context Menus}
\labelLink{using-context-menus}{Using Context Menus}
\labelLink{summary}{Summary} }

Finally, we'll put them together as a submenu in a larger menu.
We'll separate the menu items by a horizontal separator.

\bgroup\small
\begin{verbatim}
\newmenu{document-menu}{
\usemenu{section-menu}{Sections}
\hrule
\usemenu{theorem-menu}{Theorems} }
\end{verbatim}
\egroup
\newmenu{document-menu}{
\usemenu{section-menu}{Sections}
\hrule
\usemenu{theorem-menu}{Theorems} }

By repeating this process, multi-level menus of any depth can be
constructed using \verb+\newmenu+ and \verb+\usemenu+ in a bottom-up
fashion.

% --------------------------------------------------------------------
\sectionCM{Using Context Menus}\label{using-context-menus}
% --------------------------------------------------------------------

The \verb+\usemenu+ control sequence assigns a menu to
a section of text: \Syntax{\verb+\usemenu{+ {\it menuName} \}\{ {\it
menuScope}
\}}
The {\it menuName} refers to a menu definition previously created
by \verb+\newmenu+.

Now that we have defined a menu, we can wrap it around any displayed
object. For example, right-click on the mathematical expression below:
$$ \usemenu{document-menu}{\sqrt{\cos{x} - \log^3 x}} $$

We implemented this via

\bgroup\small
\begin{verbatim}
$$ \usemenu{document-menu}{\sqrt{\cos{x} - \log^3 x}} $$
\end{verbatim}
\egroup

In this example, we probably would have chosen
the section and theorem titles as good places for using this context
menu. (In fact, we did! Try right-clicking on them!)

% --------------------------------------------------------------------
\sectionCM{Summary}\label{summary}
% --------------------------------------------------------------------

Context menus are a powerful way of adding immediate access to the
important parts of your document. Links can be  within a document
or to other documents, even if they are across the World Wide Web.
Multimedia links can also be used to increase the information you
provide to your document users.

Context menus can easily be added to existing documents by hand or via
preprocessing by {\bf awk} or {\bf perl} scripts, for example. We hope
such tools will be made easily available on the Web
as authors start using \TE{} to publish on the Internet.

