Chapter 7 Converting To PreTeXt
Suppose you have materials written in another format, such as MS Word or LaTeX, 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.
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
Pandocpandoc.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
writerraw.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 repositorygithub.com/oscarlevin/pandoc-pretext
.
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.