Using LaTeX Equations in Github Pages

1 minute read

While there are a variety of workarounds for using LaTeX in Github pages, particularly related to mathematical equations, I find the following to be the easiest approach.

Step 1. Open RStudio and create an RMarkdown file. If you’re not familiar with RMarkdown, check out the RMarkdown Cookbook at https://bookdown.org/yihui/rmarkdown-cookbook/. This also contains good information about using LaTeX in RMarkdown.

Step 2. Write your document using standard markdown syntax and LaTeX math!. Unlike a Markdown file, RMarkdown can also compile quite a bit of LaTeX, most notably mathematical equations. I haven’t tried to do anything too bizarre, but it seems to work well with everything I’ve wanted to do in math mode.

Step 3. Compile to HTML. This will save your work as an HTML document.

Step 4. Upload your HTML document to Github.

Step 5. Open the HTML file in an editor (not in a browser or in RStudio) and add your Github pages header information to the top of the file. If you don’t have a way to edit HTML files on your local machine, upload your file to Github and edit it directly on the Github website. I add my header as markdown, which necessitates changing the file extension to .md (markdown can handle html, so this works ok). If you change the file type to markdown, make sure to delete <!DOCTYPE html> from the top of the file. You may also want to remove the title and header information from the RMarkdown file.

Step 6. Save and push any necessary changes. Et voila!