
\chapter{The keyboard}

The way in which \TeXmacs\ reacts on keyboard input depends
on the current \tmref{mode}{}{} (i.e. text mode,
math mode or prog mode) and sometimes on the \tmref{language}{}{}.
By default, \TeXmacs\ defines a certain number of keyboard actions
for each mode. Certain {\LaTeX} commands can also be entered directly
from the keyboard.

When moving the mouse above a menu entry,
a keystroke equivalent is displayed in a help balloon, when available.
The following abbreviations are used for such keystrokes:
\begin{description}
  \item[¤S-¤] For shift key combinations.
  \item[¤C-¤] For control key combinations.
  \item[¤A-¤] For alter key combinations.
  \item[¤E-¤] For escape key combinations.
\end{description}
For instance, ¤E-C-b¤ stands for \key{escape}-\key{ctrl-b}.

As a general rule, the keyboard works as follows:
\begin{description}
  \item[\key{ctrl-$x$}]
    Control key based shorthands are used for commands,
    which are compatible with the corresponding commands in Emacs,
    like \key{ctrl-y} for pasting text.
  \item[\key{alt-$x$}]
    The alter key is used for producing symbols,
    like the Greek letters in math-mode,
    or symbols like {\oe} in text mode.
  \item[\key{esc}-\key{$x$}]
    The escape key is used for {\TeXmacs} commands,
    like producing a fraction. The lower case letters correspond
    to commands which are relevant to all modes.
    The upper case letters correspond to mode-specific commands.
  \item[\key{esc}-\key{esc}-\key{$x$}]
    Double escape sequences are used for producing big operators,
    big delimiters and additional mathematical symbols.
\end{description}

It is possible for the user to modify the keyboard behaviour.
In order to do so, we suggest first to look at the files
in the directory ¤$TEXMACS_PATH/progs/keyboard¤, %$
where the standard keyboard behaviour is defined.
Then you may redefine the keyboard behaviour in your private
\tmref{initialization file}{}{}.

\section{General keyboard actions}
\label{kbd:general}

\subsection{Standard keyboard actions}

Some standard keyboard actions which are valid in all modes are
\begin{description}
  \item[\key{ctrl-backspace}] remove an object or environment.
  \item[\key{shift-home}] go to the start of the document.
  \item[\key{shift-end}] go to the end of the document.
  \item[\key{ctrl-home}] manually set start of the selection.
  \item[\key{ctrl-end}] manually set end of the selection.
  \item[\key{esc}-\key{return}] new line.
  \item[\key{alt-spc}] insert a small space.
  \item[\key{alt-backspace}] insert a small negative space.
\end{description}

\subsection{Manipulation of dynamic objects}

