Skip to main content

Section 2.1 Getting PreTeXt

For the sake of this tutorial, we will use the PreTeXt-CLI, a python-based command line interface that simplifies the installation of PreTeXt, and allows you to easily create, build (convert), and view PreTeXt documents. Other setups that provide more flexibility at the cost of complexity can be found in Chapter 5.

You have two options for running the PreTeXt-CLI: you could do everything in the cloud using CoCalc, or you could install PreTeXt on your own computer. The CoCalc route is faster and doesn't require installing Python and on your computer, but unless you pay for a subscription to CoCalc, your experience there might be limited. A local install also allows you to use a more powerful text editor that might have PreTeXt-specific support that speeds up editing.

Luckily, both processes are relatively easy to try out, so there is no reason not to attempt both of the options below.

Note: We will work at the command-line inside of a terminal or console. If you do not know what this is, it will seem very primitive at first. Sometimes the old ways are the best ways. This will be called a “Command Prompt” or “PowerShell” in Windows or a “Terminal” on a Mac. In Linux it may be known as a “console” or a “shell”. Whenever the guide says to enter something on the command line or in a terminal, or just to enter the command, this is what we are talking about.

Using CoCalc.

CoCalc has graciously already installed the PreTeXt-CLI, as well as , so there is almost no setup required.

Simply visit There you can click on the “Run CoCalc Now” button, or sign up for a free account so you can save your work. Once you are in a CoCalc project, click on the “New” tab and select the “Linux terminal” button. This will give you a command prompt where you can start typing commands.

At this point, you can skip directly to the next section of the tutorial, Section 2.2.

Local Installation.

Before you can install PreTeXt locally, make sure you have the following software on your computer, or else install it using instructions easily searched for online.

  • Python, version 3.8 or later. In a terminal, type python --version to ensure you are already set up.

  • . Try xelatex --version to see if you already have this.

  • Any text editor. Visual Studio Code is a reasonable choice (and has a pretext-tools extension available), but so are SublimeText, atom, emacs, vi, etc. See Appendix D.

Now we can install PreTeXt. Open a terminal and type the following:

pip install pretextbook

If this fails, try:

python -m pip install pretextbook

The python -m helps in case Python is on your PATH but pip is not. This is a useful fix for the rest of the commands listed for the PreTeXt-CLI.

To ensure that the CLI is installed, type pretext --version (or python -m pretext --version) and you should get back a number (0.5.1, for example).

We are now ready to move on to creating and converting a new PreTeXt document.