"Knit to PDF" results with error message

I wanted to generate a PDF-file out of a ".Rmd"-file. I clicked "Knit to PDF". The rendering started and finished. At the end, I read the following red message:

Error: LaTeX failed to compile regression.tex. See The R package tinytex - Helper Functions to Manage TinyTeX, and Compile LaTeX Documents - Yihui Xie | 谢益辉 for debugging tips. See regression.log for more info.
In addition: There were 18 warnings (use warnings() to see them)
Execution halted

The log file has this part at the end:

! Undefined control sequence.
l.864 ...me, et see seos on järgmine: (R=k\cdotI
^{n}).
Here is how much of TeX's memory you used:
12962 strings out of 480313
204473 string characters out of 5897214
505208 words of memory out of 5000000
30544 multiletter control sequences out of 15000+600000
451032 words of font info for 69 fonts, out of 8000000 for 9000
14 hyphenation exceptions out of 8191
60i,9n,63p,689b,469s stack positions out of 5000i,500n,10000p,200000b,80000s

! ==> Fatal error occurred, no output PDF file produced!

The corresponding line isn't actually 864 but 217 in my ".Rmd"-file and contains the following code:

Pooljuhi takistus on läbi pooljuhi mineva voolu tugevuse funktsioon *R=f(I)*. Eeldame, et see seos on järgmine: $R=k\cdotI^{n}$. Joonistada graafik, logaritmiline graafik. Leida konstandid *k* ja *n*.

This is the first appearance of LaTex-code in that file at all.

How to solve?

The error line is relative to the intermediate tex file, not the rmd file. Use this post to output to tex and examine with a text editor.

Why the error is being thrown is impossible to guess without a reproducible example. See the FAQ: How to do a minimal reproducible example reprex for beginners.

The same snippet on the line 217 in my ".Rmd"-file is really on the line 864 in the corresponding ".tex"-file:


Pooljuhi takistus on läbi pooljuhi mineva voolu tugevuse funktsioon
\emph{R=f(I)}. Eeldame, et see seos on järgmine: \(R=k\cdotI^{n}\).
Joonistada graafik, logaritmiline graafik. Leida konstandid \emph{k} ja
\emph{n}.

I have no glue what's wrong.

In order to test it, you can create a ".Rmd"-file, enter these rows to the beginning of the file:

---
title: "Regression"
author: 'peacecop kalmer:'
date: "11/9/2021"
output:
  pdf_document:
    toc: yes
  html_document:
    toc: yes
    toc_float: yes
bibliography: references.bib
---

```{r setup, include=FALSE}
options(tinytex.verbose = TRUE)
knitr::opts_chunk$set(echo = TRUE)

and then add the snippet from my first post. And then, you click "Knit" -> "Knit to PDF".

HTML-knitting works just fine, PDF-knitting causes this trouble.

I wonder if you should be treating *(R=k\cdotI^{n}* as an in line equation? And probably \emph{R=f(I)} as well?

Try

Pooljuhi takistus on läbi pooljuhi mineva voolu tugevuse funktsioon
$R=f(I)$. Eeldame, et see seos on järgmine: ($R=k\cdot I^{n}$).
Joonistada graafik, logaritmiline graafik. Leida konstandid \emph{k} ja \emph{n}.

So you did three changes:

  1. instead of telling that the first formula should be italic, you turned it into a formula which changed nothing,
  2. you added parenthesis to the second formula which changed nothing instead of just displaying these unnecessary parenthesis in addition to the formula itself,
  3. you put TEX-syntax for the last two variables instead of letting them be italic which rendered them invisible.

I've solved the particular issue considering the mentioned row by adding a space between \cdot and I. Otherwise, even HTML version didn't display the dot but colored \cdotI red.

1 Like

Glad to have been able to help.

1 Like

You haven't. I helped myself. None of advices here helped me to solve the issue. After a while, I just wanted to see how that part looked like in the website. That made me quess that there must be a space between LaTex command and something else. Maybe also braces can be used.

This topic was automatically closed 7 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.