web analytics
Skip to main content

The PreTeXt Guide

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 6. Furthur documentation of the PreTeXt-CLI is available in Section 6.2.
You have two options for running the PreTeXt-CLI: you could do everything in the cloud using CoCalc 1 , 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, although the version available there might lag behind the most recent release.
Simply visit cocalc.com. 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.5 or later. In a terminal, type python --version to ensure you are already set up. On MacOS or Linux, your command for python might be called python3, so also try python3 --version.
  • . Try xelatex --version to see if you already have this.
  • Any text editor. Visual Studio Code 2  is an excelent choice (and has an extension, PreTeXt-tools 3 , with specific language support), but other editors such as SublimeText, atom, emacs, vi, etc. can also be used. See Appendix D.
Now we can install PreTeXt. Open a terminal and type the following:
pip install pretext
If this fails, try:
python -m pip install pretext
(or, if python3 worked above, do python3 -m pip install pretext.)
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 (1.0.3, for example).
We are now ready to move on to creating and converting a new PreTeXt document using the PreTeXt-CLI. For more documentation about this CLI, see Section 6.2