[Rd] plotmath in underlined style; was: Re: [R] Underline in expression(). (PR#7286)

From: <ligges_at_statistik.uni-dortmund.de>
Date: Thu 14 Oct 2004 - 20:06:20 EST


This is a multi-part message in MIME format.

--------------060203010607060006000807
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

In order not to forget it (I have not got any answer so far) ...

Uwe Ligges

Please find attach a patch to include the feature to draw underlined mathematical annotation.

Here is an example according to the feature request given below:

    plot(0:1, 0:1, type="n")
    text(0.5, 0.5, expression(underline(widehat(x %*% y))))

Since I am too late for R-2.0.0, should I send this one to r-bugs so that we do not forget?

Uwe

John Janmaat wrote:

> Sundar,
> 
> Thanks.  Unfortunately, I am looking for something that also works in 
> the margins of the plot.
> 
> John.
> 
> Sundar Dorai-Raj wrote:
> 

>>
>>
>> John Janmaat wrote:
>>
>>> Hello All,
>>>
>>> Is there an analogue to \underbar or the AMS math \underline in
>>> graphical math expressions?
>>>
>>> Thanks,
>>>
>>> John.
>>
>>
>>
>> Uwe Ligges posted a solution a couple of years ago. I don't know if
>> there is anything built in yet. ?plotmath does not seem to say
>> anything about underlining.
>>
>> http://finzi.psych.upenn.edu/R/Rhelp01/archive/7191.html
>>
>> plot(0:1, 0:1, type="n")
>> underlined(0.5, 0.5, expression(widehat(x %*% y)))
>>
>> --sundar
>>
>> ______________________________________________
>> R-help@stat.math.ethz.ch mailing list
>> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>>
>

--------------060203010607060006000807
Content-Type: text/plain;
 name="plotmath.Rd.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="plotmath.Rd.diff"

--------------060203010607060006000807
Content-Type: text/plain;
 name="plotmath.c.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="plotmath.c.diff"

+static BBOX RenderUnderline(SEXP expr, int draw, mathContext *mc, R_GE_gcontext *gc, GEDevDesc *dd)
+{
+    SEXP body = CADR(expr);
+    BBOX BBox;
+    double width, adepth, depth, x[2], y[2];
+    double savedX = mc->CurrentX;
+    double savedY = mc->CurrentY;
+
+    BBox = RenderItalicCorr(RenderElement(body, 0, mc, gc, dd), 0, mc, gc, dd);
+    width = bboxWidth(BBox);
+
+    mc->CurrentX = savedX;
+    mc->CurrentY = savedY;
+    BBox = RenderElement(body, draw, mc, gc, dd);
+    adepth = 0.1 * XHeight(gc, dd);
+    depth = bboxDepth(BBox) + adepth;
+
+    if (draw) {
+        int savedlty = gc->lty;
+        double savedlwd = gc->lwd;
+        mc->CurrentX = savedX;
+        mc->CurrentY = savedY;
+        PMoveUp(-depth, mc);
+        x[0] = ConvertedX(mc, dd);
+        y[0] = ConvertedY(mc, dd);
+        PMoveAcross(width, mc);
+        x[1] = ConvertedX(mc, dd);
+        y[1] = ConvertedY(mc, dd);
+        gc->lty = LTY_SOLID;
+        gc->lwd = 1;
+        GEPolyline(2, x, y, gc, dd);
+        PMoveUp(depth, mc);
+        gc->lty = savedlty;
+        gc->lwd = savedlwd;
+        PMoveTo(savedX + width, savedY, mc);
+    }
+    return EnlargeBBox(BBox, 0.0, adepth, 0.0);
+}
+
+

 static int OverAtom(SEXP expr)
 {

     return NameAtom(expr) &&
@@ -1817,6 +1857,17 @@

     return RenderFraction(expr, 1, draw, mc, gc, dd);  }  

+static int UnderlAtom(SEXP expr)
+{
+    return NameAtom(expr) && NameMatch(expr, "underline");
+}
+
+static BBOX RenderUnderl(SEXP expr, int draw, mathContext *mc, R_GE_gcontext *gc, GEDevDesc *dd)
+{
+    return RenderUnderline(expr, draw, mc, gc, dd);
+}
+
+

 static int AtopAtom(SEXP expr)
 {

     return NameAtom(expr) && NameMatch(expr, "atop"); @@ -2809,6 +2860,8 @@

     return RenderAccent(expr, draw, mc, gc, dd);
     else if (OverAtom(head))
     return RenderOver(expr, draw, mc, gc, dd);
+ else if (UnderlAtom(head))
+ return RenderUnderl(expr, draw, mc, gc, dd);
     else if (AtopAtom(head))
     return RenderAtop(expr, draw, mc, gc, dd);
     else if (ParenAtom(head))


--------------060203010607060006000807--



R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu Oct 14 20:22:42 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:45:21 EST