Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSS doc fails to knit with library(kableExtra) #497

Open
3 tasks done
egouldo opened this issue Jun 23, 2022 · 1 comment
Open
3 tasks done

JSS doc fails to knit with library(kableExtra) #497

egouldo opened this issue Jun 23, 2022 · 1 comment
Labels
bug an unexpected problem or unintended behavior Upstream journals Issue probably related to journals template

Comments

@egouldo
Copy link

egouldo commented Jun 23, 2022


By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.name/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('rticles'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/rticles').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

Problem Description

JSS document fails to knit when the kableExtra library is loaded.
Suspect, possibly related to #329? When working in another document with an older version of jss.cls I get the error reported in #329, and when replacing with newest jss.cls provided with `rticles' I get the error in the MRE below.

MRE

Stock JSS template used below, with addition of call to kableExtra library, and session / tlmgr info chunk.

---
documentclass: jss
author:
  - name: FirstName LastName
    orcid: 0000-0000-0000-0000
    affiliation: University/Company
    # use this syntax to add text on several lines
    address: |
      | First line
      | Second line
    email: \email{name@company.com}
    url: http://rstudio.com
  - name: Second Author
    orcid: 0000-0000-0000-0000
    affiliation: 'Affiliation \AND'
    # To add another line, use \AND at the end of the previous one as above
  - name: Third Author
    orcid: 0000-0000-0000-0000
    address: |
      | Department of Statistics and Mathematics,
      | Faculty of Biosciences,
      | Universitat Autònoma de Barcelona
    affiliation: |
      | Universitat Autònoma 
      | de Barcelona
    # use a different affiliation in adress field (differently formated here)
    affiliation2: Universitat Autònoma de Barcelona
title:
  formatted: "A Capitalized Title: Something about a Package \\pkg{foo}"
  # If you use tex in the formatted title, also supply version without
  plain:     "A Capitalized Title: Something about a Package foo"
  # For running headers, if needed
  short:     "\\pkg{foo}: A Capitalized Title"
abstract: >
  The abstract of the article.
keywords:
  # at least one keyword must be supplied
  formatted: [keywords, not capitalized, "\\proglang{Java}"]
  plain:     [keywords, not capitalized, Java]
preamble: >
  \usepackage{amsmath}
output: rticles::jss_article
---

```{r, setup, include=FALSE}
options(prompt = 'R> ', continue = '+ ')
```

```{r}
library(kableExtra)
```

```{r}
tinytex::tlmgr_version()
xfun::session_info()
```


Error output

! Undefined control sequence.
<template> ...@setup \CT@row@color \CT@cell@color 
                                                  \CT@do@color \endgroup \@t...
l.78 \begin{document}

Error: LaTeX failed to compile Untitled.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See Untitled.log for more info.
Execution halted

Is there any suggested work around while awaiting a fix? I've tried using huxtable and get the same error, but only after creating a table, not when the huxtable library is called like in the MRE above.

Session Info

R version 4.2.0 (2022-04-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.6.5, RStudio 2022.2.3.492

Locale: en_AU.UTF-8 / en_AU.UTF-8 / en_AU.UTF-8 / C / en_AU.UTF-8 / en_AU.UTF-8

Package version:
  base64enc_0.1.3  bslib_0.3.1      digest_0.6.29    evaluate_0.15    fastmap_1.1.0    fs_1.5.2        
  glue_1.6.2       graphics_4.2.0   grDevices_4.2.0  highr_0.9        htmltools_0.5.2  jquerylib_0.1.4 
  jsonlite_1.8.0   knitr_1.39       magrittr_2.0.3   methods_4.2.0    R6_2.5.1         rappdirs_0.3.3  
  rlang_1.0.2      rmarkdown_2.14.3 rticles_0.23.6   sass_0.4.1       stats_4.2.0      stringi_1.7.6   
  stringr_1.4.0    tinytex_0.40     tools_4.2.0      utils_4.2.0      xfun_0.31        yaml_2.3.5   

TeXLive install:

tlmgr revision 63068 (2022-04-18 07:58:07 +0200)
tlmgr using installation: /Users/egould/Library/TinyTeX
TeX Live (https://tug.org/texlive) version 2022
@cderv
Copy link
Collaborator

cderv commented Jun 23, 2022

When kableExtra is loaded, it will add some LaTeX depedencies in the .tex file

\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{colortbl}
\usepackage{pdflscape}
\usepackage{tabu}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage[normalem]{ulem}
\usepackage{makecell}
\usepackage{xcolor}

That is the only difference, and it seems one of them conflict with what is already in the template. The one being \usepackage{colortbl} which conflict with jss.cls when this is called.

See kableExtra documentation: http://haozhu233.github.io/kableExtra/awesome_table_in_pdf.pdf for a workaround:

  • Deactivate auto insertation
```{r}
options(kableExtra.latex.load_packages = FALSE)
library(kableExtra)
```
  • Add dependencies manually removing the one that is causing trouble (see kableExtra::kableExtra_latex_packages())
header-includes:
  - \usepackage{booktabs}
  - \usepackage{longtable}
  - \usepackage{array}
  - \usepackage{multirow}
  - \usepackage{wrapfig}
  - \usepackage{float}
  - \usepackage{pdflscape}
  - \usepackage{tabu}
  - \usepackage{threeparttable}
  - \usepackage{threeparttablex}
  - \usepackage[normalem]{ulem}
  - \usepackage[utf8]{inputenc}
  - \usepackage{makecell}
  - \usepackage{xcolor}

You'll just loose some coloring feature I guess.

cc @haozhu233 in you case you already encounter that.

And it will be the same with huxtable as it uses also colortbl

huxtable::report_latex_dependencies()
#> \usepackage{array}
#> \usepackage{caption}
#> \usepackage{graphicx}
#> \usepackage{siunitx}
#> \usepackage[normalem]{ulem}
#> \usepackage{colortbl}
#> \usepackage{multirow}
#> \usepackage{hhline}
#> \usepackage{calc}
#> \usepackage{tabularx}
#> \usepackage{threeparttable}
#> \usepackage{wrapfig}
#> \usepackage{adjustbox}
#> \usepackage{hyperref}
#> % These are LaTeX packages. You can install them using your LaTex management software,
#> % or by running `huxtable::install_latex_dependencies()` from within R.
#> % Other packages may be required if you use non-standard tabulars (e.g. tabulary).

So basically this is an issue with JSS unless we can deal with it by changing some order of loading or configuration.
My understanding is that colortbl will do some stuff \AtBeginDocument, and this is conflicting with the jss class. Hence the issue in JSS format only.

Hope it helps understand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior Upstream journals Issue probably related to journals template
Projects
None yet
Development

No branches or pull requests

2 participants