knit to pdf failing with display math equations in align environment

The following reprex demonstrates the issue; I can knit this to word or html, but not pdf.

---
title: "test-displaymath"
author: "Drew Tyre"
date: "7/21/2021"
output:
  word_document: default
  html_document: default
  pdf_document: default
---

$$
\begin{align*}
y &= mx+b+\epsilon \\
\epsilon &\sim N(0, sigma)
\end{align*}
$$

The latex error is

! Package amsmath Error: Erroneous nesting of equation structures;
(amsmath)                trying to recover with `aligned'.

If I remove the \begin{align*} and \end{align*}, it knits to pdf (but not aligned), but then won't knit to html or word.

I'm using Version 1.4.1106 of RStudio and

R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] compiler_4.1.0    htmltools_0.5.1.1 tools_4.1.0       yaml_2.2.1       
 [5] rmarkdown_2.9     knitr_1.33        xfun_0.23         digest_0.6.27    
 [9] rlang_0.4.11      evaluate_0.14   

And from the log file I am using:

This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/W32TeX) (preloaded format=pdflatex 2020.8.3)  21 JUL 2021 12:47

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.