Bug 14751 - backslashes not properly escaped in \preformat environments in .Rd files
backslashes not properly escaped in \preformat environments in .Rd files
Status: RESOLVED FIXED
Product: R
Classification: Unclassified
Component: Misc
R 2.14.0
x86_64/x64/amd64 (64-bit) Linux
: P5 minor
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-12-07 16:02 UTC by Gray Calhoun
Modified: 2011-12-09 14:33 UTC (History)
2 users (show)

See Also:


Attachments
Patch to R 2.14.0 (827 bytes, text/plain)
2011-12-07 16:02 UTC, Gray Calhoun
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gray Calhoun 2011-12-07 16:02:23 UTC
Created attachment 1255 [details]
Patch to R 2.14.0

Hi,

The "\preformatted" environment in Rd files doesn't seem to escape
long sequences of backslashes properly when converted to pdf (LaTeX)
documentation.  I'm using R version 2.14.0 Patched (r57839) Here's an example from the command line:

echo "\title{test}\name{test}\section{problems}{\preformatted{print('\\\\\\\\\\\\\\\\begin\\\\\\\\\{block\\\\\\\\\}')}}" > temp.Rd
R CMD Rdconv --type=latex temp.Rd

which outputs:

\inputencoding{utf8}
\HeaderA{test}{test}{test}
%
\begin{Section}{problems}
\begin{alltt}print('\\\\begin\\{block\\}')\end{alltt}
\end{Section}

and the double backslashes become newlines when this text is embedded
in a complete document and converted to pdf.  I expected from the
documentation to get this:

\inputencoding{utf8}
\HeaderA{test}{test}{test}
%
\begin{Section}{problems}
\begin{alltt}print('\bsl{}\bsl{}\bsl{}\bsl{}begin\bsl{}\bsl{}\{block\bsl{}\bsl{}\}')\end{alltt}
\end{Section}

The problem seems to come from tools:::Rd2latex as this R code indicates:

library(tools)
tools:::Rd2latex(textConnection("\\title{test}\\name{test}
\\section{problems}{
\\preformatted{
print('\\\\\\\\\\\\\\\\begin\\\\\\\\\\{block\\\\\\\\\\}')
}}"))

(the output is the same as from the command line above)

I can get the behavior that I want by removing a few lines from the
relevant part of tools:::Rd2latex and I've attached a patch, but I
assume that the code that I removed was put there for a good reason so
this isn't a good fix.  make check-devel didn't find any errors after applying the patch, though.

On a possibly related note: does the replacement on \var belong in the (inPre) condition?  The documentation for \preformatted in "Writing R Extensions" reads:

"\preformatted{text}
   Indicate text that is a literal example of a piece of a program.
Text is displayed using typewriter font if possible. Formatting, e.g.
line breaks, is preserved.

   Due to limitations in LaTeX as of this writing, this macro may not
be nested within other markup macros other than \dQuote and \sQuote,
as errors or bad formatting may result."

which doesn't indicate that \var should be handled any differently
than any other macro, but the code makes me think that R is trying to
pass the macro through to LaTeX.

Thanks!
Comment 1 Duncan Murdoch 2011-12-08 02:02:39 UTC
I'll look into this.   It should be fixed in time for 2.14.1.

Duncan Murdoch

On 07/12/2011 10:02 AM, r-bugs@r-project.org wrote:
> https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14751
>
>             Summary: backslashes not properly escaped in \preformat
>                      environments in .Rd files
>             Product: R
>             Version: R 2.14.0
>            Platform: x86_64/x64/amd64 (64-bit)
>          OS/Version: Linux
>              Status: NEW
>            Severity: minor
>            Priority: P5
>           Component: Misc
>          AssignedTo: R-core@R-project.org
>          ReportedBy: gray.calhoun@gmail.com
>     Estimated Hours: 0.0
>
>
> Created an attachment (id=1255)
>   -->  (https://bugs.r-project.org/bugzilla3/attachment.cgi?id=1255)
> Patch to R 2.14.0
>
> Hi,
>
> The "\preformatted" environment in Rd files doesn't seem to escape
> long sequences of backslashes properly when converted to pdf (LaTeX)
> documentation.  I'm using R version 2.14.0 Patched (r57839) Here's an example
> from the command line:
>
> echo
> "\title{test}\name{test}\section{problems}{\preformatted{print('\\\\\\\\\\\\\\\\begin\\\\\\\\\{block\\\\\\\\\}')}}"
> >  temp.Rd
> R CMD Rdconv --type=latex temp.Rd
>
> which outputs:
>
> \inputencoding{utf8}
> \HeaderA{test}{test}{test}
> %
> \begin{Section}{problems}
> \begin{alltt}print('\\\\begin\\{block\\}')\end{alltt}
> \end{Section}
>
> and the double backslashes become newlines when this text is embedded
> in a complete document and converted to pdf.  I expected from the
> documentation to get this:
>
> \inputencoding{utf8}
> \HeaderA{test}{test}{test}
> %
> \begin{Section}{problems}
> \begin{alltt}print('\bsl{}\bsl{}\bsl{}\bsl{}begin\bsl{}\bsl{}\{block\bsl{}\bsl{}\}')\end{alltt}
> \end{Section}
>
> The problem seems to come from tools:::Rd2latex as this R code indicates:
>
> library(tools)
> tools:::Rd2latex(textConnection("\\title{test}\\name{test}
> \\section{problems}{
> \\preformatted{
> print('\\\\\\\\\\\\\\\\begin\\\\\\\\\\{block\\\\\\\\\\}')
> }}"))
>
> (the output is the same as from the command line above)
>
> I can get the behavior that I want by removing a few lines from the
> relevant part of tools:::Rd2latex and I've attached a patch, but I
> assume that the code that I removed was put there for a good reason so
> this isn't a good fix.  make check-devel didn't find any errors after applying
> the patch, though.
>
> On a possibly related note: does the replacement on \var belong in the (inPre)
> condition?  The documentation for \preformatted in "Writing R Extensions"
> reads:
>
> "\preformatted{text}
>     Indicate text that is a literal example of a piece of a program.
> Text is displayed using typewriter font if possible. Formatting, e.g.
> line breaks, is preserved.
>
>     Due to limitations in LaTeX as of this writing, this macro may not
> be nested within other markup macros other than \dQuote and \sQuote,
> as errors or bad formatting may result."
>
> which doesn't indicate that \var should be handled any differently
> than any other macro, but the code makes me think that R is trying to
> pass the macro through to LaTeX.
>
> Thanks!
>



Comment 2 Duncan Murdoch 2011-12-09 14:33:44 UTC
Fixed in R-patched and R-devel.