Home Comments Thread

108 Replies

Page 2 / 2
Raylc Raylc 2024-05-09 20:57:04

Dear Yihui and cderv,

I recently encountered the following error message when I tried to knit my old rmd file, which worked perfectly two months ago. The mistake will disappear if I switch the latex engine from pdflatex to xelatex or lualatex. However, for the last two engines, all my latex customizations do not work. I tried everything mentioned on this page.

! Undefined control sequence.
l.71 \NewDocumentCommand
\citeproctext{}{}

Here is my original yaml code

title: "xx"
author: xx
abstract:
#|

```{=latex}

xx.

```

date: "r Sys.Date()"
fontsize: 11pt
output:
bookdown::pdf_document2
header-includes:

  • \usepackage{textcomp}
  • \usepackage{utopia}
  • \usepackage{lineno}
  • \linenumbers
  • \usepackage{float}
  • \floatplacement{figure}{H}
  • \usepackage{caption}
  • \captionsetup[figure]{font=scriptsize}
  • \captionsetup[table]{font=scriptsize}
    linestretch: 1.5
    link-citations: yes
    linkcolor: blue
    bibliography: bibliography.bib
    csl: apa.csl

Thank you in advance!

cderv cderv 2024-05-13 13:46:12

You did not format the Rmd content correctly, so hard to know if you set it correctly.

This error mentions NewDocumentCommand does not seem to be defined. So I would check your latex version to be sure you are using a recent that has this command. It should be inside LaTeX and not in a package.

This is used by pandoc to create a citeproctext command when CSL is used with Pandoc's citeproc.

Raylc Raylc 2024-05-13 14:20:51

Christophe thanks for your reply! I just uninstalled my TeXLive and installed MikTeX, and it works perfectly this time. This yaml code chunk worked pretty well several weeks ago, but it stopped working since I updated RStudio, making me suspect that it is the fault of RStudio update.

suaw-hlu suaw-hlu 2024-05-22 13:42:01

I get following error after my code have usually been working:
! LaTeX Error: File `tabu.sty' not found.

! Emergency stop.
<read *>
I have done everything listed above with no luck

cderv cderv 2024-05-22 16:00:39

! LaTeX Error: File `tabu.sty' not found.

You are just missing the tabu CTAN package; If you install it, this should work. We can't say why it was not installed automatically. It shoud if you are using TinyTeX and tinytex R package with R Markdown.

I have done everything listed above with no luck

You can also search online for such error. Those are not TinyTeX specific. They are LaTeX errors. You should be able to find help online easily

mbrandt00 mbrandt00 2024-05-24 04:52:35

Hi Yihui and cderv,
Thanks for all your work on this package, really appreciate your hard work. I am trying to use this package in an aws lambda. When I knit with the rmarkdown::render function, I get:

