Skip to main content

Chapter 14 Lists

Lists are important in lots of contexts, and the desire to nest lists has led to some very, very complex discussions on the PreTeXt email lists. We'll keep it simple here. There are a variety of places that lists can live, but a good mental model is that a list must be put inside an element that's similar to <p>. So for example, you can't put your list directly inside a <subsection>, but instead must wrap the list in a <p>.

There are two common types of lists: ordered and unordered. (There's also the description list. See the Author's Guide at Section 4.10 for more information on it.) As in HTML, an ordered list is produced with <ol> and an unordered list with <ul>. The items of your list are structured inside <li> tags. The example in Listing 14.0.1 shows that these <li> tags can contain a paragraph in a <p> tag but you do not need to. If you're just putting a sentence or two inside your <li>, no <p> is required. However, if you also want to put an image or more complicated items inside the <li>, then the <li> must be structured with <p> by placing “loose” text inside one or more <p>.

<p>
  <ol>
    <li>First item.</li>

    <li>
      <p>
        Second item,
        showing can wrap content with <c>p</c>.
      </p>
    </li>
  </ol>
</p>
Listing 14.0.1. An ordered list

The code in Listing 14.0.1 produces the following output:

  1. First item.

  2. Second item, showing can wrap content with p.

You can use the @label attribute 1  on the <ol> tag to change the default labeling. For instance, if the opening tag for the list above were <ol label="A">, then the list items would be labeled as A. and B. Sensible things to use with @label are i, I, A, a, and 1. Nesting of lists is possible, and there are sensible default labels.

As illustrated here, an attribute is something that appears between the < and > of the opening tag. The convention in XML usage is to prefix an attribute name with @ when referring to the attribute outside of the tag. You do not use the @ in the tag itself.
<p>
  <ul>
    <li>First item.</li>

    <li>Another item.</li>
  </ul>
</p>
Listing 14.0.2. An unordered list

The code in Listing 14.0.2 produces the following output:

  • First item.

  • Another item.

You can also use the @cols attribute to split a list (ordered or unordered) across multiple columns if the screen/page is suitably wide. The value of this attribute must be an integer between 2 and 6 (inclusive).