0

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).

JPMD
  • 644
  • 1
  • 7
  • 19
  • I agree that the LaTeX file looks wrong, the `{question}` and `{solution}` seem to have been mixed up. However, I cannot replicate this. When I do `set.seed(1)` and `exams2pdf("ICvar.Rmd", texdir = "tmptex")` then the resulting file `tmptex/exercise1.tex` looks ok and not like the code you posted. Maybe something was edited by hand along the way? – Achim Zeileis Sep 06 '21 at 14:13
  • Hi Achim. Thanks for the prompt answer. No, no editing ... and it works ok on a ubuntu server... Are you running a Win machine? – JPMD Sep 06 '21 at 14:53
  • I'm on Debian. But at least it would not be obvious to me how the operating system could lead to the output above. – Achim Zeileis Sep 06 '21 at 20:15

1 Answers1

1

The solution:

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

And now it works...:-(

JPMD
  • 644
  • 1
  • 7
  • 19
  • Thanks for the follow-up! This solution suggests that there was something that corrupted the package, the output file, the output directory, etc. It is unlikely that this problem is reproducible for anyone - and the solution is not specific to the problem. Hence I would say: (a) Good that the problem is resolved on your end! (b) The question/answer can probably be deleted/hidden. – Achim Zeileis Sep 06 '21 at 20:18
  • It would be great if we could close this question in some way. I would argue in favor of deleting it. But if you feel that your question and solution would be useful to someone else, please accept your own answer. _(Not sure whether you can already do so. Maybe you have to wait a couple of days more.)_ – Achim Zeileis Sep 10 '21 at 18:00