I am getting error while document is getting converted from .md to .pdf

I have this code which is running well in console.

BUt while running in R markdown and at time of conversion it gives error as below because of the line below:

print(knitr::kable(Total_Demand_Monthly_Per_Table,"simple", align=c("c"), booktabs=TRUE, digit=1, caption="Monthly Percentage of Total Demand"))
cat("\\newpage")

! Undefined control sequence.
l.571 \newp
& age{[}{]}(C & orn_Dema &

Error: LaTeX failed to compile Corn_Demand_Monitor.tex. See The R package tinytex - Helper Functions to Manage TinyTeX, and Compile LaTeX Documents - Yihui Xie | 谢益辉 for debugging tips. See Corn_Demand_Monitor.log for more info.
Execution halted

To create PDF reports with R Markdown, you need to install the LaTeX environment.

https://www.tug.org/texlive/

Find out how to create a running environment in your country's language.

The error above you get is during LaTeX compilation. So it should already been installed.

No need to install a new one. (if you do want to, then follow 1.2 Install LaTeX (TinyTeX) for PDF reports | R Markdown Cookbook)

This means that there is a character somewhere in your .tex document that is not expected.
You can have a look at this by looking at the .log file and .tex file you may have (set keep_tex: true is the output format definition)

I suspect Total_Demand_Monthly_Per_Table may contain special characters that you may need to escape for LaTeX - see 10.1 The function knitr::kable() | R Markdown Cookbook

Without a reproducible, or access to the document, we can't really say more about this. You need to dig into the log file and your document.

If you can provide more information, we may be able to help more.

1 Like

Thanks for our detailed reply.

Interesting thing is above code, if i run without for loop, 10 times in 10 different chunk, its working in Markdown.

But if i work in one chunk in for loop its giving an issue.

I will try few things suggested by you.

Thanks

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.