rstudio / rmarkdown

Dynamic Documents for R
https://rmarkdown.rstudio.com
GNU General Public License v3.0
2.88k stars 979 forks source link

Pandoc error with latex-div.lua with pandoc 2.5 and rmarkdown 2.7 #2121

Closed ghost closed 3 years ago

ghost commented 3 years ago

Checklist

When filing a bug report, please check the boxes below to confirm that you have provided us with the information we need. Have you:

ReprEx

I am using the multi-column example from the R Markdown Cookbook:

test.Rmd

---
output:
  html_document:
    css: columns.css
  pdf_document:
    keep_tex: true
    includes:
      in_header: columns.tex
  beamer_presentation:
    keep_tex: true
    includes:
      in_header: columns.tex
---

# Two columns

Below is a Div containing three child Divs side by side. The Div
in the middle is empty, just to add more space between the left
and right Divs.

:::::: {.cols data-latex=""}

::: {.col data-latex="{0.55\textwidth}"}
```{r, echo=FALSE, fig.width=5, fig.height=4}
par(mar = c(4, 4, .2, .1))
plot(cars, pch = 19)

:::

::: {.col data-latex="{0.05\textwidth}"} \

:::

::: {.col data-latex="{0.4\textwidth}"} The figure on the left-hand side shows the cars data. ::: ::::::


**columns.css**

```` css
.cols {display: flex; }

columns.tex

\newenvironment{cols}[1][]{}{}

\newenvironment{col}[1]{\begin{minipage}{#1}\ignorespaces}{%
\end{minipage}
\ifhmode\unskip\fi
\aftergroup\useignorespacesandallpars}

\def\useignorespacesandallpars#1\ignorespaces\fi{%
#1\fi\ignorespacesandallpars}

\makeatletter
\def\ignorespacesandallpars{%
  \@ifnextchar\par
    {\expandafter\ignorespacesandallpars\@gobble}%
    {}%
}
\makeatother

Output from xfun::session_info('rmarkdown')

> xfun::session_info('rmarkdown')
R version 4.0.5 (2021-03-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.2 LTS

Locale:
  LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
  LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
  LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
  LC_PAPER=en_US.UTF-8       LC_NAME=C
  LC_ADDRESS=C               LC_TELEPHONE=C
  LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

Package version:
  base64enc_0.1.3   digest_0.6.27     evaluate_0.14     glue_1.4.2
  graphics_4.0.5    grDevices_4.0.5   highr_0.9         htmltools_0.5.1.1
  jsonlite_1.7.2    knitr_1.33        magrittr_2.0.1    markdown_1.1
  methods_4.0.5     mime_0.10         rlang_0.4.10      rmarkdown_2.7
  stats_4.0.5       stringi_1.5.3     stringr_1.4.0     tinytex_0.31
  tools_4.0.5       utils_4.0.5       xfun_0.22         yaml_2.2.1

Pandoc version: 2.5

Error

> rmarkdown::render("test.Rmd")

processing file: test.Rmd
  |.......................                                               |  33%
  ordinary text without R code

  |...............................................                       |  67%
label: unnamed-chunk-1 (with options)
List of 3
 $ echo      : logi FALSE
 $ fig.width : num 5
 $ fig.height: num 4

  |......................................................................| 100%
  ordinary text without R code

output file: test.knit.md

/usr/bin/pandoc +RTS -K512m -RTS test.utf8.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output test.html --lua-filter /usr/lib/R/site-library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /usr/lib/R/site-library/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --variable bs3=TRUE --standalone --section-divs --template /usr/lib/R/site-library/rmarkdown/rmd/h/default.html --no-highlight --variable highlightjs=1 --css columns.css --variable theme=bootstrap --include-in-header /tmp/Rtmp2jC2ni/rmarkdown-str2768220b17629.html --mathjax --variable 'mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
Error running filter /usr/lib/R/site-library/rmarkdown/rmarkdown/lua/latex-div.lua:
C stack overflow
stack traceback:
        [C]: in function 'table.remove'
        [string "--[[..."]:829: in function <[string "--[[..."]:826>
        [C]: in function 'table.remove'
        [string "--[[..."]:829: in function <[string "--[[..."]:826>
        [C]: in function 'table.remove'
        [string "--[[..."]:829: in function <[string "--[[..."]:826>
        [C]: in function 'table.remove'
        [string "--[[..."]:829: in function <[string "--[[..."]:826>
        [C]: in function 'table.remove'
        [string "--[[..."]:829: in function <[string "--[[..."]:826>
        ...
        [C]: in function 'table.remove'
        [string "--[[..."]:829: in function <[string "--[[..."]:826>
        [C]: in function 'table.remove'
        [string "--[[..."]:829: in function <[string "--[[..."]:826>
        [C]: in function 'table.remove'
        [string "--[[..."]:829: in function <[string "--[[..."]:826>
        [C]: in function 'table.remove'
        [string "--[[..."]:829: in function <[string "--[[..."]:826>
        [C]: in function 'table.remove'
        [string "--[[..."]:829: in metamethod '__newindex'
        ...lib/R/site-library/rmarkdown/rmarkdown/lua/latex-div.lua:22: in function 'Div'
Error: pandoc document conversion failed with error 83
cderv commented 3 years ago

Thanks I can reproduce on Windows with Pandoc 2.5. That is odd that we don't catch that in our CI. I'll check and add tests.

And also try to fix the Lua Filter - it seems like a Pandoc issue. I hope we can do something at the filter level.

Thanks a lot for the report.

cderv commented 3 years ago

Oh I see. I missed the fact that this is working with rmarkdown 2.6 but not 2.7.

From a git bisect, I see that it happens in 433e726ff5aee9cd14a285f756af814c44929c8d. I'll start from there

cderv commented 3 years ago

@davidwales thanks for the report. This should be fixed now in dev version. Sorry for the trouble.

cderv commented 3 years ago

For reference the Pandoc error was:

Error running filter C:\Users\chris\Documents\DEV_R\rmarkdown\inst\rmarkdown\lua\latex-div.lua:
C stack overflow
stack traceback:
    [C]: in function 'table.remove'
    [string "--[[..."]:829: in function <[string "--[[..."]:826>
    [C]: in function 'table.remove'
    [string "--[[..."]:829: in function <[string "--[[..."]:826>
    [C]: in function 'table.remove'
    [string "--[[..."]:829: in function <[string "--[[..."]:826>
    [C]: in function 'table.remove'
    [string "--[[..."]:829: in function <[string "--[[..."]:826>
    [C]: in function 'table.remove'
    [string "--[[..."]:829: in function <[string "--[[..."]:826>
    ...
    [C]: in function 'table.remove'
    [string "--[[..."]:829: in function <[string "--[[..."]:826>
    [C]: in function 'table.remove'
    [string "--[[..."]:829: in function <[string "--[[..."]:826>
    [C]: in function 'table.remove'
    [string "--[[..."]:829: in function <[string "--[[..."]:826>
    [C]: in function 'table.remove'
    [string "--[[..."]:829: in function <[string "--[[..."]:826>
    [C]: in function 'table.remove'
    [string "--[[..."]:829: in metamethod '__newindex'
    [string "C:\Users\chris\Documents\DEV_R\rmarkdown\inst..."]:36: in function 'Div'
Error: pandoc document conversion failed with error 83
ghost commented 3 years ago

Thank you!

github-actions[bot] commented 3 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.