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.
Markdown mode in roxygen2 does not escape braces and this seems to be intended:
roxygen2/tests/testthat/test-markdown-link.R
Lines 61 to 62 in 47e1c76
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:I think it would be nice if roxygen2 could escape the braces "as necessary" when it generates the Rd code.