
# Chapter5Compiling a PTX file

Now is the time for the magic to happen! You will take a sample PTX file (extension ptx or xml) and use it to create an HTML document and a PDF. (Note: XML is a deprecated file type; when you create PTX documents, your extension should be ptx.)

First, navigate in your Git Bash shell to the folder containing the PTX or XML file you plan to work with. For our example, navigate to ~/mathbook/examples/hello-world, which contains the XML file hello-world.xml.

To compile to HTML: From the folder containing hello-world.xml, type

~/xsltproc/xsltproc --xinclude ~/mathbook/xsl/mathbook-html.xsl hello-world.xml.

This will compile the XML file into an HTML file, hello-world.html, in the same folder as hello-world.xml. You can open it by navigating to the folder via the Windows desktop and opening it the way you'd open any HTML document on your machine.

To compile to PDF:

1. From the folder containing hello-world.xml, type in the same command as you used to create the HTML document, replacing the mathbook-html.xsl with mathbook-latex.xsl; that is, enter

~/xsltproc/xsltproc --xinclude ~/mathbook/xsl/mathbook-latex.xsl hello-world.xml.

This will compile the XML file into a LaTeX file, hello-world.tex, in the same folder as hello-world.xml.

2. From the same folder, enter the command pdflatex hello-world.tex to create a PDF from the LaTeX file. hello-world.pdf will appear in the folder. You can open it by navigating to the folder via the Windows desktop and opening it the way you'd open any PDF document on your machine.

You can generalize from this to compile any PTX (XML) file to HTML or PDF.

###### Note5.0.1

• To compile a file, first make sure you are in the directory in your Git Bash shell which contains the file to be compiled.

• If your xsltproc and mathbook folders are in your default directory on your local machine, you can always start off your xsltproc compilation commands with

~/xsltproc/xsltproc --xinclude ~/mathbook/xsl/mathbook-html.xsl (for HTML),

or

~/xsltproc/xsltproc --xinclude ~/mathbook/xsl/mathbook-html.xsl (for LaTeX),

and simply append the name of your PTX (XML) file. If you have installed or moved one or both of these directories elsewhere, you will need to change the path(s) to xsltproc.exe and/or to the xsl file in the command.

• You can always compile your LaTeX file to PDF by typing pdflatex and appending the name of your LaTeX file (provided you're in the directory containing your LaTeX file).

###### Remark5.0.2

What was all that stuff in the xsltproc compilation commands??

• ~/xsltproc/xsltproc ran the xsltproc executable, living within the xsltproc folder.

• --xinclude is an optional command that is required if you include modular PTX files in your main PTX file; don't worry about what that means for now. Suffice to say that you can always include that optional command without running into problems, so why not include it by default?

• ~/mathbook/xsl/mathbook-html.xsl and ~/mathbook/xsl/mathbook-latex.xsl) are the style files that make the PTX compile to HTML or LaTeX.

• Finally, hello-world.xml was, of course, the name of the file you were compiling to HTML or LaTeX!