Search code examples
r-exams

exams2pdf latex error !Missing $ inserted


I am puzzled with this error when compiling an exercise with exams2pdf():

Exam 1: ICvar (srt) ... w! Missing $ inserted.
<inserted text> 
                $
l.7 ...rime 2}}{\chi^2_{1-\frac{\alpha}{2};(n-1)}}
                                                  ;\frac{(n-1)S^{\prime 2}}{...

Error: LaTeX failed to compile icvar1.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See icvar1.log for more info.

This is the code from my ICvar.Rmd (I get the variables' values from previous code in the ICvar.rmd file link here if you want to see the whole file):

Solution
========
Para $n$ = `r length(v)` um I.C. a `r cilevel*100`% para a $\sigma^2$ é:

$$\bigg] \frac{(n-1)S^{\prime 2}}{\chi^2_{1-\frac{\alpha}{2};(n-1)}};\frac{(n-1)S^{\prime 2}}{\chi^2_{\frac{\alpha}{2};(n-1)}}\bigg[$$

I am generating the latex file with:

exams2pdf(file="ICvar.Rmd",
          name = "icvar",
          engine="knitr",
          verbose=T
          )

And my latex (exercise01) file is:

\begin{question}
\textbf{Um intervalo de confiança a 99\% para variabilidade é:}
\begin{answerlist}
  \item {]}1599.909; 24699.887{[}{]}1225.75; 49863.356{[}{]}24.685;
235.649{[}{]}33.179; 227.154{[}{]}129.822; 130.511{[}{]}
\frac{(n-1)S^{\prime 2}}{\chi^2_{1-\frac{\alpha}{2};(n-1)}};\frac{(n-1)S^{\prime 2}}{\chi^2_{\frac{\alpha}{2};(n-1)}}\bigg[$$

Assim:

$\bigg]\frac{(6-1) \times 64.079^2}{\chi_{1- \frac{0.01}{2};(6-1)}^2};\frac{(6-1) \times 64.079^2}{\chi_{\frac{0.01}{2};(6-1)}^2}
\bigg[ \iff$

$\bigg]\frac{5 \times 4106.118}{\chi_{1- 0.005;(5)}^2};\frac{5 \times 4106.118}{\chi_{0.005;(5)}^2}\bigg[ \iff$

$\bigg]\frac{5 \times 4106.118}{\chi_{0.995;(5)}^2};\frac{5 \times 4106.118}{\chi_{0.005;(5)}^2}\bigg[ \iff$

$\bigg]\frac{5 \times 4106.118}{16.75};\frac{5 \times 4106.118}{0.412}\bigg[ \iff$

$\bigg] 1225.736;49862.768\bigg{[}\$
\end{answerlist}
\end{question}

The \end{answerlist} is missing after the anwserlist, and no `\begin{solution} is present, and this causes the error, I believe. But can't figure out why tinytex is rendering the file as it is.

I am using:

R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22000)
other attached packages:
[1] tinytex_0.33 dplyr_1.0.7  exams_2.4-0 

Any thoughts will be appreciated... (by the way, the same file "knits" well within R studio and... exams2pdf() produces the pdf in Ubuntu 20).


Solution

  • The solution:

    1. Unistall R 4.1
    2. Unistall RStudio
    3. Restart PC
    4. Install R and Rstudio

    And now it works...:-(