# Nonlinear Input for (La)TeX IME

Since (La)TeX is a programming language (yes, it is a Turing-complete language) many of the math symbols are available as commands/functions and to help user type a text is need that the IME change the cursor position based on user inputs. At this post I will show what the IME that I’m writing should do with the cursor.

## Notation

To represent the cursor position I will use Unicode black vertical rectangle, .

## Change Cursor Key

We need to define a key to move the cursor to the next “place holder”. The RETURN key is suitable to do this because have \n inside a command or environment is rare and most of the cases it happens its purpose is make easy to read the source code ((La)TeX treats \n\n as a new paragraph but \n is ignored).

## General Commands

(La)TeX commands are, normally, of the form \command[]{} and the jumps are showed below:

• Before press the key that will insert the command:

▮

• After press the key that inserted the command:

\command[▮]{}

• After press RETURN:

\command[]{▮}

• After press RETURN:

\command[]{}▮


## General Environments

(La)TeX environments are, normally, of the form \begin{environment}[]\end{environment} and the jumps are showed below:

• Before press the key that will insert the environment:

▮

• After press the key that inserted the environment:

\begin{environment}[▮]\end{environment}

• After press RETURN:

\begin{environment}[]▮\end{environment}

• After press RETURN:

\begin{environment}[]\end{environment}▮


## Special Cases

### Vertical Bar

• Before press the key:

▮

• After press the key:

|▮|

• After press RETURN:

||▮


### Double Vertical bar

• Before press the key:

▮

• After press the key:

\|▮\|

• After press RETURN:

\|\|▮


### Subscript and Superscript

• Before press the key:

▮

• After press the key:

{▮}_{}^{}

• After press RETURN:

{}_{▮}^{}

• After press RETURN:

{}_{}^{▮}

• After press RETURN:

{}_{}^{}▮


### Underset and Overset

• Before press the key:

▮

• After press the key:

\underset{▮}{\overset{}{}}

• After press RETURN:

\underset{}{\overset{▮}{}}

• After press RETURN:

\underset{}{\overset{}{▮}}

• After press RETURN:

\underset{}{\overset{}{}}▮