Chapter 2 Converting from LaTeX notes
2.1 Converting tex files
If you already have LaTeX versions of your notes you can convert these to markdown using pandoc Pandoc won’t create perfect versions of your notes - you’ll most likely have to do a bit of tweaking, but it gets most of the way there.
You can convert a tex file to Rmd via the command
pandoc -f latex -t markdown input-tex.tex -o output-md.Rmd
where input-tex.tex
is the name of your tex file and output-md.Rmd
is the name of your output Rmd file.
Pandoc converts one tex file at a time. It doesn’t understand how to process a “master” tex file with input
or insert
LaTeX commands. Each file will need to be processed separately.
2.3 Tidying up the Rmd file
Pandoc will have done most of the work in getting your tex file converted to markdown. However, depending on how complex the original file was, you may end up with some tidying to do.
Things that typically will need fixing are:
- 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. Section 4 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 5 and edit the relavent bits.
- Equations - the equations themselves should be fine, but if you want to have equation numbers you’ll need to do some tidying. See Chapter 6 for the syntax.
- Tables - tables have a different format but it’s pretty easy to convert a latex table using find/replace. See Chapter 7.
- References - generally easy to fix. See Chapter 8.
2.4 Notes with gaps
Think carefully about whether you want to provide notes with gaps. While they may serve a purpose when the students have a hard-copy of the notes in a live lecture, they will most likely be using your notes on a screen this year.
It is possible to create notes with gaps for things like equations etc for the students to fill in. To do this you need to add some extra code to the index.Rmd
file:
```
{r setup, include=FALSE}
library(knitr)
knit_engines$set(asis = function(options) {
if (options$echo && options$eval) knit_child(text = options$code)
})
```
Then to “hide” e.g. an equation but still keep the same numbering, edit your equation to the following format:
\begin{equation}
```{asis, echo=FALSE}
\Delta s^2 = \Delta x_{1}^{2} + \Delta x_{2}^{2}
```
(\#eq:dist01)
\end{equation}
Here the asis
command and back-ticks wrap around only the equation itself, rather than the whole equation
object. If you wrap the asis
around the \begin{equation}
and \end{equation}
the equation numbering will disappear too.
Note: Sloan has a nicer way to do this - need to add his stuff to this guide.
2.5 Using the titlesec
package
If you’re using the titlesec
latex package you’ll need to add an additional line to the yaml information on your index.Rmd file:
This should fix any compilation errors related to the titlesec
package when you’re producing a pdf output.
Source: Stack Overflow