Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make latex-div lua filter apply only on latex output and no need for data-latex="" #1779

Closed
cderv opened this issue Feb 29, 2020 · 3 comments

Comments

@cderv
Copy link
Collaborator

cderv commented Feb 29, 2020

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 Div function only apply for latex output format in the lua filter. No return nil required, and no risk to conflict with fenced_divs for other format ?
  • That way if no data-latex= is provided, we could generate a verbatim environment, and otherwise data-latex should 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
@yihui yihui closed this as completed in 14127ac Apr 7, 2020
@yihui
Copy link
Member

yihui commented Apr 7, 2020

The new Div filter you proposed looks good to me. I just applied the code. Thank you very much!

@yihui
Copy link
Member

yihui commented Jun 21, 2020

Continuing from rstudio/bookdown#883 (comment).

Requiring the data-latex attribute will also solve #1815 elegantly (I know you probably can't read Chinese). I couldn't apply the Lua filter to beamer_presentation because Pandoc reserved some special fenced Divs for beamer and we must not convert them to LaTeX environments in our way. If we require the data-latex attribute, these reserved Divs won't be affected because they don't have the data-latex attribute.

jonathan-g added a commit to jonathan-g/rmarkdown that referenced this issue Jul 7, 2020
* rstudio/master: (61 commits)
  make metadata available before running pre_knit (rstudio#1855)
  fix rstudio#1815: apply the lua filters pagebreak.lua and latex-div.lua to beamer_presentation
  require the data-latex attribute on fenced Div's again: rstudio#1779 (comment)
  start the next version
  CRAN release v2.3
  fold any code blocks with the class `foldable` for html_document output (rstudio#1835)
  fix rstudio#1828: add aria-hidden = "true" to empty <a> tags in highlighted code blocks generated by Pandoc to improve screen reader accessibility (rstudio#1833)
  add a news item for rstudio#1832
  roxygenize
  no need to turn on --file-scope or actually write the split content into files if the split content is of length < 2
  eliminate renumber_footnotes option
  only test two pandoc versions (devel and RStudio version) and upgrade default to 2.7.3 (rstudio#1846)
  close rstudio#1838: test more R versions on Travis (rstudio#1845)
  renumber_footnotes output format option
  add the <div class="kable-table"> only when the output format is HTML, otherwise the div will be converted to a LaTeX environment, leading to the bug https://stackoverflow.com/q/62340425/559676
  change name of file_scope argument to references_scope
  re-roxygenize
  Add `publish_site()` function for "one-button" publishing of R Markdown websites.
  Enable use of pandoc --file-scope for input files originating from multiple Rmds (rstudio#1837)
  Added missing lang attribute to ioslides_presentation template (rstudio#1841)
  ...
clrpackages pushed a commit to clearlinux-pkgs/R-rmarkdown that referenced this issue Oct 6, 2020
… 2.4

Christophe Dervieux (7):
      add lua filter vignette to pkgdown website (#1894)
      only install pkgdown for website build (#1900)
      Add an argument `lua_filters` to pandoc_options() to store them in the output format object (#1899)
      lua filter -> Lua filter
      bump version after merging #1899
      Export pkg_file_lua for package author to use (#1904)
      bump patch version

J.J. Allaire (1):
      Discover site generators in index.Rmd files in parent directories (#1898)

Jonathan Gilligan (2):
      Fix #1861: do not use backslashes as path-separators in CSS links (#1862)
      Add documentation about how render() sets output_format options from YAML parameters (#1907)

JooYoung Seo (1):
      support number_sections for word_document() output (#1869)

Kirill Müller (1):
      close #1889: evaluate the output argument before changing working directory in pandoc_convert() (#1890)

Yihui Xie (26):
      start the next version
      require the data-latex attribute on fenced Div's again: rstudio/rmarkdown#1779 (comment)
      fix #1815: apply the lua filters pagebreak.lua and latex-div.lua to beamer_presentation
      replace base64enc with xfun::base64_encode/decode()
      xfun 0.16 is on CRAN now
      require Pandoc >= 1.14
      tweak news
      add the citation entry for the R Markdown Cookbook
      enable figure cropping in pdf_document() only when both pdfcrop and ghostscript are found (yihui/knitr#954), and do not limit this feature to non-Windows platforms
      generalize the package_root() function to work with more types of projects
      rename package_root() to proj_root()
      use our own proj_root() instead of introducing a dependency
      list.files() with full.names = TRUE (so the files could be read with corret paths), and pass down the `file`/`pattern` arguments in the recursion
      also suppor dir input in proj_root()
      recursve into the parent dir at the end
      add news for #1878
      tweak news and docs of #1904
      system.file() will signal a similar error when length(package) != 1, so we don't need to repeat the message here (i.e., just let system.file() fail)
      make sure the rmarkdown/lua/ folder exists
      amend #1907: the @param field doesn't allow more than one paragraph, so we shouldn't add an empty line here
      fix the redirected URL
      remove the pandoc installation vignette, which is no longer useful
      fix some redirected URLs discoverd by R CMD check on win-builder
      fix some redirected URLs discovered by the CRAN incoming check (but not the check on win-builder, which is very weird...)
      enable _R_CHECK_CRAN_INCOMING_ for r-devel, to see if it could reveal potentially "problematic" URLs as CRAN currently tries to identify
      CRAN release v2.4

atusy (6):
      make metadata available before running pre_knit (#1855)
      Generalize number sections (#1879)
      fix #1905: a chunk with the class "fold-hide" should only hide itself (#1906)
      incorporate CSS styles from latest Pandoc's tempalte (#1878)
      also incorporate CSS styles from latest Pandoc's template into ioslides (#1908)
      fix #457 and fix #1864: add `template` to `output_render_files` of discover_rmd_resources() (#1865)
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants