Using a Text-Based Interface

The standard front end interface, as discussed in "Using a Notebook Interface", is appropriate for most users' purposes. In some cases, however, you may not need to use the notebook front end, and you may want instead to interact more directly with the Mathematica kernel. You can do this by using a text-based interface, in which text you type on the keyboard goes straight to the kernel.

It is important to note that while the text-based interface provides access to most of the capabilities of the Mathematica kernel, the graphics functionality and dynamic interactivity of the Mathematica front end are not available.

Starting the Mathematica Kernel

To start Mathematica with a text-based interface, you typically type the command math at an operating system prompt.

$ math
Mathematica 9.0 for Linux x86 (64-bit)
Copyright 1988-2012 Wolfram Research, Inc.

C:\Program Files\Wolfram Research\Mathematica\9.0>math
Mathematica 9.0 for Microsoft Windows (32-bit)
Copyright 1988-2012 Wolfram Research, Inc.


Sometimes you may need to provide the full path to the MathKernel executable.

$ /Mathematica/9.0/
Mathematica 9.0 for Mac OS X x86 (64-bit)
Copyright 1988-2012 Wolfram Research, Inc.


On some systems, you may also be able to start Mathematica with a text-based interface by double-clicking a Mathematica kernel icon.

A Mathematica Session

At each stage, Mathematica prints a prompt of the form In[n]:= to tell you that it is ready to receive input. You can then type your input, ending with Enter or Return.

Note that you do not explicitly type the In[n]:= prompt; only type the text that follows this prompt.

When you have entered your input, Mathematica will process it and generate a result. If it prints the result out, it will label it with Out[n]=.

A dialog with Mathematica using a text-based interface.
In[1]:= 2^100

Out[1]= 1267650600228229401496703205376

In[2]:= Integrate[1/(x^3 - 1), x]

1 + 2 x
ArcTan[-------] 2
Sqrt[3] Log[-1 + x] Log[1 + x + x ]
Out[2]= -(---------------) + ----------- - ---------------
Sqrt[3] 3 6

In Mathematica documentation, "dialogs" with Mathematica are often shown in the following way:

The computer prints In[1]:=. You just type in . The line that starts with Out[1]= is the result from Mathematica.
Click for copyable input

Most of the actual dialogs given in the Mathematica tutorials show output in the form you get with a notebook interface to Mathematica; output with a text-based interface looks similar, but lacks such features as special characters and font size changes.

Editing the Input

Ctrl+A,Homemove cursor to the beginning of the input
Ctrl+E,Endmove cursor to the end of input
Ctrl+H,Backspacedelete a character before the cursor
Ctrl+D,Deletedelete a character after the cursor
Ctrl+G,Ctrl+C,Esccancel or abandon the input
Ctrl+Kdelete from the cursor to the end of input
Ctrl+D,Ctrl+Zterminate the kernel
Left,Rightmove the cursor
Up,Downrecall previous input
Enterevaluate the input or add another line
PageUp,PageDownjump to the first or last item in input history

Default keys for editing the input.

If your input is short, then you can give it on a single line. If your input is longer, it is automatically wrapped at the end of the screen to form two or more lines. You can always move the cursor back and insert or delete characters. The wrapped lines will be updated according to your edits.

To move the cursor along the input line, you use the left and right arrow keys on your keyboard. You can also jump to the beginning of the input using the Ctrl+A keys. To jump to the end of input, press Ctrl+E. You can also delete characters before or after the cursor by pressing Ctrl+H or Ctrl+D, or Backspace or Delete, correspondingly.

When your input is long, you can also give it on several lines. Mathematica will automatically continue reading successive lines until it has received a complete expression. Thus, for example, if you type an opening parenthesis or double quotation mark on one line, Mathematica will go on reading successive lines of input until it sees the corresponding closing parenthesis or double quotation mark.

In[1]:= 1+
2 f[

Out[1]= 1 + 2 f[x]

However, if you press Enter to continue on the next line, you will not be able to edit the previous line.

If you paste as input text consisting of several complete Mathematica expressions separated by newlines, these expressions will be interpreted as separate inputs, and you will see several Out[n] prompts.

Occasionally, you may want to erase the input and start again rather than evaluating what has already been typed. To cancel, or abandon, already typed input use Ctrl+G. Or, if you want to delete the input after the cursor position, use Ctrl+K.

A list of keyboard shortcuts is given in the preceding table.

Input History

%n orOut[n]the value of the n^(th) output
In[n]the n^(th) input, for reevaluation
Up,Downscroll input history up or down

Retrieving and reevaluating previous input and output.

With a text-based interface, each line of Mathematica input and output appears sequentially. It is also numbered by consecutive numbers, starting from 1, which are displayed as part of the In[n] and Out[n] prompts. These numbers allow you to retrieve or reevaluate previous input and output. In general, reevaluating a particular piece of input or output may give you a different result than when you evaluated it in the first place. The reason is that in between you may have reset the values of variables that are used in that piece of input or output. If you ask for Out[n], then Mathematica will give you the final form of your n^(th) output. On the other hand, if you ask for In[n], then Mathematica will take the n^(th) input you gave and reevaluate it using whatever current assignments you have given for variables.

Often your computer system will allow you to scroll backward to review previous work and to cut and paste previous lines of input. Or you may recall previously entered input by using the Up or Down arrows.

Terminating the Kernel

To exit Mathematica, type Quit[] at an input prompt. You may also exit Mathematica by pressing Ctrl+D or Ctrl+Z, depending on your computer system. Ctrl+D will terminate Mathematica if the input line is empty.

Ctrl+D, Ctrl+Z, or Quit[]exiting Mathematica

Terminating Mathematica with a text-based interface.

New to Mathematica? Find your learning path »
Have a question? Ask support »