! I can't write on file FileName.log
(Press Enter to retry, or Control-D to exit; default file extension is `.log')
Please type another transcript file nameERROR [2024-05-24 04:45:54] LaTeX failed to compile /tmp/Daily_Roster_Pitching_Log_and_Payroll_2024-05-24.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips.

Thank you in advance

cderv cderv 2024-05-24 08:15:07

You need write access for the LaTeX compilation to work. It seems everything happens in /tmp but maybe some environment are configured for Log file to be written elsewhere. This seems environment specific, and I don't know about aws lambda. Sorry

mbrandt00 mbrandt00 2024-05-24 15:40:33

Thanks for the reply. Knitting to an HTML file worked inside the lambda environment, so it must be a problem with lambda accessing the necessary pdflatex binaries.

cderv cderv 2024-05-24 21:30:07

TeX Live and LaTeX could do some processing in different places, also if lambda tweaked some options. R Markdown does not control much the LaTeX processing, but usually it applies in same place as the Rmd to Latex conversion. So not sure where to look

skinsella skinsella 2024-07-03 12:10:38

Hi thanks for all your work on this package. I am compiling and it won't work for some reason, error is

! Undefined control sequence.
@{} >{\raggedright \arraybackslash
}p{(\columnwidth - 6\tabcolsep...
l.866 ...width - 6\tabcolsep) * \real{0.1944}}@{}}

When I go to l.866, there does not seem to be anything wrong.

cderv cderv 2024-07-03 12:50:36

Without any example of what you tried to render this is very hard to help.

This is a LaTeX issue meaning somehow the .tex file contains some error. You need to look into it, or in what is creating this code in the .Rmd or .qmd file.

Possibly, this is missing a CTAN package which brings a command you don't have.

So this all depend on

  • Which content is creating this command ?
  • What is creating the tex file ?
  • And more.

There is no context to your question so this is really some guesses from us...

skinsella skinsella 2024-07-03 15:33:31

Sorry!

I'm using this .tex file: https://github.com/svmiller/svm-r-markdown-templates/blob/master/svm-latex-cv.tex

Here is the YAML header:


title: "Curriculum Vitae"
author: "Stephen Kinsella"
email: stephen.kinsella@ul.ie
output:
word_document: default
html_document: default
pdf_document:
latex_engine: pdflatex
template: ~/Dropbox/SKCV/svm-latex-cv.tex
fontsize: 10pt
geometry: margin=0.75in
jobtitle: Full Professor of Economics
keywords: Stephen Kinsella, long academic CV
linkcolor: blue
fontawesome: yes
address: Department of Economics, Kemmy Business School, University of Limerick
updated: yes
urlcolor: blue
web: stephenkinsella.net
github: skinsella
editor_options:
markdown:
wrap: 72


pagebreak <- function() {
  if(knitr::is_latex_output())
    return("\newpage")
  else
    return('<div style="page-break-before: always;" />')
}
skinsella skinsella 2024-07-04 06:26:55

Hi, I've figured this out thanks to your prompt to go look at the .tex file. It was deprecated. I redid the yaml based on the author's updated .tex and we're off. Thanks!

sally982 sally982 2024-08-05 11:36:06

this is my r shiny's application :

library(shiny)
library(DT)
library(rmarkdown)
library(dplyr)

Données d'exemple

data <- data.frame(
Nom = c("Alice", "Bob", "Charlie", "David"),
Age = c(24, 30, 35, 40),
Ville = c("Paris", "Lyon", "Marseille", "Nice")
)

UI

ui <- fluidPage(
titlePanel("Télécharger un tableau filtré en PDF"),

sidebarLayout(
sidebarPanel(
selectInput("ville", "Sélectionnez une ville :", choices = unique(data$Ville), selected = unique(data$Ville)[1]),
sliderInput("age", "Sélectionnez un âge :", min = min(data$Age), max = max(data$Age), value = c(min(data$Age), max(data$Age))),
downloadButton("download_pdf", "Télécharger PDF")
),

mainPanel(
  DTOutput("table")
)

)
)

Server

server <- function(input, output) {

Filtrer les données en fonction de la ville et de l'âge sélectionnés

filtered_data <- reactive({
data %>% filter(Ville == input$ville, Age >= input$age[1], Age <= input$age[2])
})

Rendu du tableau interactif

output$table <- renderDT({
datatable(filtered_data())
})

Télécharger le PDF

output$download_pdf <- downloadHandler(
filename = function() {
paste("rapport-filtre-", Sys.Date(), ".pdf", sep = "")
},
content = function(file) {
# Rendre le rapport RMarkdown en PDF avec toutes les villes filtrées par l'âge
params <- list(data = data, age = input$age)
rmarkdown::render("C:/Users/s.rhazi/Downloads/report.Rmd", output_file = file, params = params, envir = new.env(parent = globalenv()))
}
)
}

Lancer l'application

shinyApp(ui = ui, server = server)

and this is the r markdown part :


title: "Rapport de données filtrées"
output:
pdf_document:
keep_tex: true
header-includes:

  • \usepackage{booktabs}
    params:
    data: NULL
    age: NULL

knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE, results = 'asis')
library(dplyr)
library(knitr)
library(kableExtra)

# Filtrer les données selon l'âge
filtered_data <- params$data %>% filter(Age >= params$age[1], Age <= params$age[2])

# Générer les tableaux pour chaque ville
for(ville in unique(filtered_data$Ville)) {
  ville_data <- filtered_data %>% filter(Ville == ville)
 
  if(nrow(ville_data) > 0) {
    cat("\\section*{", ville, "}\n\n")
   
    # Générer le tableau sans détails supplémentaires
    ville_data %>%
      kable("latex", caption = "Tableau des données") %>%
      kable_styling(position = "center", full_width = FALSE) %>%
      row_spec(0, bold = TRUE, background = "gray") %>%
      row_spec(1:nrow(ville_data), background = "lightgray") %>%
      print()
   
    cat("\n\n")
  } else {
    cat("\\section*{", ville, "}\n\n")
    cat("Aucune donnée disponible pour cette ville.\n\n")
  }
}

and they keep giving me errors , I installed MIKTEX and I did all of this

CRAN version

install.packages('tinytex')
tlmgr_install()

or the development version on GitHub

remotes::install_github('rstudio/tinytex')

tinytex::parse_packages()

latexmk(engine = 'pdflatex', emulation = TRUE)

update.packages(ask = FALSE, checkBuilt = TRUE)
tinytex::tlmgr_update()

options(tinytex.verbose = TRUE)

update.packages(ask = FALSE, checkBuilt = TRUE)
tinytex::tlmgr_update()

tinytex::tlmgr_install(c('texlive-scripts', 'dehyph-exptl'))
tinytex::tlmgr_install(c('texlive-scripts', 'dehyph-exptl'))

tinytex::uninstall_tinytex()
tinytex::install_tinytex(dir = "C:/TinyTeX")

TinyTeX (tinytex::reinstall_tinytex())

and this is the error : Listening on http://127.0.0.1:3130

processing file: report.Rmd

output file: report.knit.md

"C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/pandoc" +RTS -K512m -RTS report.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output pandoc3628d2d65bd.tex --lua-filter "C:\Users\s.rhazi\AppData\Local\Programs\R\R-4.3.3\library\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\s.rhazi\AppData\Local\Programs\R\R-4.3.3\library\rmarkdown\rmarkdown\lua\latex-div.lua" --embed-resources --standalone --highlight-style tango --pdf-engine pdflatex --variable graphics --include-in-header "C:\Users\SB81C1.RHA\AppData\Local\Temp\Rtmp0Y8Fyp\rmarkdown-str36287f00461c.html" --variable "geometry:margin=1in"
This is pdfTeX, Version 3.141592653-2.6-1.40.25 (MiKTeX 24.1) (preloaded format=pdflatex.fmt)
restricted \write18 enabled.
entering extended mode
Avis : Error in : LaTeX failed to compile C:\Users\SB81C
1.RHA\AppData\Local\Temp\Rtmp0Y8Fyp\file362853c05ec3.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips.
3: runApp
2: print.shiny.appobj
1:

stressedchicken123 stressedchicken123 2024-12-31 10:49:02

In R Markdown I had the following errors when I try knitting using the papaja apa 6th edition format:

tlmgr: Remote database (revision 73229 of the texlive-scripts package) seems to be older than the local installation (rev 73240 of texlive-scripts); please use a different mirror and/or wait a day or two. ! LaTeX Error: File caption.sty' not found. ! Emergency stop. <read *> Error: LaTeX failed to compile Untitled.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Untitled.log for more info.

In addition: Warning message: In system2("tlmgr", args, ...) : running command ''tlmgr' search --file --global '/caption.sty'' had status 1 Execution halted

I have tried everything and nothing changes or a new error will appear…

Im using the R version 4.4.2 for Mac.

cderv cderv 2024-12-31 14:00:24

Probably something related to your TeX Live installation, or just your network. It seems it couldn't reach the CTAN server to install the missing caption.sty.

So check your network and your TinyTeX (or TeX Live) install - you could try reinstalling.

ecceeecs ecceeecs 2025-04-07 21:52:38
<div style="color: rgb(0, 0, 0); font-family: &quot;Lucida Grande&quot;, serif; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(246, 247, 249); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; position: absolute; overflow: hidden; z-index: 0; inset: 0px 0px 525px;"><div role="region" aria-label="Source" class="windowframe GNTYACMBJW" style="-webkit-font-smoothing: subpixel-antialiased; position: absolute; inset: 0px;"><div style="border: 1px solid rgb(214, 218, 220); border-radius: 3px 3px 0px 0px; inset: 3px 3px 5px; overflow: hidden; position: absolute;"><div style="position: absolute; inset: 0px;"><div style="position: relative; width: 1041.48px; height: 559.253px;"><div style="position: absolute; overflow: hidden; inset: 0px;"><div class="gwt-TabLayoutPanel GNTYACMBDQ GNTYACMBMS rstudio_source_panel" style="background: rgb(244, 248, 249); position: absolute; inset: 0px;"><div style="inset: 24px 0px 0px; position: absolute; overflow: hidden;"><div class="gwt-TabLayoutPanelContentContainer" style="position: absolute; inset: 0px;"><div style="position: absolute; overflow: hidden; left: 0px; top: 0px; width: 1041.48px; height: 536.267px;"><div role="tabpanel" aria-label="443HW1.Rmd" id="gwt-uid-584" class="gwt-TabLayoutPanelContent" style="background: rgb(244, 248, 249); position: absolute; inset: 0px;"><div style="position: absolute; overflow: hidden; inset: 46px 0px 16px;"><div class="ace_editor_theme" style="background-color: rgb(255, 255, 255); color: black; position: absolute; inset: 0px;"><div style="position: absolute; overflow: hidden; inset: 0px;"><div style="position: absolute; inset: 0px;"><div style="position: absolute; overflow: hidden; inset: 0px;"><div class="gwt-HTML GNTYACMBBX ace_editor ace_hidpi GNTYACMBJUC" id="rstudio_source_text_editor" style="position: absolute; overflow: hidden; padding: 0px; font-style: normal; font-variant: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-weight: normal; font-stretch: normal; font-size: 9pt !important; line-height: 1.45; font-family: Monaco, monospace !important; direction: ltr; text-align: left; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: none !important; background-color: rgb(255, 255, 255); color: black; width: 1041.48px; height: 474.288px; inset: 0px;"><div class=" ace_lineWidgetContainer" style="position: absolute; z-index: 3; top: 492.128px; left: 55px; right: 17px;"><div class="GNTYACMBPED GNTYACMBGU rstudio_chunk" style="user-select: text; cursor: text; padding-bottom: 7px; position: relative; height: 257px; background-color: rgb(255, 255, 255);"><div class="GNTYACMBMED" style="border: 1px solid rgba(0, 0, 0, 0.12); padding-top: 10px; overflow: hidden; height: 250px; background-color: rgb(255, 255, 255);"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAkCAYAAAD7PHgWAAABpklEQVR4Xu2VsU7CQBzGmVx8BUeegIEHkIaOLjjpTIAuPAJONp0d9BmIE3EjroRITDfciAnQ0tCIRgNqzNkPe1rvFNqjaRnuS740tLnv+7V3+ZPJSElJSW2farVatlqtHnvXhufTiG74a7NsbiyqVCqqruvnpmnejcfjheM4JIqxBmuRgSw2fyPhrQ3DuPBK5mxxVCMDWbF+SWwN3p4tEzWykMn2CAvnR2Rb/7NlWa8e4AnbIywcctu2SZxGJtsjLIT1+30Sp4UBi8XivqqqdcbtZvOSBN3r3ZK39w9hCwMCiIQQIJ9f5lxxWAsD0i84HDlklQE4caZccVgLA0KFQkFZBwnA4cjiisN6I0CIQtoTl4NLHZBuM86a6z5ycKkChoFLDXAV3BcQ+ztBwFVwmIOt1tUvyEQB18DVFUVpDQb3pNPpfkMmCkjhpu6Mg8vlckelUumMDuVu92YJ125fJzcH/xrOFM57vFcul41gOGAfZk/J/pMEh3MQzvMOwtiCTR0ZEKKQ+Xz+MOPD4f7WAPoC1K5/XUrTtAMExmlk/lRKSUlJJa5PbK0yKomJVB4AAAAASUVORK5CYII=" width="40" height="36" class="GNTYACMBCFD" title="Show in New Window" style="position: absolute; top: 0px; padding: 5px; cursor: pointer; z-index: 25; right: 58px; width: 14px; height: 14px; opacity: 0.7;"><div class="GNTYACMBDED" title="Clear Output" style="position: absolute; top: 2px; padding: 5px; cursor: pointer; z-index: 25; right: 12px; width: 11px !important; height: 10px !important;"><div class="GNTYACMBEED" style="background-size: 100%; width: 11px; height: 10px; background-image: url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAUCAYAAACJfM0wAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA4ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTM4IDc5LjE1OTgyNCwgMjAxNi8wOS8xNC0wMTowOTowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDoxZjc0ZGZmNi00ZWEyLTRmNTQtOTkxNS1mN2E1OGQyODdmMzgiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6Qzg0QzdGM0NGQUIwMTFFNkI1MjA5MzExNzcwNUREOTYiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6Qzg0QzdGM0JGQUIwMTFFNkI1MjA5MzExNzcwNUREOTYiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIDIwMTcgKE1hY2ludG9zaCkiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo2YmU2Yjg2ZC1jNTQ1LTQzZTEtOGYxNi03MTg1NWVkZTVlNGYiIHN0UmVmOmRvY3VtZW50SUQ9ImFkb2JlOmRvY2lkOnBob3Rvc2hvcDpkNTJiMzQxOC00MzE3LTExN2EtYjhmOS1kMTcyMzliNGI4YjAiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz5gxgbbAAAA00lEQVR42rTUUQrDIAwAUCvtyuh+R4+wa20fO1V3sR1B9quUwsBFsCAh0RRnIB+F+JCYtPPeqxahVaNoBvfpx+V6q8Ls51288Qg5CaxQc5K2IhTeIZ8FfIo1Dwqn4AHyDDln8B2dY+0ggR3kC9IweIqaWOukU2EZnEItBXTpghBTgSGVQyVTkbZlSW5evGntgvjazcOtMIVpEcEYXVBbsrg+gDqi5yyuD6Dcg5I4BX8hVwal8DWeEc3xGP98TvC4Ad3wHPfMgW0vFsy5Km7eP+MnwADdyU/tIwjohwAAAABJRU5ErkJggg==&quot;);"></div></div><div class="GNTYACMBJED" title="Expand/Collapse Output" style="position: absolute; top: 2px; padding: 5px; cursor: pointer; z-index: 25; width: 11px !important; height: 10px !important; right: 35px; transition: transform 400ms ease 0s, -webkit-transform 400ms ease 0s;"><div class="GNTYACMBKED" style="background-size: 100%; width: 11px; height: 10px; background-image: url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAUCAYAAACJfM0wAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA4ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTM4IDc5LjE1OTgyNCwgMjAxNi8wOS8xNC0wMTowOTowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDoxZjc0ZGZmNi00ZWEyLTRmNTQtOTkxNS1mN2E1OGQyODdmMzgiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6Qzg0QzdGMzRGQUIwMTFFNkI1MjA5MzExNzcwNUREOTYiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6Qzg0QzdGMzNGQUIwMTFFNkI1MjA5MzExNzcwNUREOTYiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIDIwMTcgKE1hY2ludG9zaCkiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo2YmU2Yjg2ZC1jNTQ1LTQzZTEtOGYxNi03MTg1NWVkZTVlNGYiIHN0UmVmOmRvY3VtZW50SUQ9ImFkb2JlOmRvY2lkOnBob3Rvc2hvcDpkNTJiMzQxOC00MzE3LTExN2EtYjhmOS1kMTcyMzliNGI4YjAiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz63LKxbAAAAwUlEQVR42mL8//8/Ay0AEwONAM0MZkEXSE1NBdOPHr1El2qC0nVycuIYBs2ePZssFzchs7FYSnxQ7Ny5CYxhhu7atXkLCMMMB7kQ3ZVEu9jd3Q9uKJA6BcIww2FyINdj8wETCYbCAIbhRLsY6AJchmIYjhb+uA0mZChShsJrOEZyAyalOmyGIXm7DsRnZGQEGw5Uf4qsDIJmKN5wJcpgkIHIhiInN5gYvnKG7OTm5uY7UpMblvDEazjjaEEPAwABBgBxs6XcbDPKhQAAAABJRU5ErkJggg==&quot;);"></div></div><div class="GNTYACMBDFD" style="position: relative; transition: opacity 400ms ease 0s; margin: 10px; opacity: 1;"><div><div data-ordinal="16"><div data-pagedtable="false"><div class="pagedtable pagedtable-not-empty" style="overflow: auto; padding-left: 8px; padding-right: 8px; font-family: &quot;Lucida Sans&quot;, &quot;DejaVu Sans&quot;, &quot;Lucida Grande&quot;, &quot;Segoe UI&quot;, Verdana, Helvetica, sans-serif; opacity: 1;"><div><div class="pagedtable-metacell" style="padding-left: 0px; padding-bottom: 10px; display: flex; flex-direction: row;"><div style="display: inline-block; border: 1px solid rgb(233, 233, 233); border-radius: 3px; padding: 4px; margin-left: 0px; margin-right: 10px; font-size: 8pt !important;"><span class="pagedtable-metafield" style="color: rgb(153, 153, 153); padding-right: 4px;">Description:</span><span class="pagedtable-metaval">df [6 × 7]</span></div></div></div>
 
--


</div></div></div><div style="position: absolute; overflow: hidden; inset: 22px 0px 0px;"><div style="width: 1041.48px; height: 470.781px; position: absolute; inset: 0px;"><div style="width: 1041.48px; height: 470.781px;"><div class="ace_editor ace_scroller" style="position: relative; overflow: auto; padding: 0px; font-style: normal; font-variant: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-weight: normal; font-stretch: normal; font-size: 12px; line-height: normal; font-family: Monaco, monospace !important; direction: ltr; text-align: left; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); top: 0px; bottom: 0px; background-color: rgb(255, 255, 255); user-select: none; cursor: text; border: none !important; color: black; zoom: 1; width: 1041.48px; height: 470.781px;"><div style="position: relative; zoom: 1;"><pre tabindex="0" class="GNTYACMBB4B GNTYACMBF4B GNTYACMBBX" style="font-family: Monaco, monospace; font-size: 9pt !important; outline: none; border: none; word-break: break-all; margin: 0px; user-select: text; white-space: pre-wrap !important; box-sizing: border-box; width: 1041.48px; padding: 6px; line-height: 1.45;"><span class="GNTYACMBB4B  ace_constant" style="outline: none; border: none; word-break: break-all; margin: 0px; user-select: text; white-space: pre-wrap !important; color: rgb(197, 6, 11);">

processing file: 443HW1.Rmd
</span><span class="GNTYACMBB4B" style="outline: none; border: none; word-break: break-all; margin: 0px; user-select: text; white-space: pre-wrap !important;">                                                                                                             
/Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/x86_64/pandoc +RTS -K512m -RTS 443HW1.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output 443HW1.tex --lua-filter /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/library/rmarkdown/rmarkdown/lua/latex-div.lua --embed-resources --standalone --highlight-style tango --pdf-engine pdflatex --variable graphics --include-in-header /var/folders/1r/h2xt1gz576x16dqm89mspbz00000gn/T//Rtmp4i5t31/rmarkdown-str130421e671e5a.html --variable 'geometry:margin=1in' 
</span><span class="GNTYACMBB4B  ace_constant" style="outline: none; border: none; word-break: break-all; margin: 0px; user-select: text; white-space: pre-wrap !important; color: rgb(197, 6, 11);">output file: 443HW1.knit.md

! Incomplete \ifx; all text was ignored after line 99.
&lt;inserted text&gt; 
                \fi 
&lt;*&gt; 443HW1.tex

Error: LaTeX failed to compile 443HW1.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See 443HW1.log for more info.
Execution halted</span></pre></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>

Hi all, I'm getting the above error when trying to knit in Rstudio. I've reinstalled TinyTex. It seems to be an issue with TeX.

I went to line 99 in the .tex file. here it is:

\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\usepackage[amsmath]
\ifLuaTeX
  \usepackage{selnolig}  % disable illegal ligatures
\fi
\usepackage{bookmark} #LINE 99 
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same}
\hypersetup{
cderv cderv 2025-04-08 09:39:27

Where does this HTML come from? Copy and paste from RStudio IDE copy, or do you see that in your file or in the console/terminal?

Unfortunately, we can't say much about this issue; this depends on your document's content.

ecceeecs ecceeecs 2025-04-09 04:51:25

Hi, it comes from "Render" in RStudio (line is now 109 since I added some stuff).
image

cderv cderv 2025-04-09 09:06:30

Something in your document is leading to faulty .tex file. Look at the .log file and try to find the Rmd part that can cause this.

Without idea about the content of the .Rmd that can cause this, we can't unfortunately help further

kola8513 kola8513 2025-04-30 13:31:16

Dear Yihui,

I'm trying to combine a Plotly plot and user text responses into a PDF report generated from an RMarkdown file in a Shiny app.

The downloadHandler part for "Download Plot (PNG)" works and I get a nice png plot but "Download PDF Report" doesn't work in which I tried to combine the user responses with the Plotly plot.

It gives error:
Warning: Error in : LaTeX failed to compile What I have tried: followed steps here: https://yihui.org/tinytex/r/#debugging.

  • I have installed Tinytex and updated it using

tinytex::tlmgr_update().

  • I made sure all packages are upto date

update.packages(ask = FALSE, checkBuilt = TRUE)

library(shiny)
library(plotly)

writeLines(
  con = file.path(tempdir(), 'report_template.rmd'),
  text =
    '---
title: "Self Assessment Report"
output: pdf_document
params:
  responses: !r list()
  plot_path: ""
---

```{r, include=FALSE}
options(tinytex.verbose = TRUE)
```


```{r}
for (i in seq_along(params$responses)) {
  cat(sprintf("**Response %d:**\n", i))
  cat(params$responses[[i]], "\n\n")
}
```

' )
```

```
ui <- fluidPage(

  tabPanel("EisenVerla",
           tabsetPanel(id = "Eisen_subtabs",
                       tabPanel("Self_Assessment",
                                fluidRow(
                                  column(
                                    width = 7,
                                    div(
                                      style = "border: 1px solid #dddddd; padding: 10px; margin-bottom: 20px",
                                      tags$h4("selfAssesment", style = "text-align: left; font-weight: bold; margin-bottom: 20px;"),

                                      # Questions with consistent spacing
                                      div(
                                        style = "margin-top: 20px;",  # Added margin for alignment with criteria

                                        # 1
                                        div(
                                          tags$h5("Enter your response"),
                                          radioButtons("response1", label = NULL, choices = c("N/A", 1:5), selected = "N/A", inline = TRUE),
                                          textAreaInput("response_text1", label = "comment", placeholder = "Enter text...")
                                        ),
                                        # 2
                                        div(
                                          tags$h5("Enter your response"),
                                          radioButtons("response2", label = NULL, choices = c("N/A", 1:5), selected = "N/A", inline = TRUE),
                                          textAreaInput("response_text2", label = "comment", placeholder = "Enter text...")
                                        ),

                                        # 3
                                        div(
                                          tags$h5("Enter your response"),
                                          radioButtons("response3", label = NULL, choices = c("N/A", 1:5), selected = "N/A", inline = TRUE),
                                          textAreaInput("response_text3", label = "comment", placeholder = "Enter text...")
                                        ),

                                        #  4
                                        div(
                                          tags$h5("Enter your response"),
                                          radioButtons("response4", label = NULL, choices = c("N/A", 1:5), selected = "N/A", inline = TRUE),
                                          textAreaInput("response_text4", label = "comment", placeholder = "Enter text...")
                                        ),

                                        #  5
                                        div(
                                          tags$h5("Enter your response"),
                                          radioButtons("response5", label = NULL, choices = c("N/A", 1:5), selected = "N/A", inline = TRUE),
                                          textAreaInput("response_text5", label = "comment", placeholder = "Enter text...")
                                        ),

                                        #  6
                                        div(
                                          tags$h5("Enter your response"),
                                          radioButtons("response6", label = NULL, choices = c("N/A", 1:5), selected = "N/A", inline = TRUE),
                                          textAreaInput("response_text6", label = "comment", placeholder = "Enter text...")
                                        ),
                                        
  
                                      )
                                    )
                                  ),
                                  column(
                                    width = 2,
                                    fluidRow(
                                      column(4,
                                             div(align = "left",
                                                 actionButton("export", "Export Plot"),
                                                 plotlyOutput("p"),
                                                 downloadButton("downloadPlot", "Download Plot (PNG)"),
                                                 
                                                 style = "margin-right: 500px;" 
                                             ),
                                             downloadButton("dnld", "Download PDF Report")
                                      )
                                    )
                                  ),
                                ),

                                mainPanel(
                                )

                       )

           )
  ),


)
```

```
server <- function(input, output, session) {

  # Compute numeric values for plot
  numeric_values <- reactive({
    sapply(1:6, function(i) {
      val <- input[[paste0("response", i)]]
      if (identical(val, "N/A")) NA_real_ else as.numeric(val)
    })
  })


  # interactive Plotly plot from from user based response
  myPlotlyGraph <- reactive({
    plot_ly(
      mode = 'markers+lines',
      type = 'scatterpolar',
      fill = 'toself',
      fillcolor = "rgba(231, 184, 0, 0.5)",
      line = list(color = 'rgb(0, 0, 0)'),
      marker = list(
        symbol = 100,
        size = 6,
        color = 'rgb(0, 0, 0)',
        line = list(color = 'rgb(0, 0, 0)', width = 1)
      ),
      r = numeric_values(),
      theta = c("<b>1</b>", "<b>2</b>", "<b>3</b>", "<b>4</b>", "<b>5</b>", "<b>6</b>")
    ) |>
      layout(
        title = list(text = "Self_Assessment", y = 0.99),
        polar = list(radialaxis = list(visible = TRUE, range = c(0, 5))),
        angularaxis = list(rotation = 90, direction = "clockwise"),
        showlegend = FALSE,
        margin = list(l = 30, r = 30, b = 30, t = 30),
        font = list(size = 9, color = 'black'),
        paper_bgcolor = "#B4D9F9",
        plot_bgcolor = "#B4D9F9",
        width = 400,
        height = 300
      )
  })
  
  # orca to save the plot

  observeEvent(input$export, {
    orca(myPlotlyGraph())
  })

  output$p <- renderPlotly({
    myPlotlyGraph()
  })

  # using webshot2 to save the static image
  output$downloadPlot <- downloadHandler(
    filename = function() "self_assessment_plot.png",
    content = function(file) {
      temp_html <- tempfile(fileext = ".html")
      htmlwidgets::saveWidget(myPlotlyGraph(), temp_html, selfcontained = TRUE)
      webshot2::webshot(temp_html, file = file, vwidth = 500, vheight = 400)
    }
  )
    #integrating png image in the pdf report doesn't work
  output$dnld <- downloadHandler(
    filename = function() "report_template.pdf",
    content = function(file) {
      # Save plotly plot as PNG
      temp_html <- tempfile(fileext = ".html")
      temp_png <- tempfile(fileext = ".png")
      htmlwidgets::saveWidget(myPlotlyGraph(), temp_html, selfcontained = TRUE)
      webshot2::webshot(temp_html, file = temp_png, vwidth = 500, vheight = 400)
      
      # Collect responses
      response_list <- lapply(1:6, function(i) input[[paste0("response_text", i)]])
      
      # Render PDF with plot
      rmarkdown::render(
        input = file.path(tempdir(), "report_template.rmd"),
        output_file = file,
        params = list(
          responses = response_list,
          plot_path = temp_png
        ),
        envir = new.env(parent = globalenv())
      )
    }
  )
}

shinyApp(ui, server)

```
`




thanks in advance.

cderv cderv 2025-04-30 16:39:30

Please format your post correctly regarding code block syntax.

Also does your parametrized rmarkdown::render() with your plotly graph works outside of shiny app ?

kola8513 kola8513 2025-05-02 07:58:22

Thanks. I edited the post. Yes, the parameterized rmarkdown::render() with plotly graph works outside of the shiny app.

cderv cderv 2025-05-02 09:04:01

Then it is probably related to how shiny will run the code you pass into downloadHandler()

I would suggest try to debug the shiny app and look at the log file from TeX compilation. This will tell you what the compilation error is.

Without knowing why LaTeX is failling in shiny context, it will be hard to help debug.

kola8513 kola8513 2025-05-02 09:42:32

Okay. I found the log file from TeX compilation.
texput.log

cderv cderv 2025-05-02 15:58:35

You got *** (job aborted, file error in nonstop mode)

It does not tell much - except that it fails completely. You need to understand what is different in your shiny app context for the rendering.

Check all resources are available to the .Rmd when in temp directory maybe.

It does not seem like a TinyTeX problem, but more like an environment problem when you are rendering in Shiny context

Sign in to join the discussion

Sign in with GitHub