Skip to main content

Section 5.12 Testing HTML Output Locally

Certain complicated parts of HTML output will not always function when you look at PreTeXt output by just opening files in your web browser. These include knowls, Sage cells, and YouTube videos. This is a consequence of security policies and so will vary from browser to browser. A solution is to run a web server on your own machine, which is much easier than it sounds.

In fact, this is exactly what the PreTeXt-CLI does when you type the following command.

pretext view html

You can replace “html” with any build target, although it is really HTML builds that benefit from this feature. The CLI uses Python to spin up a local web server so you can see a copy of your output by going to the URL the CLI gives as output (usually http://localhost:8000, although if you are working in CoCalc, this will be different).

There are two useful options that can be used with pretext view to speed up authoring. First, the -b flag will convert your source before starting the server (i.e., runs pretext build in the background). Second, for small projects, adding the -w flag with “watch” your source for changes and rebuilds the HTML output whenever the source changes (this also builds the source before starting the server).

It is also possible to specify whether your server is public or private (on your local network) with the -a option, and to specify a port other than 8000 with the -p option. (Run pretext view --help for more.)

Finally, having this quick local web server is so useful that you can use the -d option to specify a path to any directory to serve any files, not just those created in PreTeXt.