-
-
Notifications
You must be signed in to change notification settings - Fork 996
Description
Design about this lua filters by @RLesur has been discussed in yihui/bookdown-crc#1 and added in rmarkdown in cecd812
Currently, the lua filter is only activated and useful for latex output if data-latex= has been added. If not useful, it must be set to ""
I think this is not obvious from what you expect from pandoc and it does not serve well "multi-format" output, because you need to add data-latex="" if you want it to work in pdf and in html. Currently, it seems that example in ongoing bookdown-cookbook is not working : rstudio/rmarkdown-cookbook#188
How about improving the filter my thought:
- we could make the
Divfunction only apply for latex output format in the lua filter. Noreturn nilrequired, and no risk to conflict withfenced_divsfor other format ? - That way if no
data-latex=is provided, we could generate averbatimenvironment, and otherwisedata-latexshould be provided to set options.
I don't think this will break anything, just change the way the lua filter is activated, to make this type of example works
https://bookdown.org/yihui/rmarkdown-cookbook/multi-column-layout.html
I have something like this in mind
Div = function (div)
local options = div.attributes['data-latex']
-- if the output format is not latex, the object is left unchanged
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
return div
end
local env = div.classes[1]
-- if the div has no class, the object is left unchanged
if not env then return nil end
-- insert raw latex before content
table.insert(
div.content, 1,
pandoc.RawBlock('tex', '\\begin' .. '{' .. env .. '}' .. (options or ""))
)
-- insert raw latex after content
table.insert(
div.content,
pandoc.RawBlock('tex', '\\end{' .. env .. '}')
)
return div
end