Skip to main content
Logo image

Chapter 7 Converting To PreTeXt

View Source
Suppose you have materials written in another format, such as MS Word or , and would like to convert these to PreTeXt. Alas, there is not a perfect way to make this happen, but what follows is some general advice to get you started. We would love to hear what sort of workflow you would like to see so we can improve this experience.

Warning 7.0.1.

Your goal in doing a conversion should be to move all your materials into PreTeXt and then always work from the PreTeXt source, converting back to other formats as needed. It is simply not feasible to keep converting to PreTeXt, since this process is not automatic.

Section 7.1 Using Pandoc

If you have a number of individual documents that you would like to convert, from pretty much any format, consider trying Pandoc
 1 
pandoc.org/
. This command-line tool can read in lots of different formats and output in lots of different formats. Unfortunately, PreTeXt is not a default output format, so you need to use a custom writer.
The pretext-tools VS Code extension has a shortcut for using the custom writer and pandoc, assuming you have pandoc installed (which you will if you use a codespace). You will need to upload the file you want to convert, either by dragging it to the Explorer menu in VS Code. Then open the Command Pallet with CTRL+SHIFT+P and start typing “pretext: convert file to pretext” and select the item to shows up. You will be prompted for the name of the file you want to convert. The file will be converted and opened in a new tab. You can then copy/paste the contents into your main documents.
You can also use Pandoc outside of VS Code. Install pandoc from their website. Then download the this writer
 2 
raw.githubusercontent.com/oscarlevin/pandoc-pretext/master/pretext.lua
and put it somewhere you will remember. Documentation for how to use this tool is available on its GitHub repository
 3 
github.com/oscarlevin/pandoc-pretext
.

Section 7.2 Using the community

If you have a mostly complete project, written entirely in not-too-customized , David Farmer has volunteered to help you convert the entire project to likely 90% correct working PreTeXt. See https://pretextbook.org/conversions.html for details.

Section 7.3 By hand

If you have some familiarity with Regex, you can use VS Code’s find/replace tools to clean up text that you copied/pasted into your document. For example, if you entered \$(.*?)\$ in the search bar (with the “.*” setting selected), and put <m>$1</m> in the replace box, you can easily replace all math in your document with the correct syntax.