4
$\begingroup$

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

$\endgroup$
1
  • 1
    $\begingroup$ Try MaTeX? MaTeX["\\left(\\frac{1}{2}\\right)"] $\endgroup$ Dec 19, 2020 at 14:52

2 Answers 2

7
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Works great, but can you explain why? Why does an invisible head change the output? $\endgroup$
    – rogerl
    Dec 20, 2020 at 1:03
6
$\begingroup$
<< 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

$\endgroup$
2
  • 1
    $\begingroup$ Can you clarify how the new 12.2 TeX typesetting does in such a case? $\endgroup$ Dec 19, 2020 at 23:56
  • 1
    $\begingroup$ @CATrevillian 12.2 doesn’t use Tex to typeset, it merely converts the Tex strings into mma boxes $\endgroup$
    – user5601
    Dec 21, 2020 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.