2
$\begingroup$

TraditionalForm seems not to be working properly on Mathematica 11.3 when used in Graph. The following MWE

edges = {1 \[UndirectedEdge] 2};
GraphicsRow[{Graph[edges, VertexLabels -> ρ,
   VertexLabelStyle -> Directive["StandardForm", 30]],
  Graph[edges, VertexLabels -> ρ, 
   VertexLabelStyle -> Directive["TraditionalForm", 30]], 
  Graph[edges, VertexLabels -> ρ, 
   VertexLabelStyle -> Directive["DisplayForm", 30]]}]

Produces the following output (I'm putting StandardForm for comparison)

graph

However, when I do

TraditionalForm[ρ]

The character output is that in the left image of the character description.

Then, I began to wonder, is it possible to use characters in TraditionalForm inside Graphs?

$\endgroup$
  • $\begingroup$ Should this work? "TraditionalForm" is not a graphics directive. $\endgroup$ – Jason B. Jun 25 at 15:55
  • $\begingroup$ Thank you for the answer. I think it should, since for instance "StandardForm" does work. I have updated the question to show this. $\endgroup$ – Alex Jun 25 at 16:06
4
$\begingroup$

When you put "StandardForm" or "TraditionalForm" inside the directive, it's using them as named styles, not as StandardForm or TraditionalForm.

The reason they look different, is because "StandardForm" (as a style) includes a specific font, while "TraditionalForm" doesn't:

In[122]:= Lookup[
 CurrentValue[{StyleDefinitions, "StandardForm"}], FontFamily]

Out[122]= "Source Code Pro"

In[121]:= Lookup[
 CurrentValue[{StyleDefinitions, "TraditionalForm"}], FontFamily]

Out[121]= Missing["KeyAbsent", FontFamily]

(Note that the font for "StandardForm" is actually a dynamic value; I hacked in what it looks like for me.)

This is why

Style[TraditionalForm[Sin[x]], FontFamily -> "Comic Sans MS"]

will show up in Comic Sans, while

Style[StandardForm[Sin[x]], FontFamily -> "Comic Sans MS"]

won't:

enter image description here

What "form" is used for the labels is determined by the FormatType option, using the default font for text in graphics:

Graph[{1 -> 2}, VertexLabels -> {1 -> x^2, 2 -> Sqrt[x]}, FormatType -> TraditionalForm]
Graph[{1 -> 2}, VertexLabels -> {1 -> x^2, 2 -> Sqrt[x]}, FormatType -> StandardForm]
Graph[{1 -> 2}, VertexLabels -> {1 -> x^2, 2 -> Sqrt[x]}, FormatType -> InputForm]

enter image description here

$\endgroup$
3
$\begingroup$

It seems that Graph doesn't propagate the FormatType to the InsetBox objects used to typeset the labels. You can workaround this by including the right FontFamily explicitly:

Graph[
    {1 \[UndirectedEdge] 2},
    VertexLabels -> ρ, 
    VertexLabelStyle -> Directive[FontFamily->"Times", "TraditionalForm", 30]
]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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