(La)TeX

 

1. How to Start

On the College network there is an installation of (La)TeX, a type-setting program widely used at universities and for scientific publications, in many different subjects. Amongst reasons that it is so widely used are that
  1. it produces nice output, especially mathematical/ scientific/ economic formulae,
  2. the program takes care of most of the lay-out, including spacing, sizes, table of contents, and so on,
  3. it works the same on different operating systems: MS Windows, Linux, Mac, and files are interchangeable.
An installation consists of three components:
  1. a text-editor, to make .tex-files: this could just be Notepad, but we have installed a nice, free program, Crimson Editor,
  2. a compiler, to turn .tex-files into .dvi-files: this can be started while a file is being edited in Crimson Editor, by pressing Ctrl+1,
  3. a viewer for .dvi-files, which is also used to print the files: this can be started from Crimson Editor by pressing Ctrl+2.
Here is how to start:
  1. log-on as usual,
  2. in your H:-drive, create a new folder 'tex' for the new files you will make,
  3. create a new icon for Crimson Editor on your desktop:
    1. right-click on any empty space on the desktop, and select New > Shortcut,
    2. select Browse, and navigate to the folder C:\Program Files\Crimson Editor,
    3. click on the file 'cedt.exe', (the file with a dog-icon next to it,) and press Next,
    4. enter a name, like 'Crimson Editor', and press Finish.
  4. copy the following into the editing window:
    \documentclass{article}
    \begin{document}
    Hello, world!
    \end{document}
  5. Save As 'try.tex' (or some other 'filename.tex') in your new 'tex'-folder,
  6. press Ctrl+1, (the output-window below the editing window will show how the compilation is progressing: don't worry about this for now,) and then Ctrl+2, to view the file.

(Btw, Crimson Editor is good for other things too, like editing of html-files.)


2. What to Do Next

To get you started and see what can be done, you can copy the following file to your 'tex'-folder: exam1.tex (-- right-click on the link and select Save Target As ...; if you get a security warning, you need to change settings in Internet Explorer > Tools > Internet Options > Security.) Then open the file in Crimson Editor, compile it with Ctrl+1 and view it with Ctrl+2.

Note:
If the compilation is successful, the last line in the output-window will be:

Terminated with exit code 0
Otherwise, if there is an error (in the syntax, not in the content ...) in your .tex-file, read what it says: it may tell you what the problem is. Then right-click in the output-window and select Kill Process; you can then try to correct the mistake in your file and compile again.

It may be useful to also create an icon for the LaTeX help-file on your desktop, as follows:

  1. right-click on any empty space on the desktop, and select New > Shortcut,
  2. select Browse, and navigate to the folder C:\texmf\doc\latex\help,
  3. click on the file 'latex2e.html', (or 'latex2e.chm' or 'latex2e.hlp': these are the same file in different formats,) and press Next,
  4. enter a name, like 'LaTeX Help', and press Finish.


3. How to ...

I intend to put together an introduction to (La)TeX, at a rate of perhaps a section per week, with the needs of EE-students in mind.

... start making a document

Every .tex-file must have a proper beginning and a proper end, such as:
\documentclass{article}
    ... preamble: define layout and general commands ...
\begin{document}
    ... content ...
\end{document}
There are a number of different document classes: apart from 'article' there are 'book' and 'letter', and they have most of the typical formatting built in.

Note that the commands and special values in (La)TeX start with a back-slash '\'. Some of these take their input from brackets that follow them: so with each such instruction one needs to know what further information is allowed or required, and in which format it needs to be given; (like on the calculator.)

For instance, the first line above could read (-- 'pt' = 'point' is a measure of size; the alternatives here are '10pt' and '11pt'):

\documentclass[a4paper,12pt]{article}
(If you open an empty document in UltraEdit32, and click on 'Advanced' > Insert Template > 0, you will have a good starting point for a document: the margins are set narrower than the default settings.)

(La)TeX allows all manner of fine adjustment of the output on screen or page; try putting

This text is in normal size.
{\Large This text will be printed larger.}
into your document and compile and preview it. There are in fact 10 standard size-changing commands: '\tiny', '\scriptsize', ..., '\huge', '\Huge'; (note that case matters, 'huge' is not the same as 'Huge'!) The braces '{...}' define the scope of the command, to how much of the text it should apply.

But before getting used to using these, get used to not using them: the power of (La)TeX comes from the fact that you concentrate on the logical ordering of your material, and leave the details of the lay-out to the program.

Another thing that makes (La)TeX such a powerful tool is that you can define your own commands and values. See what happens when you put the next lines into the 'document' section of your file (-- the '\par' starts a new paragraph):

\newcommand{\mytext}{Try doing this in MS Word \ldots \par}
{\small \mytext}
{\normalsize \mytext}
{\large \mytext}
{\Large \mytext}
{\LARGE \mytext}
Happy TeXing!

... make nice formulae/equations

To make nice-looking formulae and equations, (La)TeX needs to be switched into maths mode, and then out of it again. We can make ...
  1. a formula that is part of the line of text in which it apears; (the start and the end command can both be replaced by just a $-sign):
    \( f(x) = (x + 1)^2 \)
  2. a formula that is set apart from the text, centered:
    \[ (x + 1)^2 = x^2 + 2x + 1 \]
  3. a formula that is set apart from the text, centered, with an equation number at the right margin, (though this can be changed):
    \begin{equation} x^2 + 2x + 1 = 0 \end{equation}
Note that the spacing of symbols in maths mode, as anywhere else in a .tex file, does not matter: the lay-out is taken care of automatically.

The range of symbols that are available is much too wide to be listed here, so I will just give a few examples.

$\sin^2 \theta + \cos^2 \theta = 1$
(the whole Greek alphabet is available, of course.) Whereas variables appear in italics, function-names with a \ prefixed will be upright.
$\displaystyle \int_0^{\frac 1 2}
\frac{1}{\sqrt {1 - x^2}} \;dx = \frac \pi 6$
(braces are used to group elements together; \displaystyle increases the size of symbols in fractions etc.) Matrices are easy too:
$\pmatrix{ 3 & -1 & 2 \cr 4 & 2 & 0 }^{-1}
\cdot \overrightarrow{PQ}$
If there is a notation that is missing, or one wants a shortcut, one can with a little experience define one's own commands:
\newcommand{\D}{\displaystyle}
$\D S_n = a\, \frac {r^n - 1}{r - 1}$
( \, and \; add a little extra space; \quad and \qquad add more space.) Over the years, many users have invented useful new commands that can be copied; thus, the following makes available the symbol for the set of natural numbers, which strangely is missing:
\newcommand{\N}{\mbox{$I\!\!N$}}
$3 \in \N$ but~ $\ln 3 \notin \N$
( ~ makes a hard space.) New commands can even take arguments, like
\newcommand{\area}[3]
{area $= {1 \over 2} \, #1 \, #2 \, \sin #3$}
\area{b}{c}{A}
With just a list of the many maths-commands that are available, most people should not find it too hard to produce nice-looking output quickly.

Happy TeXing!

... structure a document

The best advice here is to just let (La)TeX get on with it: many years of experience of type-setting, to make articles and books attractive and easy to read, are built into the program.

This is what a basic document might look like; you could copy and paste this into an empty document and then compile it (-- up to three times, for the table of contents to be compiled --) and look at it:

\documentclass[a4paper,12pt,titlepage]{article}
\title{Extended Essay:\\ My Really Interesting Topic}
\author{Who I. Am,\\ Atlantic College}
\begin{document}
\maketitle
\begin{abstract}
\noindent
   This is a very brief abstract of no Extended Essay,
   which probably looks better without an indent in the
   first line; (an indent is the \LaTeX default.)
\end{abstract}
\tableofcontents
\newpage
\section{First Header}
   Here goes the introduction, including something like a
   'research question' that the IB says every essay should
   have.
\newpage
\section{Second Header}
   Here is where the body of the argment goes; of course
   it makes sense to divide it into subsections.
\subsection{My Hypothesis}
   With the documentclass 'article', to put the title page
   and the abstract on separate pages, specify the option
   'titlepage'.
\subsection{My Experiment}
   By default, \LaTeX includes sections, subsections and
   subsubsections in the table of contents, but this can
   be changed.
\subsection[My Results]{How I Fiddled It}
   Here, the text that appears in the table of contents
   is 'My Results', but the heading in the text is the
   truth, of course.
\subsection*{My Evaluation}
   With the command in this form, the subsection is not
   numbered and not entered into the table of contents.
\newpage
\section{Conclusion}
   An E$^2$, like a novel, as was once recommended to an
   eager beginner, should have a beginning, a middle and
   an end.\par
   The next line, by the way, enters a line which is not
   a heading in the text into the table of contents
\newpage
\addcontentsline{toc}{section}{Appendix}
\appendix
\section{What I had no space for ...}
   Note that after the command $\backslash$appendix,
   sections are labelled with letters rather than
   numbers.
\end{document}
The details for the titlepage are entered in the preamble, but they appear in the document when the command \maketitle is given.

As it is, the date when the document is compiled will be appear; with the command \date{07 November 2003} in the preamble, the fixed date will appear instead.

Happy TeXing!

... set font defaults and change fonts

(La)TeX comes with a number of fonts and many font variations installed, but the flexibility and configurability of the way fonts are handled means that this is not a simple topic.
  1. We will first see how to change the default font families for a document. Note that all these changes must be made in the preamble, before the \begin{document} command.

    For each document three default fonts are set, a roman (serif) font, a sans serif font and a typewriter (monospace) font; the values of these are set by commands of the form

    \renewcommand{\rmdefault}{ptm}
    You can then choose which of the three to take as the main font family for your document by means of something like
    \renewcommand{\familydefault}{\rmdefault}
    Which families are available depends on the particular installation, but you should find at least the following:
    roman (serif)\rmdefaultcmr, pbk, pnc, ppl, ptm
    sans serif\sfdefaultcmss, pag, phv
    typewriter (monospace)\ttdefaultcmtt, pcr
    speciality fontscmfib, cmfr, cmdh, pzc
    The (La)TeX defaults for \documentclass{article} are the Computer Modern fonts cmr, cmss and cmtt, and the default for the main document font is \rmdefault.

    (Unfortunately the characters are not in the same order in all font files, so if you get some 'funny' characters, try putting

    \renewcommand{\encodingdefault}{T1}
    into the preamble.)
  2. There are also packages available that set the default text fonts, or change or extend features available in mathematical mode, or set both a text font and a matching mathematical font. To load, use a command like
    \usepackage{bookman}
    in the preamble; (try it first without using any of the other commands to change defaults -- you can always 'comment out' the text on a line without having to remove it, by putting a %-sign in front of it.)
    text fontsbookman, palatino, times
    math fontsamsmathprovides a variety of extra mathematical features
    eucalsets up the command \CMcal{} to use the Euler script symbols in math mode
    eufraksets up the command \mathfrak{} to use the Euler Fraktur alphabet in math mode
    text font and a matching math fontmathpazo, mathpple, mathptmx
  3. Once you have defined the defaults for the three font families, you can select the default series and shape in the same way:
    \renewcommand{\seriesdefault}{bx}
    \renewcommand{\shapedefault}{it}
    The possible values for the series are 'bx' (= bold face) and 'm' (= medium,) and for the shape 'it' (= italics,) 'sl' (= slanted,) 'sc' (= small capitals) and 'n' (= normal.) The defaults are medium normal.

    If, as sometimes happens, there are no font files for some combination of family, series, shape and size, then (La)TeX will produce a warning

    Font shape `T1/cmss/m/sc' in size <12> not available
    and try to find a substitute.
  4. Having defined the default settings for your document, you can then change the font of sections of text by using simple declarations:
    This is normal text and {\scshape Small Capitals,}\\
    {\ttfamily monospace and {\slshape slanted monospace,}}\\
    {\itshape italics and {\bfseries bold italics,}} and \\
    {\sffamily it even works {\large in different sizes.}}
    Conveniently, each of these declarations has a corresponding command, i.e. the following two lines will produce the same output:
    {\slshape slanted text {\bfseries and also bold}}
    \textsl{slanted text \textbf{and also bold}}
    And once again you can easily define new commands for fonts that you use frequently:
    \newcommand{\myfont}[1]{\texttt{\textsc{#1}}}
    I can now \myfont{change to My New Font} and back.
    -- here the new command \myfont takes one argument, which is the section of text to which it is applied.

Happy TeXing!

... draw pictures and graphs

Graphs are put into a document using the picture environment:
\setlength{\unitlength}{0.8cm}
\begin{picture}(8,5)
...
\end{picture}
Here the two numbers after \begin{picture} determine the width and height of the picture, and the \setlength -command determines the unit that is used throughout -- so this picture would actually be 6.4 cm wide and 4 cm high. That makes rescaling the picture very easy: just change the value of \unitlength.

Objects are drawn into the picture with the \put -command:

\put(0.2,1){\vector(1,0){7.6}}
\put(1,0.2){\vector(0,1){4.6}}
\put(0.5,4){\line(2,-1){5.5}}
The two numbers after \put are the starting coordinates, the two numbers in (...) after \vector and \line are the Δx and Δy that determine the gradient, and the number in {...} is the length of the arrow or line.

Here are some more things we can draw into our picture:

\multiput(2,1)(1,0){6}{\line(0,-1){0.2}}
\put(1.9,0.3){1}
\put(7.5,1.2){$x$}
\put(3.4,3){gradient $m = - \frac 1 2$}
After the \multiput, the first pair of numbers are the starting coordinates, the second pair determine the change from one object to the next, and the number in {...} determines how many objects are drawn.

It is easy to look up the commands for other objects in the help-file -- it may be useful to put a link to ...\texmf\doc\latex\help\latex2e.html onto your desktop.

Unfortunately, the (La)TeX picture-environment is rather limited in what can be done; for instance only circles up to 40pt diameter and only lines whose gradients are very simple ratios can be drawn. Fortunately, though, there are packages that can be used that make available many more useful commands.

To be able to use a package, you have to load it in the preamble, i.e. before the line \start{document}, with a command like

\usepackage{curves}
For (La)TeX to be able to find the .sty-file for the package, it may be easiest for now if you just put it into the same directory as the .tex-file in which it is used. To obtain the file, right-click on the link below and select 'Save Target As ...'

With the package curves.sty, commands like the following become available (-- all the details can be found in curves.dvi):

\put(4,2.5){\bigcircle{4.8}}
\put(4,2.5){\arc(3,0){-45}}
\put(1,1){\curve(0,1,1,0,2,1,3,4)}
Similarly, if you use the packages epic.sty (for 'extended picture environment') and eepic.sty for ('extended extended picture environment') commands like the following can be used (-- again, all the details can be found in eepic.dvi):
%  draw lines of any gradient
\put(3.6,0.4){\line(7,3){4}}
%  define symbols to use in the graphs
\newcommand{\mybull}{\makebox(0,0){$\bullet$}}
\newcommand{\mycirc}{\makebox(0,0){$\circ$}}
%  draw a line graph, method 1
\put(1,3){\path(0,0)(5,1)(6,-2)}
\put(1,3){\mybull}
\put(6,4){\mybull}
\put(7,1){\mybull}
%  draw a line graph, method 2
\begin{dashjoin}{0.1}
  \jput(1,1.5){\mycirc}
  \jput(2,4.5){\mycirc}
  \jput(7,0.5){\mycirc}
\end{dashjoin}
\put(2.2,4.6){maximum}
(Remember that the symbol % makes the rest of the line a comment, which will not appear in the .dvi file or on the print-out.)

Happy TeXing!

... draw bar charts and functions

... make your own page layout

Page layout settings are also changed by commands in the preamble. The margins in (La)TeX default layout are rather wide; to produce a larger area for text, use something like the following:
\setlength{\hoffset}{-15.4mm}
\setlength{\voffset}{-25.4mm}
\setlength{\evensidemargin}{5mm}
\setlength{\footskip}{5.4mm}
\setlength{\oddsidemargin}{5mm}
\setlength{\textwidth}{180mm}
\setlength{\textheight}{260mm}
You should be able to look up other variables whose values can be redefined.