From hin-tak.leung at cimr.cam.ac.uk  Mon Nov 21 11:18:25 2005
From: hin-tak.leung at cimr.cam.ac.uk (Hin-Tak Leung)
Date: Mon, 21 Nov 2005 10:18:25 +0000
Subject: [Rd] problem with \eqn (PR#8322)
In-Reply-To: <17278.11673.761366.759409@mithrandir.hornik.net>
References: <20051117215558.33EB422485@slim.kubism.ku.dk>	<437E0384.604@cimr.cam.ac.uk>	<17278.3526.762256.703178@stat.math.ethz.ch>	<437E11F7.6010604@cimr.cam.ac.uk>	<437E1993.5020804@stats.uwo.ca>
	<17278.11673.761366.759409@mithrandir.hornik.net>
Message-ID: <43819EF1.7000908@cimr.cam.ac.uk>

Kurt Hornik wrote:
>>>>>>Duncan Murdoch writes:
> 
> 
>>On 11/18/2005 12:40 PM, Hin-Tak Leung wrote:
>>
>>>Martin Maechler wrote:
>>>
>>>
>>>>>>>>>"Hin-Tak" == Hin-Tak Leung <hin-tak.leung at cimr.cam.ac.uk>
>>>>>>>>>on Fri, 18 Nov 2005 16:38:28 +0000 writes:
>>>>
>>>>
> Hin-Tak> Your own fault. See below. It is basic LaTeX and any LaTeX person
> Hin-Tak> can tell you the answer...(most probably haven't bothered...)
> 
>>>>No.  Whereas I partly agree that it's Ross ``fault'' trying to
>>>>use too smart LaTex (and using outdated \bf instead of \mathbf), 
>>>>;-)
>>>>
>>>>The bug is really there, since we are talking about the Rd "language",
>>>>not LaTeX, an in Rd,  \eqn and \deqn are defined to have either
>>>>one or two arguments -- where Ross used the 2-argument version
>>>>correctly (in principle at least) --> See the manual "Writing R
>>>>Extensions".
>>>
>>>
>>>Forgive me for not reading R-ext carefully, but Ross's Rd code is
>>>still "obviously" wrong in the lights of the two-argument \eqn:
>>>(really doesn't differ from the 1-arg interpretaion of \eqn)
>>>
>>>\eqn{{\bf\beta}_j}{\bf\beta}_jnormal-bracket5bracket-normal{b(j)}
>>>
>>>In other words,
>>>\eqn{...}{...}_...
>>>
>>>and the "_" is still outside of any maths environment, which is most
>>>probably not Ross's intention.
> 
> 
>>But that is Latex code produced by R, not Rd code produced by Ross.
>>The bug is in the Latex production (which I think is done by
>>share/perl/R/Rdconv.pm, but I don't know Perl well enough to attempt
>>to fix it).
> 
> 
> Definitely a problem in Rdconv.
> 
> E.g.,
> 
> $ cat foo.Rd 
> \description{
>   \eqn{{A}}{B}
> }
> hornik at mithrandir:~/tmp$ R-d CMD Rdconv -t latex foo.Rd | grep eqn
> \eqn{{A}}{A}{{B}
> 
> shows what is going on.
> 
> My reading of R-exts would suggest that it is not necessary to escape
> braces inside \eqn (and in fact these are not unescaped by Rdconv).
> 
> Btw, the conversions of the above example are wrong for at least HTML
> and text as well, giving
> 
>   <i>A</i>{{B}
> 
> and
> 
>   A{{B}
> 
> respectively.

Apologies - the problem is with this section of "share/perl/R/Rdconv.pm"
around line 400 - it basically doesn't try very hard dealing with nested 
brackets.

=======================
## Get the arguments of a command.
sub get_arguments {
     my ($command, $text, $nargs) = @_;
     ## Arguments of get_arguments:
     ##  1, command: next occurence of 'command' is searched
     ##  2, text:    'text' is the text containing the command
     ##  3, nargs:   the optional number of arguments to be extracted;
     ##              default 1
     my @retval;
     ## Returns a list with the id of the last closing bracket and the
     ## arguments.

     if($text =~ /\\($command)(\[[^\]]+\])?($ID)/){
         $id = $3;
         $text =~ /$id(.*)$id/s;
         $retval[1] = $1;
         my $k=2;
         while(($k<=$nargs) && ($text =~ /$id($ID)/)){
             $id = $1;
             $text =~ /$id\s*(.*)$id/s;
             $retval[$k++] = $1;
         }
     }
     $retval[0] = $id;
     @retval;
}
==================

HT



[Rd] problem with \eqn (PR#8322)
Hin-Tak Leung