Skip to content

Commit

Permalink
require the data-latex attribute on fenced Div's again: #1779 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Jun 29, 2020
1 parent b53a85a commit b2cff70
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
================================================================================
Expand Down
10 changes: 4 additions & 6 deletions inst/rmd/lua/latex-div.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(
Expand Down

0 comments on commit b2cff70

Please sign in to comment.