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 -------- Original Message -------- Subject: plotmath in underlined style; was: Re: [R] Underline in expression(). Date: Sun, 26 Sep 2004 18:50:02 +0200 From: Uwe Ligges <[EMAIL PROTECTED]> Organization: Fachbereich Statistik, Universitaet Dortmund To: John Janmaat <[EMAIL PROTECTED]>, [EMAIL PROTECTED] CC: [EMAIL PROTECTED] References: <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> 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 >> >> ______________________________________________ >> [EMAIL PROTECTED] 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" --- y:\recent\R\src\library\grDevices\man\plotmath.Rd 2004-09-26 18:34:28.000000000 +0200 +++ plotmath.Rd 2004-09-26 18:25:22.000000000 +0200 @@ -91,6 +91,7 @@ \code{textstyle(x)} \tab draw x in normal size \cr \code{scriptstyle(x)} \tab draw x in small size \cr \code{scriptscriptstyle(x)} \tab draw x in very small size \cr + \code{underline(x)} \tab draw x underlined\cr \code{x ~~ y} \tab put extra space between x and y \cr \code{x + phantom(0) + y} \tab leave gap for "0", but don't draw it \cr \code{x + over(1, phantom(0))} \tab leave vertical gap for "0" (don't draw) \cr --------------060203010607060006000807 Content-Type: text/plain; name="plotmath.c.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="plotmath.c.diff" --- y:\recent\R\src\main\plotmath.c 2004-09-26 18:31:11.000000000 +0200 +++ plotmath.c 2004-09-26 18:48:17.000000000 +0200 @@ -1806,6 +1806,46 @@ return CombineAlignedBBoxes(numBBox, denomBBox); } +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-- ______________________________________________ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-devel