| 1 |
% Copyright 1994 Michael John Downes |
| 2 |
% Copyright 2013 TeX Users Group |
| 3 |
% This file is part of the dialogl package, released under the LPPL; |
| 4 |
% see dialogl.ins for details. |
| 5 |
% |
| 6 |
% Originally published in TUGboat with ltugboat documentstyle. |
| 7 |
% Switched to generic article/twocolumn afterward. |
| 8 |
% Does not work with either LaTeX2e or LaTeX 2.09 compatibility mode :(. |
| 9 |
\documentstyle[doc,dialogl-doc]{article} |
| 10 |
|
| 11 |
\title{Interaction tools: {\tt dialog.sty} and {\tt menus.sty}} |
| 12 |
\author{Michael Downes} |
| 13 |
\date{November 3, 1994} |
| 14 |
|
| 15 |
% one latex2e command gets used. |
| 16 |
\def\ensuremath#1{\ifmmode #1\else $#1$\fi\relax} |
| 17 |
|
| 18 |
\hyphenation{pro-duces} |
| 19 |
|
| 20 |
\renewcommand{\thepart}{\arabic{part}} |
| 21 |
\renewcommand{\thesection}{\thepart.\arabic{section}} |
| 22 |
|
| 23 |
% Some customizations of doc.sty parameters. |
| 24 |
\def\PrintMacroName#1{} |
| 25 |
% |
| 26 |
%\renewcommand{\PrintDescribeMacro}[1]{} |
| 27 |
%\renewcommand{\PrintDescribeEnv}[1]{} |
| 28 |
|
| 29 |
\setlength{\MacroIndent}{0pt} |
| 30 |
\def\MacroFont{\verbatimfont}% doc.sty uses \MacroFont |
| 31 |
|
| 32 |
% No modules in the files to be processed; so don't bother checking. |
| 33 |
\DontCheckModules |
| 34 |
|
| 35 |
\multicoldefaultlayout |
| 36 |
\begin{document} |
| 37 |
\jobswitch % print only selected parts if \jobname so indicates; see |
| 38 |
% dialog.sty |
| 39 |
\maketitle |
| 40 |
\thispagestyle{empty} |
| 41 |
|
| 42 |
\begin{multicols}{2} |
| 43 |
\section*{Introduction} |
| 44 |
|
| 45 |
\ifall |
| 46 |
This article describes |
| 47 |
\fn{dialog.sty} and \fn{menus.sty}, which |
| 48 |
provide functions for printing messages or menus on screen and reading |
| 49 |
users' responses. The file \fn{dialog.sty} contains basic message and |
| 50 |
input-reading functions; \fn{menus.sty} takes \fn{dialog.sty} for its |
| 51 |
base and uses some of its functions in defining more complex menu |
| 52 |
construction functions. These two files are set up in the form of |
| 53 |
\LaTeX{} documentstyle option files, but in writing them I spent some |
| 54 |
extra effort to try to make them usable with \plaintex/ or other |
| 55 |
common macro packages that include \plaintex/ in their base, such as |
| 56 |
\AmSTeX{} or \eplain/. |
| 57 |
|
| 58 |
The appendix describes \fn{grabhedr.sty}, required by \fn{dialog.sty}, |
| 59 |
which provides two useful file-handling features: (1)~a command |
| 60 |
\cw{inputfwh} that when substituted for \cw{input} makes it possible to |
| 61 |
grab information such as file name, version, and date from standardized |
| 62 |
file headers in the style promoted by Nelson Beebe\Dash and to grab it |
| 63 |
in the process of first inputting the file, as opposed to inputting the |
| 64 |
file twice, or \cw{read}ing the information separately (unreliable due |
| 65 |
to system-dependent differences in the equivalence of \tex/'s \cw{input} |
| 66 |
search path and \cw{openin} search path). And (2)~functions |
| 67 |
\cw{localcatcodes} and \cw{restorecatcodes} that make it possible for |
| 68 |
\fn{dialog.sty} (or any file) to manage internal catcode changes |
| 69 |
properly regardless of the surrounding context. |
| 70 |
|
| 71 |
These files and a few others are combined in |
| 72 |
\else |
| 73 |
This package is part of |
| 74 |
\fi |
| 75 |
a suite of files that goes |
| 76 |
by the name of {\bf dialogl}, available on the Internet by anonymous ftp |
| 77 |
from CTAN (Comprehensive \tex/ Archive Network), e.g., \fn{ftp.shsu.edu} |
| 78 |
(USA), or \fn{ftp.uni-stuttgart.de} (Europe). |
| 79 |
% |
| 80 |
\ifall |
| 81 |
The file \fn{listout.tex} is a utility for verbatim printing of plain |
| 82 |
text files, with reasonably good handling of overlong lines, tab |
| 83 |
characters, other nonprinting characters, etc. It uses \fn{menus.sty} to |
| 84 |
present an elaborate menu system for changing options (like font size, |
| 85 |
line spacing, or how many spaces should be printed for a tab character). |
| 86 |
\else |
| 87 |
It includes the packages \pkg{dialog}, \pkg{menus}, and \pkg{grabhedr} |
| 88 |
and a utility file \fn{listout.tex} for verbatim printing of plain text |
| 89 |
files. |
| 90 |
\fi |
| 91 |
|
| 92 |
\ifmenus |
| 93 |
Here's an example from the menu system of \fn{listout.tex} to |
| 94 |
demonstrate the use of some features from \fn{dialog.sty} and |
| 95 |
\fn{menus.sty}. First, the menu that you would see if you wanted to |
| 96 |
change the font or line spacing: |
| 97 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 98 |
% This funny way of calling \samepage is (I think) the most |
| 99 |
% convenient way to avoid turning off page breaks for the preceding |
| 100 |
% paragraph. |
| 101 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 102 |
\def\next{\begin{verbatim}\samepage}\next |
| 103 |
=============================================== |
| 104 |
F Change font |
| 105 |
S Change font size |
| 106 |
L Change line spacing |
| 107 |
|
| 108 |
Current settings: typewriter 8 / 10.0pt. |
| 109 |
|
| 110 |
Q Quit X Exit ? Help |
| 111 |
=============================================== |
| 112 |
|
| 113 |
Your choice? |
| 114 |
\end{verbatim} |
| 115 |
Suppose you wanted to change line spacing to 9 points, so you entered |
| 116 |
\qc{\l} (lowercase \qc{\L}) and then \verb'9pt', except that on your |
| 117 |
first attempt you accidentally mistyped \verb'9pe' instead of |
| 118 |
\verb'9pt'. Here's what you would see on screen: |
| 119 |
\begin{verbatim} |
| 120 |
Your choice? l |
| 121 |
Desired line spacing [TeX units] ? 9pe |
| 122 |
?---I don't understand "9pe". |
| 123 |
Desired line spacing [TeX units] ? 9pt |
| 124 |
|
| 125 |
* New line spacing: 9.0pt |
| 126 |
\end{verbatim} |
| 127 |
Both lowercase \verb'l' and capital \verb'L' are acceptable responses, |
| 128 |
and the value given for line spacing is checked to make sure it's a |
| 129 |
valid \tex/ dimension. Before continuing, the internalized version of |
| 130 |
the user's value is echoed on screen to confirm that the entered value |
| 131 |
was read correctly. |
| 132 |
|
| 133 |
Now here's how the above menu is programmed in \fn{listout.tex}. |
| 134 |
A function \cw{menuF} is constructed using \cw{fxmenu}: |
| 135 |
\begin{verbatim} |
| 136 |
\fxmenu\menuF{}{ |
| 137 |
F Change font |
| 138 |
S Change font size |
| 139 |
L Change line spacing |
| 140 |
}{ |
| 141 |
Current settings: &\mainfont &\mainfontsize / % |
| 142 |
&\the&\normalbaselineskip. |
| 143 |
} |
| 144 |
% |
| 145 |
\def\moptionF{\lettermenu F} |
| 146 |
\end{verbatim} |
| 147 |
In the definition of \cw{moptionF}, \cw{lettermenu} is a high-level |
| 148 |
function from \fn{menus.sty} that prints \cw{menuF} on screen (given |
| 149 |
the argument \verb'F'), reads a line of input from the user, extracts |
| 150 |
the first character and forces it to uppercase, then branches to |
| 151 |
the next menu as determined by that character. The response of |
| 152 |
\verb'l' causes a branch to the function \cw{moptionFL}: |
| 153 |
\begin{verbatim} |
| 154 |
\def\moptionFL{% |
| 155 |
\promptmesj{% |
| 156 |
Desired line spacing [TeX units] ? }% |
| 157 |
\readline{Q}\reply |
| 158 |
\end{verbatim} |
| 159 |
If \verb'Q', \verb'X', or \verb'?' was entered, the test |
| 160 |
\cw{xoptiontest} will return `true'; then we should skip the dimension |
| 161 |
checking and go directly to \cw{optionexec}, which knows what to do |
| 162 |
with those responses: |
| 163 |
\begin{verbatim} |
| 164 |
\if\xoptiontest\reply |
| 165 |
\else |
| 166 |
\end{verbatim} |
| 167 |
Otherwise we check the given dimension to make sure it's usable. If so, |
| 168 |
echo the new value as confirmation. |
| 169 |
\begin{verbatim} |
| 170 |
\checkdimen\reply\dimen@ |
| 171 |
\ifdim\dimen@>\z@ |
| 172 |
\normalbaselineskip\dimen@\relax |
| 173 |
\normalbaselines |
| 174 |
\confirm{New line spacing: |
| 175 |
\the\normalbaselineskip}% |
| 176 |
\def\reply{Q}% |
| 177 |
\fi |
| 178 |
\end{verbatim} |
| 179 |
If \cw{reply} was changed to \verb'Q' during the above step, |
| 180 |
\cw{optionexec} will pop back up to the previous menu level (normal |
| 181 |
continuation); otherwise \cw{reply} retains its prior definition\Dash |
| 182 |
e.g., \verb'9pe'\Dash to which \cw{optionexec} will simply say ``I |
| 183 |
don't understand that'' and repeat the current prompt. |
| 184 |
\begin{verbatim} |
| 185 |
\fi |
| 186 |
\optionexec\reply |
| 187 |
} |
| 188 |
\end{verbatim} |
| 189 |
|
| 190 |
For maximum portability, \fn{listout.tex} uses in its menus only |
| 191 |
lowest-common-denominator ordinary printable ASCII characters in the |
| 192 |
range 32\dash 126. Fancier menus can be obtained at a cost of forgoing |
| 193 |
system independence, for instance by using em\tex/'s \verb'/o' option |
| 194 |
to output the box-drawing characters in the standard PC DOS character |
| 195 |
set. |
| 196 |
\fi |
| 197 |
|
| 198 |
\subsection*{Notation} |
| 199 |
|
| 200 |
Double-hat notation such as \verb'^^J' is used herein for |
| 201 |
control characters, as in \TB{}, although occasionally the alternate |
| 202 |
form `{\sc control}-J' is used when the emphasis is away from the |
| 203 |
character's tokenized state inside \tex/. A couple of abbreviations |
| 204 |
from \fn{grabhedr.sty} are used frequently in the macro code: \cw{xp@} |
| 205 |
= \cw{expandafter}, and \cw{nx@} = \cw{noexpand}. Standard |
| 206 |
abbreviations from \fn{plain.tex} such as \cw{z@} or \cw{toks@} are |
| 207 |
used without special comment. |
| 208 |
|
| 209 |
\ifall |
| 210 |
\part{Basic dialog functions: \fn{dialog.sty}} |
| 211 |
\fi |
| 212 |
\ifdialog\hDocInput{dialogl.dtx}\fi |
| 213 |
|
| 214 |
\ifall |
| 215 |
\part{Menu functions: \fn{menus.sty}} |
| 216 |
\setcounter{section}{0} |
| 217 |
\fi |
| 218 |
\ifmenus\hDocInput{menus.dtx}\fi |
| 219 |
|
| 220 |
\ifall |
| 221 |
% It's hard to make this part title come out right without assuming |
| 222 |
% \partname is defined. |
| 223 |
\part*{Appendix\penalty-10000 |
| 224 |
Miscellaneous support functions: |
| 225 |
\fn{grabhedr.sty}} |
| 226 |
\setcounter{section}{0} |
| 227 |
\renewcommand{\thepart}{A} % for use in \thesection |
| 228 |
\fi |
| 229 |
\ifgrabhedr\hDocInput{grabhedr.dtx}\fi |
| 230 |
|
| 231 |
\end{multicols} |
| 232 |
|
| 233 |
\ifdim\textwidth>\textheight |
| 234 |
\typeout{^^JWarning: remember to print using LANDSCAPE orientation^^J} |
| 235 |
\fi |
| 236 |
\end{document} |