How to display exponents properly in R documentation files

I need help with formatting mathematical expressions in R documentation. I’m trying to add exponents to my function documentation but they’re not showing up correctly.

When I write \eqn{3^{y}} in my documentation file, the exponent doesn’t appear as superscript after I build the package. The expression just shows as plain text instead of proper mathematical notation.

I checked the official R documentation examples and found references to dpois.Rd which supposedly shows correct exponent formatting. However when I look at the actual help page using ?dpois, I don’t see any superscript formatting there either.

Is this normal behavior or could there be something wrong with my R setup? I’m wondering if mathematical formatting in R help files only works in certain contexts or requires special configuration.

Has anyone else experienced this issue with mathematical notation in R documentation? Any suggestions would be appreciated.

for sure! i had the same issue when i started. make sure ur compilin the docs in html, otherwise u’ll miss out on the formatting like exponents. just do help(your_function, help_type="html"). and yeah, remember to use double backslashes in your .Rd files, it helps avoid issues!

Math formatting in R docs depends on where you’re viewing them. The \eqn{} command behaves differently across help viewers. When you use ?dpois in the console, you’re seeing text-based help that strips formatting like superscripts. Proper mathematical notation only shows up in HTML help or PDF docs. Try help(dpois, help_type="html") instead - you’ll see the exponents as actual superscripts. If you’re building a package, the math expressions render correctly in HTML documentation or when it’s on CRAN. For complex expressions, consider \deqn{} for display equations instead of inline \eqn{}. What you’re seeing is normal behavior for R’s default text-based help system.

This is totally normal and caught me off guard when I first started writing R packages too. R’s help system has multiple rendering engines, and math notation only works in certain formats. When you use ?function or help(), you’re getting text-based help that can’t render math symbols or superscripts. That’s why your \eqn{3^{y}} shows up as plain text. The math formatting is actually there in your docs - the text viewer just strips it out. To see your exponents formatted properly, you need the HTML version. Set options(help_type="html") in your R session, or use RStudio’s help pane which automatically shows the HTML version. Then your \eqn{3^{y}} will render with proper superscripts. This text vs HTML help distinction trips up tons of package developers at first, but it makes sense once you get it.