``Dynamic'' objects, such as labels or function definitions are
temporarily inactive, when being modified and activated by
pressing the \key{return}-key. Certain dynamic objects take parameters,
which are inserted using \key{tab} in the deactivated state.
The following dynamic objects can be used in any mode:
\begin{description}
  \item[\key{esc}-\key{!}] insert a label.
  \item[\key{esc}-\key{?}] insert a reference.
  \item[\key{esc}-\key{=}] assign a variable.
  \item[\key{esc}-\key{w}] locally change a variable.
  \item[\key{esc}-\key{m}] define a macro.
  \item[\key{esc}-\key{f}] define a function.
  \item[\key{esc}-\key{i}-\key{s}] insert a symbol.
  \item[\key{esc}-\key{i}-\key{$\#$}] get the value of a macro argument.
  \item[\key{esc}-\key{i}-\key{v}] get the value of a variable.
  \item[\key{esc}-\key{i}-\key{l}] Execute a {\LaTeX} command.
  \item[\key{esc}-\key{i}-\key{e}] expand a macro.
  \item[\key{esc}-\key{i}-\key{a}] apply a function.
  \item[\key{esc}-\key{i}-\key{q}] insert a quote.
\end{description}
For more information on these functionalities and
the creation of executable markup using \key{esc}-\key{x}-\key{$\ldots$},
we refer to \submenu{Help}{styles}.

\subsection{Latex commands}

{\TeXmacs} allows you to enter {\LaTeX} commands directly from the keyboard
as follows. You first hit the \key{$\backslash$}-key
in order to enter the hybrid {\LaTeX}/{\TeXmacs} command mode.
Next you type the command you wish to execute.
As soon as you finished typing your command,
the left footer displays something like
\begin{verbatim}
    <return>: action to be undertaken
\end{verbatim}
When you hit the \key{return}-key at this stage, your command will
be executed. For instance, in math-mode, you may create a fraction
by typing \key{$\backslash$}-\key{f}-\key{r}-\key{a}-\key{c}-\key{return}.

If the command you have typed is not a (recognized) {\LaTeX} command,
then we first look whether the command is an existing {\TeXmacs} macro,
function or environment (provided by the style file). If so,
the corresponding macro expansion, function application or
environment application is created (with the right number of arguments).
Otherwise, it is assumed that your command corresponds to an environment
variable and we ask for its value. The \key{$\backslash$}-key
is always equivalent to one of the commands \key{esc}-\key{i}-\key{l},
\key{esc}-\key{i}-\key{e}, \key{esc}-\key{i}-\key{a},
\key{esc}-\key{i}-\key{$\#$} or \key{esc}-\key{i}-\key{v}.

\section{The keyboard in text mode}
\label{kbd:text}

The only extra keyboard actions available in text mode are \key{\$} %$
in order to enter math-mode and the following shorthands to create
accented characters:
\begin{description}
  \item[\key{esc}-\key{\'{}}] like in \'e.
  \item[\key{esc}-\key{\`{}}] like in \`e.
  \item[\key{esc}-\key{\^{}}] like in \^e.
  \item[\key{esc}-\key{\"{}}] like in \"e.
  \item[\key{esc}-\key{\~{}}] like in \~a.
  \item[\key{esc}-\key{C}] like in \c{c}.
  \item[\key{esc}-\key{U}] like in \u{a}.
  \item[\key{esc}-\key{V}] like in \v{c}.
  \item[\key{esc}-\key{H}] like in \H{o}.
  \item[\key{esc}-\key{O}] like in å.
  \item[\key{esc}-\key{.}] like in \.{z}.
\end{description}
For instance, \key{esc}-\key{\'{}}-\key{e} produces \'e.

The special characters \ss, \SS, \oe, {\OE}, {\ae} and {\AE}
are obtained by typing \key{alt-s}, \key{alt-S}, \key{alt-o}-\key{alt-e},
\key{alt-O}-\key{alt-E}, \key{alt-a} resp. \key{alt-A}.

In French, you may also use the special keybindings \key{$<$}-\key{$<$} and
\key{$>$}-\key{$>$} in order to obtain the French {\em guillemets\/}.
In Spanish, the opening exclamation and question marks are obtained
by typing \key{!}-\key{*} (or \key{!}-\key{`}) resp.
\key{?}-\key{*} (or \key{?}-\key{`}).

\section{The keyboard in math mode}
\label{kbd:math}

In math-mode, you can again use \key{\$} to re-enter in text-mode. %$
The \key{alt}-key in combination with a letter is used for
producing Greek characters.

\subsection{Mathematical objects}

The main mathematical objects are created as follows:
\begin{description}
  \item[\key{esc}-\key{\$}] insert text. %$
  \item[\key{\tmunsc}] create a subscript.
  \item[\key{\^{}}] create a superscript.
  \item[\key{esc}-\key{L}-\key{\tmunsc}] create a subscript on the left.
  \item[\key{esc}-\key{L}-\key{\^{}}] create a superscript on the right.
  \item[\key{\'{}}] create a prime.
  \item[\key{\`{}}] create a ``back-prime''.
  \item[\key{esc}-\key{F}] or \key{esc}-\key{/} create a fraction.
  \item[\key{esc}-\key{S}] create a square root.
  \item[\key{esc}-\key{R}] create an $n$-th root.
  \item[\key{esc}-\key{N}] create a negation.
\end{description}

\subsection{Accents in math-mode}

The following key combinations are used for creating mathematical accents:
\begin{description}
  \item[\key{esc}-\key{\~{}}] for tildes like in $\tilde{x}$.
  \item[\key{esc}-\key{\^{}}] for hats like in $\hat{x}$.
  \item[\key{esc}-\key{C}] for checks like in $\check{x}$.
  \item[\key{esc}-\key{B}] for vectors like in $\bar{x}$.
  \item[\key{esc}-\key{V}] for vectors like in $\vec{x}$.
  \item[\key{esc}-\key{\'{}}] for acute accents like in $\acute{x}$.
  \item[\key{esc}-\key{\`{}}] for grave accents like in $\grave{x}$.
\end{description}

\subsection{Large symbols}

The following key-combinations are used in order to create large symbols:
\begin{description}
  \item[\key{esc}-\key{esc}-\key{S}] produces $\sum$.
  \item[\key{esc}-\key{esc}-\key{P}] produces $\prod$.
  \item[\key{esc}-\key{esc}-\key{I}] produces $\int$.
  \item[\key{esc}-\key{esc}-\key{O}] produces $\oint$.
  \item[\key{esc}-\key{esc}-\key{A}] produces $\amalg$.
  \item[\key{esc}-\key{esc}-\key{N}] produces $\bigcap$.
  \item[\key{esc}-\key{esc}-\key{W}] produces $\bigwedge$.
  \item[\key{esc}-\key{esc}-\key{U}] produces $\bigcup$.
  \item[\key{esc}-\key{esc}-\key{V}] produces $\bigvee$.
  \item[\key{esc}-\key{esc}-\key{\tmat}-\key{.}] produces $\bigodot$.
  \item[\key{esc}-\key{esc}-\key{\tmat}-\key{+}] produces $\bigoplus$.
  \item[\key{esc}-\key{esc}-\key{\tmat}-\key{x}] produces $\bigotimes$.
  \item[\key{esc}-\key{esc}-\key{L}-\key{I}] produces $\int$ with limits.
  \item[\key{esc}-\key{esc}-\key{L}-\key{O}] produces $\oint$ with limits.
\end{description}

\subsection{Large delimiters}

Large delimiters are created as follows:
\begin{description}
  \item[\key{esc}-\key{esc}-\key{(}] produces $($.
  \item[\key{esc}-\key{esc}-\key{)}] produces $)$.
  \item[\key{esc}-\key{esc}-\key{[}] produces $[$.
  \item[\key{esc}-\key{esc}-\key{]}] produces $]$.
  \item[\key{esc}-\key{esc}-\key{\{}] produces $\{$.
  \item[\key{esc}-\key{esc}-\key{\}}] produces $\}$.
  \item[\key{esc}-\key{esc}-\key{$<$}] produces $\langle$.
  \item[\key{esc}-\key{esc}-\key{$>$}] produces $\rangle$.
  \item[\key{esc}-\key{esc}-\key{$|$}] produces $|$.
  \item[\key{esc}-\key{esc}-\key{/}] produces $/$.
  \item[\key{esc}-\key{esc}-\key{b}] produces $\backslash$.
\end{description}

In \TeXmacs, large delimiters may either be
``left delimiters'', ``right delimiters'' or ``middle delimiters''.
By default, $(, [, \{$ and $\langle$ are left delimiters,
$), ], \}$ and $\rangle$ are right delimiters and
$|, /$ and $\backslash$ are middle delimiters.
But there status can be changed using the \key{esc}-\key{esc}-\key{l},
\key{esc}-\key{esc}-\key{r} and \key{esc}-\key{esc}-\key{m} key combinations.
For instance, \key{esc}-\key{esc}-\key{l}-\key{)} produces $)$,
considered as a large left delimiter.

In {\TeX} and {\LaTeX}, ``middle delimiters'', or ``separators'' do not exist;
they are used for producing the vertical bars in formulas like
\[ \left\langle \frac{a}{b+c} \left|
                \frac{p}{q+r} \right|
                \frac{a}{b+c} \right\rangle. \]
There may be as many middle delimiters between a left and
a right delimiter as one wishes.

\subsection{Other mathematical symbols}

Other mathematical symbols are obtained by ``natural''
key-combinations. For instance, \key{$-$}-\key{$>$} yields $\rightarrow$,
\key{$-$}-\key{$-$}-\key{$>$} yields $\longrightarrow$ and
\key{$>$}-\key{$=$} yields $\geqslant$. Similarly,
\key{$|$}-\key{$-$} yields $\vdash$, \key{$|$}-\key{$-$}-\key{$>$}
yields $\mapsto$ and \key{$-$}-\key{$>$}-\key{$<$}-\key{$-$}
yields $\rightleftarrows$.

Some general rules hold in order to obtain variants of symbols:
\begin{description}
  \item[\key{$\star$}] is the main key for obtaining variants.
        For instance, \key{$>$}-\key{$=$} yields $\geqslant$,
        but \key{$>$}-\key{$=$}-\key{$\star$} yields $\geq$.
        Similarly, \key{$<$}-\key{$\star$} yields $\prec$,
        \key{$<$}-\key{$\star$}-\key{$=$} yields $\preccurlyeq$ and
        \key{$<$}-\key{$\star$}-\key{$=$}-\key{$\star$} yields $\preceq$.
  \item[\key{\tmat}] is used for putting symbols into circles or boxes.
        For instance, \key{\tmat}-\key{+} yields $\oplus$ and
        \key{\tmat}-\key{x} yields $\otimes$. Similarly,
        \key{\tmat}-\key{$\star$}-\key{+} yields $\boxplus$.
  \item[\key{/}] is used for negations. For instance,
        \key{$=$}-\key{/} yields $\neq$ and \key{$<$}-\key{$=$}-\key{/}
        yields $\not{\leqslant}$. Notice that
        \key{$<$}-\key{$=$}-\key{$\star$}-\key{$\star$}-\key{/}
        yields $\nleqq$, while
        \key{$<$}-\key{$=$}-\key{$\star$}-\key{$\star$}-\key{/}-\key{$\star$}
        yields $\lneqq$.
\end{description}

Below follows a list of other characters, which are not obtained
in a straightforward manner by the above system.
\begin{description}
  \item[Variants.]
        Small variants of the large delimiters are obtained as follows:
        \key{esc}-\key{esc}-\key{a} yields $\amalg$,
        \key{esc}-\key{esc}-\key{n} yields $\cap$, etc.
  \item[\key{esc}-\key{esc}-\key{d}] yields $\partial$.
  \item[\key{esc}-\key{esc}-\key{x}] yields $\times$.
  \item[\key{esc}-\key{esc}-\key{p}] yields $\wp$.
\end{description}

\section{The keyboard in prog mode}
\label{kbd:prog}

You enter programming mode either using \key{pound} or
by starting a programming session from the menu \submenu{Insert}{session}.
In programming mode, the current paragraph is executed each time when
you type \key{return}. If you want to insert a carriage return,
type \key{shift-return}.
