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

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

Closed
MLopez-Ibanez opened this issue Sep 7, 2024 · 5 comments

Comments

@MLopez-Ibanez
Copy link

MLopez-Ibanez commented Sep 7, 2024

@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
Copy link
Owner

GeoBosh commented Sep 7, 2024

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
Copy link
Author

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

@GeoBosh
Copy link
Owner

GeoBosh commented Nov 7, 2024

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
Copy link
Owner

GeoBosh commented Nov 8, 2024

I fixed this in Rdpack, see above.

The current solution is to emit an ifelse instruction which keeps \slash for 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.

@GeoBosh
Copy link
Owner

GeoBosh commented Nov 15, 2024

in Rdpack v2.6.2, now on CRAN

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jan 1, 2025
# Rdpack 2.6.2

- `RStudio_reprompt` now issues a more informative error message when not called
  on a suitable file or function. Fixes issue #30, reported by @daattali.

- now the LaTeX macro `\slash` is wrapped in a condition, so that it is passed
  on for LaTeX related output but converted to `/` for other formats (such as
  html). Fixes GeoBosh/rbibutils#9, reported by @MLopez-Ibanez.

- fixed the test for the fix in Rdpack v2.6.1 (see below) to work with R-4.4.2,
  since that R-devel change was not carried on to R-4.4.2.  (Note: the error
  concerns the test only. The fix in the code of the package works for any R
  version.) Fixes issue #37, reported by @charles-plessy.


# Rdpack 2.6.1

- R-devel c86938 turned to error the warning for a non-existing key in the bib
  file. Fixed `insert_bib` (and a related test) to handle that.


# Rdpack 2.6

- fixed issues causing 'lost braces' (actually, superfluous braces) NOTEs from
  checks in R-devel occuring with some accented LaTeX characters. These NOTEs
  are not yet activated on CRAN but if/when they do, developers using Rd macros
  `\insertRef` and `\insertCite` can eliminate them by building their packages
  with Rdpack (>= 2.6) and rbibutils (>= 2.2.16).  Thanks to Sebastian Meyer for
  tracing down the issues.

- fixed a `Sweave` expression in 'man/predefined.Rd' to not emit unnecessary
  braces (see the note above).


# Rdpack 2.5

- Rd macros `insertCite` and friends were calling `\insert_citeOnly()` with
  argument `key` instead of `keys`. This was not an error since partial matching
  is ok here but not good practice. Fixes issue #28 reported by Marcel Ramos.

- changed the saved value in "tests/testthat/dummyArticle.rds" used in
  'test-bib.R' with a value obtained with R-devel r84896 n previu versins of R
  there wasasuperfluous final ' .').

- in some cases when square brackets were requested, rather than round ones,
  `\insertCiteOnly` was using closing round parenthesis.

- in some cases `\insertCiteOnly` was not handling well the last cite when it
  was followed by free text.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants