Skip to content
Prev 4289 / 12125 Next

[R-pkg-devel] Literal LaTeX Text in Function Arguments

It seems that expansion of \ldots occurs in two different circumstances. 

1) The Rd2XXX converters treat specially \ldots and \dots but in different ways. tools::Rd2latex() defines in its body texify(), which, when called with a piece of R code, starts by replacing \ldots and \dots with        

     x <- psub("\\\\[l]{0,1}dots", "...", as.character(x))

Similarly, Rd2ex(), defines a function remap() which does a similar thing. The 'html' and 'txt' renderers also treat specially \dots and \ldots but only in more restricted cases. I didn't find what 'R CMD check' does. 

This might explain the differences between 'html'  and 'text' on the one hand, and 'pdf' output on the other hand. 
(as Duncan pointed out, he didn't see this in html).

But macros starting with '\l'  seem to be expanded in R code in all formats, if the backslash is not escaped, example a) below illustrates this. I redefined '\ldots' to demonstrate that this is  not due to the special treatment that literally replaces \ldots with '...' as above. I think this follows from the specification of Rd format p. 8 of the 'parseRd' document  referenced in my previous email. 


For illiustration, I added the following lines before the Usage section in Bill's file topic_long_table_header.Rd.

\renewcommand{\ldots}{Aaaargh }
\renewcommand{\lmydots}{Uuugh }
\renewcommand{\mydots}{this is mydots }

Here the Usage entry for the shown argument  only is modified (with 3 backslashes)

topic_long_table_header(x, col_names = NULL,
  (not changed)
  subsequent_page_notification = "\\\ldots continued \\\lmydots \\\mydots",
  (not changed)
   )

In the pdf file we see 

    subsequent_page_notification = "\Aaaargh continued \Uuugh \\mydots"

\ldots and \lmydots are expanded but \mydots is not. I believe that \lmydots is expanded since it starts with 'l', see my previous email. In this case, 'R CMD check' gives an additional warning about the unescaped backslash: 

    ...
    subsequent_page_notification = "<unescaped bksl>Aaaargh  continued \Uuugh  \\mydots"

This seems to happen since an attempt is made later to parse \Aaaargh and \Uuugh. If the Rd entry in the Usage section contaiin only one backslash, as in  
     subsequent_page_notification = "\ldots continued \lmydots \\\mydots",

then we get in all renderings: 

    subsequent_page_notification = "Aaaargh continued Uuugh \\mydots"

'R CMD check' also shows this text (and complains, since it obviously is not as in the function deifnition,



b) With proper escaping (using 4, instead of 3 backslashes above) we get (in the pdf rendering):

subsequent_page_notification = "\... continued \\lmydots \\mydots"

\ldots is expanded but the other macros are not. Note that the expansion of \ldots here is due is due to the specific rendering for LaTeX, which replaces \\ldots by three dots (...), and doesn't use my Rd definition for \ldots, suggesting that  this occurs at a different place.


Georgi Boshnakov