A Sampler of L^{A}TEX Features

Berna Massingill

Contents

1 Text and sectioning

1.1 Text

L^{A}TEX formats lines into paragraphs automagically. For purposes of illustration, I’ll put in some extra text here: lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots of words.

A blank line in the source starts a new paragraph, like this one. For purposes of illustration, I’ll put in some extra text here: lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots of words.

And here’s yet another paragraph with lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots of words.

Here is yet another paragraph, this one preceded by some space and not indented. Look at the source for how that was accomplished.

One thing you do have to be careful about is making sure TEX doesn’t interpret periods as “end of sentence” (which would result in its adding a bit of extra space). Example: Dr. Smith-Jones has a hyphenated last name.

1.2 Text styles

You emphasize text with the \emph macro. There are also macros for applying various different styles (italics, etc.) to text.

• \textsf (looks like this)

• \texttt (looks like this)

• \textbf (looks like this)

• \textit (looks like this)

• \textsl (looks like this)

• \textsc (looks like this)

I like to use typewriter font (\texttt) for program variables and command names, as well as for URLs, but for the former it may be better to use verb, which allows including characters that normally would need to be “escaped”, such as some of the characters in !@#$%^&*()_<>, and for the

latter it may be better to use \url (e.g., http://www.cs.trinity.edu/

~bmassing), which breaks lines where needed and does something reasonable with the tilde character (~).

2 Lists and other environments

2.1 Itemized lists

Here is an itemized list.

• An item. (For purposes of illustration, part of the list entry is this sentence with lots and lots and lots and lots and lots and lots and lots and lots and of words.)

• Another item. (For purposes of illustration, part of the list entry is this sentence with lots and lots and lots and lots and lots and lots and lots and lots and of words.)

This one has subitems.

– An item. (For purposes of illustration, part of the list entry is this sentence with lots and lots and lots and lots and lots and lots and lots and lots and of words.)

– Another item. (For purposes of illustration, part of the list entry is this sentence with lots and lots and lots and lots and lots and lots and lots and lots and of words.)

It has some text after it. (Note that text after a list is only set flush left if it doesn’t start a new paragraph.)

2.2 Enumerated lists

Here is an enumerated list.

1. An item. (For purposes of illustration, part of the list entry is this sentence with lots and lots and lots and lots and lots and lots and lots and lots and of words.)

2. Another item. (For purposes of illustration, part of the list entry is this sentence with lots and lots and lots and lots and lots and lots and lots and lots and of words.) This one has subitems.

(a) An item. (For purposes of illustration, part of the list entry is this sentence with lots and lots and lots and lots and lots and lots and lots and lots and of words.)

(b) Another item. (For purposes of illustration, part of the list entry is this sentence with lots and lots and lots and lots and lots and lots and lots and lots and of words.)

2.3 “Description” lists

Here is a “description list”.

Something. An item. (For purposes of illustration, part of the list entry is this sentence with lots and lots and lots and lots and lots and lots and lots and lots and of words.)

Another thing. Another item. (For purposes of illustration, part of the list entry is this sentence with lots and lots and lots and lots and lots and lots and lots and lots and of words.)

2.4 Centered text and block quotations

Here is some centered text, with explicit line breaks.

A first line A second line with more text Another line And one more

and here is some text set off as one would a long quotation, also set in a much smaller type size.

(For purposes of illustration, part of the list entry is this sentence with lots and lots and lots and lots and lots and lots and lots and lots and of words.)

Here is that example again, using a user-defined environment.

(For purposes of illustration, part of the list entry is this sentence with lots and lots and lots and lots and lots and lots and lots and lots and of words.)

3 Math

Here is some math inline: c = \sqrt{a^{2} + b^{2}}. And here is the same math “displayed” (on a separate line and centered).

c = \sqrt{a^{2} + b^{2}}

And here it is again with an equation number:

c = \sqrt{a^{2} + b^{2}}  (1)

