TransWikia.com

Stretchable parentheses in text labels in Graphics

Mathematica Asked by rogerl on August 11, 2021

I’m trying to annotate a plot with points of the form $left(frac{1}{2},frac{1}{2}right)$; my problem is that the parentheses don’t stretch to cover the fraction. I think that what I want to do is to use a StyleBox inside the Graphics primitive to allow me to format the string using SpanMaxSize, but StyleBox is not a text string. I cannot figure out how to make this work. Is there an easier way?

So for example, if I use

Graphics[Text[Style["(1/2,sqrt(3)/2)", Black, 12], {-1.1, .8}]]

with the 1/2 and sqrt(3)/2 formatted in OutputForm, I get
enter image description here

2 Answers

In graphics, Text objects render in TraditionalForm. In TraditionalForm, parentheses are used instead of square brackets. So you can achieve what you want by using an expression with an invisible head:

Graphics[Text[Style[Invisible[""][1/2,Sqrt[3]/2],Black,12],{-1.1,.8}]]

enter image description here

There are other ways to achieve this behavior, but they require learning a bit about how boxes work.

Correct answer by Carl Woll on August 11, 2021

<< MaTeX`
Plot[0, {x, -1, 1}, 
    Epilog -> { Point[{-1/2, Sqrt[3]/2}], 
            Inset[MaTeX[
                    "left(-frac{1}{2},frac{sqrt{3}}{2}right)"], {-1/2 + 
                        0.1, Sqrt[3]/2 - 0.3}]}]

enter image description here

Answered by wuyudi on August 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP