web analytics
Skip to main content

The PreTeXt Guide

Section 2.3 Extending the Minimal Example

We will not keep reproducing the entire example but instead suggest a series of modifications. After each edit, convert the file again (pretext build web) to make sure your syntax is correct (before you get too far along) and to see the changes (pretext view web). Since this is a pretty small document, you could also use the following trick: run pretext view -w web, which will build the source, start the local server, and then rebuild whenever you save a sorce file.
The generic name of the resulting files is pretty bland, and it would be nice to have a title for our article. We will add an attribute to the <article> tag, specifically @xml:id, which is a very important part of PreTeXt and used frequently. For now, it will be used to generate the names of the output files. (The “at” symbol is a way of reminding you that it is an attribute, it is not part of what you author.)
So make the following modifications:
<article xml:id="hello">
  <title>Hello World!</title>
  <p>This is a PreTeXt document.</p>
</article>
Your outputs should now have a title, and more importantly, the HTML filename will be hello.html.
Let us give our article a bit of structure. We will have an introduction and two sections with their own titles. So replace the one-sentence paragraph by the following, all following the article title and contained within the <article> tags.
<introduction>
  <p>
    Let's get started.
  </p>
</introduction>

<section xml:id="section-short">
  <title>Beginnings</title>

  <p>
    This is a short sentence.
  </p>
</section>

<section xml:id="section-multiple-paragraph">
  <title>Endings</title>

  <p>
    This is a longer sentence that is followed by another sentence.
    Two sentences, and a second paragraph to follow.
  </p>

  <p>
    One more short paragraph.
  </p>
</section>
The /PDF output will be a bit odd looking since every paragraph is so short, but all the content should be there. Notice that the HTML output now has a table of contents to the left and active navigation buttons. Also the two sections are in their own files and the URLs have been constructed from the supplied values of the @xml:id attribute.
One last experiment—let's add some mathematics. We use XML tags, <m> for “inline” mathematics and <me> for a “math equation” which will be rendered with a bit of vertical separation and centered from left to right. We use syntax for mathematics, which has been the standard for working mathematicians for decades. For electronic presentation, we rely on the excellent MathJax 1  project which basically supports all the syntax of the amsmath 2  package from the American Mathematical Society. Add the following sentence to any of the paragraphs of your article (inside on of the <p> tags).
If the two sides of a right triangle have lengths
<m>a</m> and <m>b</m> and the hypotenuse has length
<m>c</m>, then the equation <me>a^2 + b^2 = c^2</me>
will always hold.
So your final source file might look like the following.
<pretext>
  <article xml:id="hello">
    <title>Hello World</title>

    <introduction>
      <p>
        Let's get started.
      </p>
    </introduction>

    <section xml:id="section-short">
        <title>Beginnings</title>

        <p>
          This is a short sentence.
        </p>
    </section>

    <section xml:id="section-multiple-paragraph">
        <title>Endings</title>

        <p>
          This is a longer sentence that is followed
          by another sentence. Two sentences, and a
          second paragraph to follow.
        </p>

        <p>
          One more short paragraph.  If the two sides of a
          right triangle have lengths <m>a</m> and <m>b</m>
          and the hypotenuse has length <m>c</m>, then the
          equation <me>a^2 + b^2 = c^2</me> will always hold.
        </p>
    </section>
  </article>
</pretext>
You now have many of the basic skills you would need to write an entire research article in mathematics, and should be in a position to learn the remainder easily and quickly. Poke around the book-example we created earlier to see how to include modular files, as well as some of the other blocks (examples, theorems, figures) you can include. These constructions are detailed in the next few chapters. For a quick introduction to what is available, also see the Basics Reference.
www.mathjax.org/
www.ctan.org/pkg/amsmath?lang=en