Skip to content

Lost braces #1578

@bastistician

Description

@bastistician

Markdown mode in roxygen2 does not escape braces and this seems to be intended:

# Non code parts are not escaped (invalid Rd)
expect_equal(markdown("[foo({ bar })][x]"), "\\link[=x]{foo({ bar })}")

However, many developers don't know that braces need to be escaped in LaTeX-like text in Rd. For example, Rd authors commonly use markup like \pkg{pkgname}, but I have seen markdown-type documentation with roxygen2 using the {pkgname} notation to refer to an R package, where these braces are expected to appear in the rendered documentation. This won't happen, unfortunately:

library("roxygen2")
out <- roc_proc_text(rd_roclet(), "
  #' {pkgname}: Playing with Braces
  #'
  #' Plain-text math: integer in {1, 2, ..., n}, (-1)^{n-1}
  #' @md
  null <- function () NULL
")[[1]]

out
#> % Generated by roxygen2: do not edit by hand
#> % Please edit documentation in ./<text>
#> \name{null}
#> \alias{null}
#> \title{{pkgname}: Playing with Braces}
#> \usage{
#> null()
#> }
#> \description{
#> Plain-text math: integer in {1, 2, ..., n}, (-1)^{n-1}
#> }

rdfile <- tempfile()
cat(out$format(), file = rdfile)
tools::Rd2txt(rdfile)
#> pkgname: Playing with Braces
#> 
#> Description:
#> 
#>      Plain-text math: integer in 1, 2, ..., n, (-1)^n-1
#> 
#> Usage:
#> 
#>      null()
#> 

tools::checkRd(rdfile)
#> checkRd: (-3) file2c241344a233:5: Lost braces
#>      5 | \title{{pkgname}: Playing with Braces}
#>        |        ^
#> checkRd: (-3) file2c241344a233:10: Lost braces
#>     10 | Plain-text math: integer in {1, 2, ..., n}, (-1)^{n-1}
#>        |                             ^
#> checkRd: (-3) file2c241344a233:10: Lost braces
#>     10 | Plain-text math: integer in {1, 2, ..., n}, (-1)^{n-1}
#>        |                                                  ^

I think it would be nice if roxygen2 could escape the braces "as necessary" when it generates the Rd code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions