[Rd] Rd macros are not expanded inside of \eqn{} or \deqn{}

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Mon Jun 12 20:19:44 CEST 2023


A description of the format is given in this document:

   https://developer.r-project.org/parseRd.pdf

As far as I know that document is still up to date.  As it says in Table 
3, \eqn and \deqn take "Verbatim" arguments.  That mode is described in 
the introduction to Section 2; it contains text and comments, so by 
design no macros are expanded.

I think it's unlikely that this would change.  The problem is that the 
equation markup can contain LaTeX macros.  So the parser would have to 
have a new mode where it distinguished between LaTeX macros and Rd 
macros.  But then how would you write true verbatim text, where you're 
trying to discuss the macros?  It gets complicated very quickly.

What you could conceivably do is write your own macro that passed its 
content to R code that expanded your user-defined macros. It sounds 
complicated, and would probably be hard to get right.

Duncan Murdoch

On 12/06/2023 1:55 p.m., Mikael Jagan wrote:
> I was a bit surprised to learn that, if one has an Rd file as below:
> 
>       %% zzz.Rd
>       \newcommand{\zzz}{whatever}
>       \name{zzz}
>       \title{zzz}
>       \description{ \zzz{} \eqn{\zzz{}} \deqn{\zzz{}} }
> 
> then the macro is _not_ expanded inside of \eqn{} or \deqn{} when parsed to text
> or HTML.  Is this behaviour intentional?  Could it be changed?  Inside of \eqn{}
> and \deqn{} is where I am _most_ likely to want to use macros, at least since
> R 4.2.0, which added KaTeX support ...
> 
> See output pasted below.
> 
> Mikael
> 
>   > tools::Rd2txt(tools::parse_Rd("zzz.Rd"))
> zzz
> 
> Description:
> 
>        whatever \zzz{}
> 
>                                      \zzz{}
> 
>   > tools::Rd2HTML(tools::parse_Rd("zzz.Rd"))
> <!DOCTYPE html><html><head><title>R: zzz</title>
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
> <meta name="viewport" content="width=device-width, initial-scale=1.0,
> user-scalable=yes" />
> <link rel="stylesheet"
> href="https://cdn.jsdelivr.net/npm/katex@0.15.3/dist/katex.min.css">
> <script type="text/javascript">
> const macros = { "\\R": "\\textsf{R}", "\\code": "\\texttt"};
> function processMathHTML() {
>       var l = document.getElementsByClassName('reqn');
>       for (let e of l) { katex.render(e.textContent, e, { throwOnError: false,
> macros }); }
>       return;
> }</script>
> <script defer src="https://cdn.jsdelivr.net/npm/katex@0.15.3/dist/katex.min.js"
>       onload="processMathHTML();"></script>
> <link rel="stylesheet" type="text/css" href="R.css" />
> </head><body><div class="container">
> 
> <table style="width: 100%;"><tr><td>zzz</td><td style="text-align: right;">R
> Documentation</td></tr></table>
> 
> <h2 id='zzz'>zzz</h2>
> 
> <h3>Description</h3>
> 
>    <p>whatever <code class="reqn">\zzz{}</code> </p>
> <p style="text-align: center;"><code class="reqn">\zzz{}</code>
> </p>
> 
> 
> </div>
> </body></html>
> 
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list