Chapter 5 Compiling a PTX file
Now is the time for the magic to happen! You will take a sample PTX file (extension
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
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
To compile to HTML: From the folder containing
~/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:
From the folder containing
hello-world.xml, type in the same command as you used to create the HTML document, replacing the
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
From the same folder, enter the command
pdflatex hello-world.texto create a PDF from the LaTeX file.
hello-world.pdfwill 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.
To compile a file, first make sure you are in the directory in your Git Bash shell which contains the file to be compiled.
mathbookfolders are in your default directory on your local machine, you can always start off your
xsltproccompilation commands with
~/xsltproc/xsltproc --xinclude ~/mathbook/xsl/mathbook-html.xsl(for HTML),
~/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.exeand/or to the
xslfile in the command.
You can always compile your LaTeX file to PDF by typing
pdflatexand appending the name of your LaTeX file (provided you're in the directory containing your LaTeX file).
What was all that stuff in the
xsltproc compilation commands??
xsltprocexecutable, living within the
--xincludeis 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-latex.xsl) are the style files that make the PTX compile to HTML or LaTeX.
hello-world.xmlwas, of course, the name of the file you were compiling to HTML or LaTeX!