Skip to main content
\( \newcommand{\lt}{<} \newcommand{\gt}{>} \newcommand{\amp}{&} \)

Section 4.9 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. The one prerequisite is that you have Python installed, as is normally the case on any Linux or Mac computer. On Windows, you may need to install Python yourself, but you may eventually need it for the mbx script anyway (Chapter 8). The following has been tested on Ubuntu Linux 16.10 and MacOS 10.12 (2017-08-06).

Python 2 and Python 3 are different in some regards, and that is the case here. Your system may have commands python2, python3, and/or plain python. Experiment with variants of the following two commands. First, at a command-line, set your working directory to be the location of a directory containing the HTML files you want to test.

python3 -m http.server

python2 -m SimpleHTTPServer 

Use --help if you want to see the (limited) options for configuration. Then go to the address bar of your browser and use

to actually view the files from a web server. Running the Python command should tell you which address to use (the and your project might not have an index.html file, so adjust accordingly.

Official documentation: Python 3 and Python 2.

You may also be able to configure your hosts file so that this webserver looks like it lives somewhere else. Clues at