rstudio / rticles

LaTeX Journal Article Templates for R Markdown
https://pkgs.rstudio.com/rticles/
1.46k stars 516 forks source link

Documents with tables with long texts, created with visual markdown editor are not knitted #421

Closed ccamara closed 2 years ago

ccamara commented 3 years ago

Documents with tables and long texts created with Rstudio's visual editor cause the following error when running knitr and using elsevier template:

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

The offending table, created with visual editor has this format:

+----------+--------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+
| Column 1 | Column 2                                                           | Column 3                                                                                               |
+==========+====================================================================+========================================================================================================+
| Cell 1.1 | This is a very, very, long text that does not fit in a single line | And this is also a very very (even longer, maybe) text that makes it difficult to fit in a single line |
+----------+--------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+
| Cell 1.2 |                                                                    |                                                                                                        |
+----------+--------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+
| Cell 1.3 |                                                                    |                                                                                                        |
+----------+--------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+

: The offending table

See xfun::session_info('rticles') output:

R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042), RStudio 1.4.1717

Locale:
  LC_COLLATE=English_United States.1252 
  LC_CTYPE=English_United States.1252   
  LC_MONETARY=English_United States.1252
  LC_NUMERIC=C                          
  LC_TIME=English_United States.1252    

Package version:
  base64enc_0.1.3   digest_0.6.27     evaluate_0.14     glue_1.4.2       
  graphics_4.1.0    grDevices_4.1.0   highr_0.9         htmltools_0.5.1.1
  jsonlite_1.7.2    knitr_1.33        magrittr_2.0.1    markdown_1.1     
  methods_4.1.0     mime_0.11         rlang_0.4.11      rmarkdown_2.9    
  rticles_0.20.2    stats_4.1.0       stringi_1.6.2     stringr_1.4.0    
  tinytex_0.32      tools_4.1.0       utils_4.1.0       xfun_0.24        
  yaml_2.2.1 

And the entire document:

---
title: Short Paper
author:
  - name: Alice Anonymous
    email: alice@example.com
    affiliation: Some Institute of Technology
    footnote: 1
  - name: Bob Security
    email: bob@example.com
    affiliation: Another University
  - name: Cat Memes
    email: cat@example.com
    affiliation: Another University
    footnote: 2
  - name: Derek Zoolander
    email: derek@example.com
    affiliation: Some Institute of Technology
    footnote: 2
address:
  - code: Some Institute of Technology
    address: Department, Street, City, State, Zip
  - code: Another University
    address: Department, Street, City, State, Zip
footnote:
  - code: 1
    text: "Corresponding Author"
  - code: 2
    text: "Equal contribution"
abstract: |
  This is the abstract.

  It consists of two paragraphs.

journal: "An awesome journal"
date: "`r Sys.Date()`"
bibliography: mybibfile.bib
#linenumbers: true
#numbersections: true
csl: elsevier-harvard.csl
output: rticles::elsevier_article
---

*Text based on elsarticle sample manuscript, see <http://www.elsevier.com/author-schemas/latex-instructions#elsarticle>*

# The Elsevier article class

### Table R code

This table works great.

```{r}
mtcars

Markdown Table

This table is also rendered:

Col1 Col2 Col3
Cell 1.1 Cell 2.1 Cell 3.1
Cell 1.2 Cell 2.2 Cell 3.2
Cell 1.3 Cell 2.3 Cell 3.3

: Table using Visual mardkwon editor

This table, on the contrary, is not. Please note the different formatting:

+----------+--------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+ | Column 1 | Column 2 | Column 3 | +==========+====================================================================+========================================================================================================+ | Cell 1.1 | This is a very, very, long text that does not fit in a single line | And this is also a very very (even longer, maybe) text that makes it difficult to fit in a single line | +----------+--------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+ | Cell 1.2 | | | +----------+--------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+ | Cell 1.3 | | | +----------+--------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+

: The offending tables



---

By filing an issue to this repo, I promise that

- [x] I have fully read the issue guide at https://yihui.name/issue/.
- [x] 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.
- [x] 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.
cderv commented 3 years ago

I think this happens because some LaTeX packages are missing in the template, but required if you use Pandoc's grid table syntax. The Visual will use Grid tables in some cases.

This should work by adding this in your YAML header

output: 
  rticles::elsevier_article: 
    extra_dependencies: 
      - array
      - calc

Can you try ?

For the context, this is required because Pandoc will convert the grid table Markdown to a LaTeX syntax using those packages' functions.

We may need to add them into all our template to make them work with grid_tables. However, some editor does not allow to add other packages than those expected so it is not easy for us to know when to add them automatically or not.

ccamara commented 3 years ago

Thank you very much, @cderv !

Simply adding those extra dependencies in the yaml worked! (Sorry, I'm not familiar at all with Latex -that's why I'm using this package)

cderv commented 3 years ago

I'll reopen because I think it would be better to add them into the template.

ccamara commented 3 years ago

Great! Thank you again and sorry for the inconvenience.

cderv commented 2 years ago

@ccamara This should be fine now with dev version of rticles

remotes::install_github("rstudio/rticles")

Thanks!

ccamara commented 2 years ago

Thank you very much @cderv!

github-actions[bot] commented 2 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.