5  Converting existing LaTeX Notes

Fortunately, a large proportion of LaTeX mathematics can be copied directly into Quarto documents without modification.

For example:

\[
F = ma
\]

and

\begin{equation}
E = mc^2
\end{equation}

typically work immediately.

5.2 Automatically converting LaTeX

Pandoc can convert between lots of different formats including LaTeX (.tex) and Quarto (.qmd). It won’t do a perfect job and which is why it’s recommended to carefully go through your TeX source. However if your TeX is relatively clean (few macros, extra packages, complex float layouts), then Pandoc can get you going quite quickly.

From the command line you can run

pandoc -f latex -t markdown input-tex.tex -o output-md.qmd
Important

You will need to review the output .qmd to make sure you have output that is compatible.

Caution

Pandoc is not aware of your whole TeX project: you need to convert each .TeX separarely.

5.3 Tidying up the .qmd file

Here are some things Pandoc does not readily convert into markdown:

  • Section etc labels - if you used underscores in any of your latex labels you should change these to ‘-’ in the markdown file. The underscores confuse markdown. Chapter 9 discusses sections, chapters, etc.
  • Figures - the default pandoc conversion is quite limited, so here we’ll use a more adaptable figure environment. In practice its easiest to just copy-paste the example code in Chapter 6.
  • Equations - most equations convert fine but if you want to have equation numbers and labels you’ll need to do some tidying. See Chapter 7 for the syntax.
  • Tables - tables have a different format but it’s pretty easy to convert a latex table using find/replace or online table editors/converters (e.g. Table Convert) References - generally easy to fix - see Chapter 10

This list is based on the Making Lecture Notes with Bookdown guide by Vicky Scowcroft

Tip

If you’re from a LaTeX background and are editing/writing a Quarto document, you may sometimes forget to add blank lines between markdown commands (as with LaTeX you could just close brackets and define the next command). Some typical mistakes a LaTeX user makes in markdown:

  • you have a figure and then a paragraph of text, you must add a blank line between the figure and the paragraph. Otherwise the paragraph will be treated as part of the figure caption.
  • you start a list without a blank line, the list will be treated as part of the previous paragraph (and not start the list environment).

Simple tip Always add a blank line between different elements in your Quarto document. This will help avoid formatting issues!