0

I am running into an issue in the process of generating PDFs through R/Sweave/tinytex on a CentOS server. Here is the command that runs the process:

(generateReport.R)
Sweave(rnwFile, encoding = "UTF-8", output=filename)
tools::texi2pdf(filename)

The error occurs once the .tex is being converted into a .pdf via the tools:texi2pdf command and reads as follows:

! Missing \endcsname inserted.
<to be read again>
                   \egroup
l.118 \begin
            {threeparttable}
!  ==> Fatal error occurred, no output PDF file produced!
Calls: <Anonymous> -> texi2dvi

After chopping up my code to figure out where the error occurs from, I can tell it is originating from within its huxtable. I will post the important part of the RNW file here:

\documentclass[letterpaper,12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{array}
\usepackage{lastpage}
\usepackage{multirow}
\usepackage{fancyhdr}
\usepackage{longtable}
\usepackage{array}
\usepackage{caption}
\usepackage{siunitx}
\usepackage[normalem]{ulem}
\usepackage{colortbl}
\usepackage{hhline}
\usepackage{calc}
\usepackage{tabularx}
\usepackage{threeparttable}
\usepackage{wrapfig}
\usepackage{adjustbox}
\usepackage[hmargin=1cm,top=5cm,headheight=6cm,footskip=40pt]{geometry}
<<external-code, warning=FALSE, message=FALSE, echo=FALSE>>=
options(width=60)
library(dplyr)
library(stringr)
library(mongolite)
library(huxtable)
library(knitr)
# r code for getting data here, works fine
#....................
huxTable <- as_hux(df1)
huxTable <- huxTable %>%
set_align(1, everywhere, "center") %>%
set_all_borders(brdr(0.5, "solid", "black")) %>%
set_align(-1, 1, ".") %>%
#set_colspan(1, 2, 5) %>%
set_font_size(everywhere, everywhere, 8)

@
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[C]{%
#the header is full of other fields/data, but I have confirmed it is unrelated to this issue.
}
\begin{document}
\SweaveOpts{concordance=TRUE}
<<results=tex, include=TRUE, warning=FALSE, message=FALSE, echo=FALSE>>=
print_latex(huxTable)
@
\end{document}

I have confirmed that the text inside the huxtable does not have any special characters that caused it to error out. I also ensured that the .aux and .out files generated with the failed attempts were deleted, too. I have generated other PDFs with similar dependencies, and so I am stumped with what's going on here. Any ideas?

Danchat
  • 137
  • 2
  • 12
  • You need to debug the TeX file. The TeX stackexchange community might help. If you create the huxtable on the R command line and run `quick_pdf(huxTable)`, do you get an error? Have you pasted the full result of `report_latex_dependencies()` into your header? Dependencies change over time so if you've updated huxtable, you may need to recheck this. – dash2 Sep 11 '21 at 12:44
  • I reached out to the Tex part of Stack Exchange, but I've heard nothing. I ran quick_pdf and got the exact same error with \endcsname. I can confirm the entire latex dependencies output is in the header of the file, as you can see on the .tex file. I can also confirm that I downloaded the latest version of huxtable. – Danchat Sep 13 '21 at 19:54
  • I tried using 'huxtable::install_latex_dependencies()', and that got me past the \endcsname error. Now I am running into '! LaTeX Error: File `threeparttable.sty' not found.', despite the fact that threeparttable has been installed already. – Danchat Sep 13 '21 at 21:52
  • sounds like an issue with your TeX installation :-/ – dash2 Sep 14 '21 at 22:03
  • I tried following some instructions here https://stackoverflow.com/questions/52090721/latex-error-environment-threeparttable-undefined , which led to me installing "kableExtra", which got rid of the 'threeparttable.sty' not found error, but then replaced it with ! LaTeX Error: File `\strut ' not found. I've been following some other suggestions on that issue but I've come up dry. – Danchat Oct 08 '21 at 15:49

0 Answers0