From b2cff70c523b1bd6a7269fc8c28ee9ca9f51c71a Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Mon, 29 Jun 2020 15:53:31 -0500 Subject: [PATCH] require the data-latex attribute on fenced Div's again: https://github.com/rstudio/rmarkdown/issues/1779#issuecomment-647184984 --- NEWS.md | 2 ++ inst/rmd/lua/latex-div.lua | 10 ++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0c9bfb69c0..a7fb409d4c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ rmarkdown 2.4 ================================================================================ +- Since **rmarkdown** 1.16, Pandoc's fenced `Div`'s are converted to LaTeX environments when the output format is LaTeX, e.g., `::: {.center data-latex=""}` is converted to `\begin{center}`. The attribute `data-latex` of the `Div` was mandatory, even if it is empty. In **rmarkdown** 2.2, we silently drop this requirement, which means `::: {.center}` is converted to `\begin{center}`. This turns out to be a bad idea, because users have no control over which Div's to be converted to LaTeX environments. Previously, they could opt-in by the `data-latex` attribute, but with **rmarkdown** 2.3, all Div's are converted to LaTeX environments unconditionally. What's more, this change led to bugs like https://stackoverflow.com/q/62340425/559676 and https://github.com/rstudio/bookdown/issues/883. Therefore the `data-latex` attribute became mandatory again in this version. If the LaTeX environment does not need arguments, you may use `data-latex=""`. + rmarkdown 2.3 ================================================================================ diff --git a/inst/rmd/lua/latex-div.lua b/inst/rmd/lua/latex-div.lua index ab4bc032f9..cc80f7c054 100644 --- a/inst/rmd/lua/latex-div.lua +++ b/inst/rmd/lua/latex-div.lua @@ -6,13 +6,11 @@ Div = function (div) local options = div.attributes['data-latex'] + if options == nil then return nil end - -- if the output format is not latex, the object is left unchanged + -- if the output format is not latex, remove the data-latex attr and return if FORMAT ~= 'latex' and FORMAT ~= 'beamer' then - -- if options has been set for latex, unset for other output - if options then - div.attributes['data-latex'] = nil - end + div.attributes['data-latex'] = nil return div end @@ -23,7 +21,7 @@ Div = function (div) -- insert raw latex before content table.insert( div.content, 1, - pandoc.RawBlock('tex', '\\begin' .. '{' .. env .. '}' .. (options or "")) + pandoc.RawBlock('tex', '\\begin' .. '{' .. env .. '}' .. options) ) -- insert raw latex after content table.insert(