rjournal / rjtools

Tools for AUTHORS to use for checking and submitting articles to the R Journal
https://rjournal.github.io/rjtools/
Other
31 stars 14 forks source link

Issue with references on pdf #124

Open rnlouro opened 6 months ago

rnlouro commented 6 months ago

When I tried to run the article template with the commands below the html version was rendered without a problem but there was an error for the pdf version.

rjtools::create_article() rmarkdown::render("test.Rmd")

Error: ! in callr subprocess. Caused by error: ! LaTeX failed to compile RJwrapper.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See RJwrapper.log for more info. See $stdout and $stderr for standard output and error.

Backtrace:

  1. rmarkdown::render("test.Rmd")
  2. output_format$on_exit()
  3. local overlay()
  4. callr::r(function(input) { …
  5. callr:::get_result(output = out, options)
  6. callr:::throw(callr_remote_error(remerr, output), parent = fix_msg(remerr[[3]]))

    Subprocess backtrace:

    1. rmarkdown::render(input, output_format = "rjtools::rjournal_pdf_article")
    2. output_format$post_processor(front_matter, input, output_file, …
    3. tinytex::latexmk("RJwrapper.tex", fmt$pandoc$latex_engine, pdf_file = xfun::with_ext(basename(output_file), …
    4. tinytex:::latexmk_emu(file, engine, bib_engine, engine_args, min_times, …
    5. local run_engine()
    6. tinytex:::system2_quiet(engine, c("-halt-on-error", "-interaction=batchmode", …
    7. local on_error()
    8. tinytex:::show_latex_error(file, logfile)
    9. base::stop(e, " See ", logfile, " for more info.", call. = FALSE)
  7. | base::.handleSimpleError(function (e) …
  8. global h(simpleError(msg, call))

In the RJwrapper.log file I managed to trace the error to this:

! LaTeX Error: Lonely \item--perhaps a missing list environment.

After some trial and error I managed to trace the issue to the article references. If the references are done with @ it will cause this error, however replacing everyone with \cite{} will stop the error, but now there will be a numbered heading named References and an unumbered heading named Bibliography in the article

The session info is the following:

─ Session info ──────────────────────────────────────────────────────────────────────────────────────────────────────── setting value version R version 4.4.0 (2024-04-24 ucrt) os Windows 11 x64 (build 22631) system x86_64, mingw32 ui RStudio language (EN) collate Portuguese_Portugal.utf8 ctype Portuguese_Portugal.utf8 tz Europe/Lisbon date 2024-05-05 rstudio 2024.04.0+735 Chocolate Cosmos (desktop) pandoc 3.1.11 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)

─ Packages ──────────────────────────────────────────────────────────────────────────────────────────────────────────── package version date (UTC) lib source BiocManager 1.30.23 2024-05-04 [1] CRAN (R 4.4.0) bookdown 0.39 2024-04-15 [1] CRAN (R 4.4.0) bslib 0.7.0 2024-03-29 [1] CRAN (R 4.4.0) cachem 1.0.8 2023-05-01 [1] CRAN (R 4.4.0) callr 3.7.6 2024-03-25 [1] CRAN (R 4.4.0) cli 3.6.2 2023-12-11 [1] CRAN (R 4.4.0) colorspace 2.1-0 2023-01-23 [1] CRAN (R 4.4.0) crosstalk 1.2.1 2023-11-23 [1] CRAN (R 4.4.0) curl 5.2.1 2024-03-01 [1] CRAN (R 4.4.0) data.table 1.15.4 2024-03-30 [1] CRAN (R 4.4.0) devtools 2.4.5 2022-10-11 [1] CRAN (R 4.4.0) digest 0.6.35 2024-03-11 [1] CRAN (R 4.4.0) distill 1.6 2023-10-06 [1] CRAN (R 4.4.0) downlit 0.4.3 2023-06-29 [1] CRAN (R 4.4.0) dplyr 1.1.4 2023-11-17 [1] CRAN (R 4.4.0) ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.4.0) evaluate 0.23 2023-11-01 [1] CRAN (R 4.4.0) fansi 1.0.6 2023-12-08 [1] CRAN (R 4.4.0) farver 2.1.1 2022-07-06 [1] CRAN (R 4.4.0) fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.4.0) fs 1.6.4 2024-04-25 [1] CRAN (R 4.4.0) generics 0.1.3 2022-07-05 [1] CRAN (R 4.4.0) ggplot2 3.5.1 2024-04-23 [1] CRAN (R 4.4.0) glue 1.7.0 2024-01-09 [1] CRAN (R 4.4.0) gtable 0.3.5 2024-04-22 [1] CRAN (R 4.4.0) highr 0.10 2022-12-22 [1] CRAN (R 4.4.0) htmltools 0.5.8.1 2024-04-04 [1] CRAN (R 4.4.0) htmlwidgets 1.6.4 2023-12-06 [1] CRAN (R 4.4.0) httpuv 1.6.15 2024-03-26 [1] CRAN (R 4.4.0) httr 1.4.7 2023-08-15 [1] CRAN (R 4.4.0) hunspell 3.0.3 2023-10-06 [1] CRAN (R 4.4.0) jquerylib 0.1.4 2021-04-26 [1] CRAN (R 4.4.0) jsonlite 1.8.8 2023-12-04 [1] CRAN (R 4.4.0) kableExtra 1.4.0 2024-01-24 [1] CRAN (R 4.4.0) knitr 1.46 2024-04-06 [1] CRAN (R 4.4.0) labeling 0.4.3 2023-08-29 [1] CRAN (R 4.4.0) later 1.3.2 2023-12-06 [1] CRAN (R 4.4.0) lazyeval 0.2.2 2019-03-15 [1] CRAN (R 4.4.0) lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.4.0) lubridate 1.9.3 2023-09-27 [1] CRAN (R 4.4.0) magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.4.0) memoise 2.0.1 2021-11-26 [1] CRAN (R 4.4.0) mime 0.12 2021-09-28 [1] CRAN (R 4.4.0) miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 4.4.0) munsell 0.5.1 2024-04-01 [1] CRAN (R 4.4.0) palmerpenguins 0.1.1 2022-08-15 [1] CRAN (R 4.4.0) pillar 1.9.0 2023-03-22 [1] CRAN (R 4.4.0) pkgbuild 1.4.4 2024-03-17 [1] CRAN (R 4.4.0) pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.4.0) pkgload 1.3.4 2024-01-16 [1] CRAN (R 4.4.0) plotly * 4.10.4 2024-01-13 [1] CRAN (R 4.4.0) processx 3.8.4 2024-03-16 [1] CRAN (R 4.4.0) profvis 0.3.8 2023-05-02 [1] CRAN (R 4.4.0) promises 1.3.0 2024-04-05 [1] CRAN (R 4.4.0) ps 1.7.6 2024-01-18 [1] CRAN (R 4.4.0) purrr 1.0.2 2023-08-10 [1] CRAN (R 4.4.0) R6 2.5.1 2021-08-19 [1] CRAN (R 4.4.0) Rcpp 1.0.12 2024-01-09 [1] CRAN (R 4.4.0) remotes 2.5.0 2024-03-17 [1] CRAN (R 4.4.0) rjtools 1.0.14 2024-05-04 [1] Github (rjournal/rjtools@567c5be) rlang 1.1.3 2024-01-10 [1] CRAN (R 4.4.0) rmarkdown 2.26 2024-03-05 [1] CRAN (R 4.4.0) rprojroot 2.0.4 2023-11-05 [1] CRAN (R 4.4.0) rstudioapi 0.16.0 2024-03-24 [1] CRAN (R 4.4.0) sass 0.4.9 2024-03-15 [1] CRAN (R 4.4.0) scales 1.3.0 2023-11-28 [1] CRAN (R 4.4.0) sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.4.0) shiny 1.8.1.1 2024-04-02 [1] CRAN (R 4.4.0) stringi 1.8.3 2023-12-11 [1] CRAN (R 4.4.0) stringr 1.5.1 2023-11-14 [1] CRAN (R 4.4.0) svglite 2.1.3 2023-12-08 [1] CRAN (R 4.4.0) systemfonts 1.0.6 2024-03-07 [1] CRAN (R 4.4.0) tibble 3.2.1 2023-03-20 [1] CRAN (R 4.4.0) tidyr 1.3.1 2024-01-24 [1] CRAN (R 4.4.0) tidyselect 1.2.1 2024-03-11 [1] CRAN (R 4.4.0) timechange 0.3.0 2024-01-18 [1] CRAN (R 4.4.0) urlchecker 1.0.1 2021-11-30 [1] CRAN (R 4.4.0) usethis 2.2.3 2024-02-19 [1] CRAN (R 4.4.0) utf8 1.2.4 2023-10-22 [1] CRAN (R 4.4.0) varbreaks 0.1.0 2024-05-01 [1] local vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.4.0) viridisLite 0.4.2 2023-05-02 [1] CRAN (R 4.4.0) whisker 0.4.1 2022-12-05 [1] CRAN (R 4.4.0) withr 3.0.0 2024-01-16 [1] CRAN (R 4.4.0) xfun 0.43 2024-03-25 [1] CRAN (R 4.4.0) xml2 1.3.6 2023-12-04 [1] CRAN (R 4.4.0) xtable 1.8-4 2019-04-21 [1] CRAN (R 4.4.0) yaml 2.3.8 2023-12-11 [1] CRAN (R 4.4.0) yesno 0.1.2 2020-07-10 [1] CRAN (R 4.4.0)

