# TeX at the Command Line

How does TeX work at the command line? More specifically, after having installed LaTeX, I found that typing tex in the command line opened up an interpreter. However, I have no idea what I can do here! If I type something like \pi, nothing happens! What does this TeX interpreter at the command line do?

• You've said you installed LaTeX but then ran tex at the command line: which one are you aiming to use? (If that question doesn't make sense to you, take a look at What is the difference between TeX and LaTeX?.) – Joseph Wright Jan 8 '15 at 8:36
• Hit enter and then your \pi should give an error. Type "x" and hit enter to quit. If you type \relax abc \bye at the ** prompt you will get a dvi with "abc" in it. If you start the whole experiment with pdftex you will get a pdf. If you type simply abc tex will try to find and open the file abc.tex. – Ulrike Fischer Jan 8 '15 at 9:04
• @JosephWright I was aiming to mess around with TeX- just mentioning how I cam about installing it in case that was relevant. – user41692 Jan 8 '15 at 9:06
• @UlrikeFischer I'll try when I get back to my computer. I wasn't getting an error though. I got one initial mathmode error, but then nothing. What does the \relax command do? – user41692 Jan 8 '15 at 9:08
• Well a mathmode error is an error, so you got an error. The \relax avoids that tex interprets the following text as file name. – Ulrike Fischer Jan 8 '15 at 9:37

TeX is designed to read input either from a file or from the command line: indeed, if you have a file that doesn't properly end a TeX run you'll get the prompt wait for more input. When you start TeX at the prompt without giving it a file name, you'll get something like

This is TeX, Version 3.14159265 (TeX Live 2014/W32TeX) (preloaded format=tex)
**

where the two * are important. For this first prompt, TeX will try to look for a file name if you give just 'some text'. As such, it's normally safest to put \relax here (\relax is TeX's do-nothing command, so makes no change to the results).

This is TeX, Version 3.14159265 (TeX Live 2014/W32TeX) (preloaded format=tex)
**\relax

*

Notice that there is only one * now: TeX is no longer looking for a file name. Any input given is now treated in exactly the same way as if it were in a file. As we are talking about running tex, that means we use plain TeX syntax. We might therefore do

*Hello world

* $y = mx + x$.

*\bye
[1]
Output written on texput.dvi (1 page, 296 bytes).
Transcript written on texput.log.

That will produce a .dvi file containing thext text Hello world y = mx + c with the formula in math mode. There will also be a page number as plain adds that automatically. You can then convert the .dvi to PDF format sing dvips/ps2pdf or dvipdfmx. (with no file name given, TeX default to the job name texput.)

As noted in a comment, running pdftex will give direct PDF output but otherwise the same process occurs. LaTeX can be run interactively with latex or pdflatex: the same considerations apply except the pre-defined control sequences are different.