As another more complicated example, taken from one of my programming assignments, the following is a recursive version of Euclid’s algorithm for finding the greatest common divisor of non-negative integers a and b:

gcd(a, b) = \{ \begin{matrix}a & if b = 0 \\ gcd(b, a mod b) & otherwise \end{matrix}

(a mod b is the remainder when a is divided by b.)

4 References, etc.

L^{A}TEX includes a lot of features useful in writing scholarly papers (which after all is what it was designed for).

4.1 Cross-references

You can label things and reference them later, with or without the pages on which they appear. For example, Equation ?? appears on page ??, Section ?? appears on page ??, and Section ?? appears on page ??. There are more uses of references in the section on figures and tables (Section ??).

4.2 Footnotes

You can also have footnotes.^{1} Here^{2} is another example.

4.3 Bibliographies

There is also nice support for bibliographies, particularly in combination with companion program BibTEX. Here I’m going to shamelessly plug two of my own (well-aged) papers [?, ?] and also cite a book [?] and a Web site [?].

5 Figures and tables

Figures and tables “float” (might appear somewhere other than where they are in the input source). You can include with each figure or table a caption (positioned above or below) and of course a label you can (and usually should) use to reference it in the text. In the examples, captions appear after the figure or table, though you could choose to put them above. (Notice that the captions include some explanatory text. When to put explanatory text in a figure’s caption and when to put it in the main text — well, it probably merits some thought.)

For example, this section includes Table ??, which is defined after this sentence but which might appear (almost) anywhere. (To make this a slightly

1This is a footnote. It can include more than one sentence, and in fact could be quite long.

2Another footnote.

This  that  a line
Whatever whichever another line

Table 1: This is a simple table. Default spacing is, in my opinion, not very pretty, so I changed it in the preamble.

more realistic example I’ll add some more text here discussing the table: This is a sentence with lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots and lots of words.)

As another example, Figure ?? shows how to include an image or diagram from a file created by some other program. Again I’ll put in some more

Figure 1: This is a picture of an XOR circuit I drew for my CSCI 2321 class years ago. It’s scaled here to half the text width. I drew this with xfig.

explanatory text so maybe it’s clearer how this works.

As yet another example, particularly relevant in our field, Figure ?? and Figure ?? show two simple ways of including code, while Figure ?? and Figure ?? show two not-so-simple ways of including code with an enclosing “box”.

     #include <iostream>
     int main(void) {
         cout << "Hello, world!\n";
         return 0;
     }

Figure 2: This is a figure that consists of code. Making it a figure keeps it all on one page and gives it a number we can reference. I used the quoted environment to indent it.

     #include <iostream>
     int main(void) {
         cout << "Hello, world!\n";
         return 0;
     }

Figure 3: This is another figure with the same code as Figure ??, but included from a file.

                #include <iostream>
                int main(void) {
                    cout << "Hello, world!\n";
                    return 0;
                }

Figure 4: This is the code from Figure ?? again, this time boxed. This was trickier to do than I thought it would be!

                #include <iostream>
                int main(void) {
                    cout << "Hello, world!\n";
                    return 0;
                }

Figure 5: This is the code from Figure ?? yet again, included from a file and boxed. This also was trickier to do than I thought it would be!

References

[GHJV95] Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, 1995.

[MMS99] Berna L. Massingill, Timothy G. Mattson, and Beverly A. Sanders. Patterns for parallel application programs. In Proceedings of the Sixth Pattern Languages of Programs Workshop (PLoP99), 1999. See also our Web site at http://www.cise.

ufl.edu/research/ParallelPatterns.

[MMS01] Berna L. Massingill, Timothy G. Mattson, and Beverly A. Sanders. Parallel programming with a pattern language. International Journal on Software Tools for Technology Transfer, 3(2):217–234, 2001.

[MPI] MPI (Message Passing Interface) 2.0 standard. http://www.

mpi-forum.org/docs/docs.html.