[1] C:/Users/Rui/AppData/Local/R/win-library/4.4 [2] C:/Program Files/R/R-4.4.0/library

lclarfel commented 6 months ago

I am having the same issue and would love any input on how to resolve it.

niekdt commented 6 months ago

This apparently only happens for recent versions of pandoc, as mentioned here. I was using pandoc 3.1.11 (included with Rstudio) and getting the same issue.

Quick work-around

Force rmarkdown rendering using an older version of pandoc. However, as rjtools::rjournal_article appears to override the active pandoc version, you need to render the HTML and PDF outputs separately. So change the output to:

# test.rmd
output: 
  rjtools::rjournal_pdf_article:
    toc: no
  rjtools::rjournal_web_article:
    self_contained: yes
    toc: no

Then you can render using:

pandoc::pandoc_activate(version = '3.1.6')
rmarkdown::render('test.Rmd', output_format = 'all')
rnlouro commented 5 months ago

This apparently only happens for recent versions of pandoc, as mentioned here. I was using pandoc 3.1.11 and getting the same issue.

Quick work-around

Force rmarkdown rendering using an older version of pandoc. However, as rjtools::rjournal_article appears to override the active pandoc version, you need to render the HTML and PDF outputs separately. So change the output to:

# test.rmd
output: 
  rjtools::rjournal_pdf_article:
    toc: no
  rjtools::rjournal_web_article:
    self_contained: yes
    toc: no

Then you can render using:

pandoc::pandoc_activate(version = '3.1.6')
rmarkdown::render('test.Rmd', output_format = 'all')

Thanks, I managed to make it work with this work around.

lbelzile commented 4 months ago

Duplicate of #117 ?