GeoBosh / rbibutils

Convert bibliography files between various formats, including BibTeX, BibLaTeX, PubMed, RIS, and Bibentry. This is an R port of the bibutils utilities plus R manipulation of bibiliography objects.
https://geobosh.github.io/rbibutils/
13 stars 1 forks source link

Warning in parse_Rd(tmpcon, encoding = "UTF-8", fragment = TRUE, macros = macros) : unknown macro '\slash' #9

Closed MLopez-Ibanez closed 9 hours ago

MLopez-Ibanez commented 2 months ago
@misc{key,
title = "Something\slash Something",
author = "John Smith",
}

It seems rbibutils does not convert \slash to / when translating from BibTeX to Rd. The main difference between writing / and \slash in LaTeX is that "and/or" will never allow a linebreak after "/" but "and\slash or" does allow it" (not sure how to express this in Rd format).

GeoBosh commented 2 months ago

Thanks, it is sensible to fix this. The simplest would be to replace \slash with /. A complete Rd solution could be based on \if{latex} ... else ....

It may take some time as the teaching is starting.

MLopez-Ibanez commented 2 months ago

No hurry, I just wanted to document this issue somewhere.

GeoBosh commented 1 day ago

Did you get the warning in the title when building (the documentation of) a package?

A reproducible example (for testing a fix later):

slash_bib <- charToBib('@misc{key,
title = "Something\\slash Something",
author = "John Smith",
}', direct = TRUE)

## this is a simplified version of what insert_ref does:
toRd(slash_bib)
## [1] "Smith J (????).\n\\dQuote{Something\\slash Something.}"

slash_bib
## Smith J (????). "Something\slash Something."

print(slash_bib, style = "html")
## <p>Smith J (????).
## &ldquo;Something\slash Something.&rdquo; 
## </p>

print(slash_bib, style = "latex")
## Smith J (????).
## ``Something\bsl{}slash Something.''

It looks like a new Rdmacro \slash, which conditionally export / or \slash might be the most suitable solution.

GeoBosh commented 8 hours ago

I fixed this in Rdpack, see above.

The current solution is to emit an ifelse instruction which keeps \slashfor latex but replaces it with slash,/`, otherwise.

For the record, a solution based on introducing a new Rd macro \slash does not work for 'pkgdown' as that doesn't use user macros for parsing Rd, except when initially reading the Rd file. So, it the text returned by the reference macros contains a user macro like \slash, its definition is not passed on to the parser. Also, although it works for the various formats of R documentation (produced by R), it would be tricky to gobble the whitespace after \slash in a macro.

More testing is needed, please feel free to reopen the issue if something is wrong.