Section 5.11 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 web
You can replace “web” with any target name, 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 viewto speed up authoring. First, the
-bflag will build your source before starting the server (i.e., runs
pretext buildin the background). Similarly, the
-gflag will generate assets prior to viewing. For small projects, adding the
-wflag will “watch” your source for changes and rebuild 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
-aoption, and to specify a port other than 8000 with the
pretext view --helpfor more.)
Finally, having this quick local web server might be useful for other purposes. You can use the
-doption to specify a path to any directory to serve any files, not just those created in PreTeXt.