# Infix notation for VertexLabels in a Graph (reformulated from a closed topic)

I am reformulating this question as it was incomplete.

I want to label vertices in a graph with expressions in infix notation.

I copy my code below. First part converts a list of expressions to infix notation. This works fine. Second part uses the same code to produce vertex labels in a graph. However the vertex labels produced do not remain in infix (instead they convert back to prefix code).

I include the code below.

Map[# /. S -> (Infix[S[##]] &) &, {S[1, 2], S[2, S[3, 4]]}]


This code produces infix code fine, yielding {1 ~ S ~ 2, 2 ~ S (3 ~ S ~ 4)}

However the following code:

HasseGraph[g_] := Fold[SetProperty[{#1, #2}, {Map[# /. S -> (Infix[S[##]] &) &,
VertexLabels] ->  #2}] &, g, VertexList[g]]
HasseGraph[Graph[{S[1, 2] -> S[2, S[3, 4]]}]]


produces a graph for which the vertex labels are: S(2,(3,4)) and S(2,S(3,4)). I need these to be in infix notation as for the above example. The conversion to infix has not been preserved. Can you advise on how to make sure that the vertex labels remain in infix form?

• Related question: is it possible to simply display the infix without the ~ signs that clutter up matters? – Mike Feb 13 '19 at 22:33

Maybe you could do:

HasseGraph[g_] :=
With[{vlist = VertexList[g]},
Graph[g, VertexLabels ->
Thread[vlist -> Map[# /. S -> (Infix[S[##]] &) &, vlist]]]]
HasseGraph[Graph[{S[1, 2] -> S[2, S[3, 4]]}]]

• Unfortunately this does not solve the problem. The vertex labels still appear in prefix form. – Mike Feb 13 '19 at 16:43
• @Mike I edited answer. – halmir Feb 13 '19 at 18:02
• Brilliant, that dit it. Thanks, Halmir! – Mike Feb 13 '19 at 18:10
• Is it possible to display infix notations without the ~ signs? So a ~ S ~ b would become aSb as one would expect in infix? – Mike Feb 13 '19 at 22:33
• @Mike Infix[S[##], S] could be what you want. – halmir Feb 13 '19 at 22:44

Again, you could just define a format for S instead. In this case, Graph uses TraditionalForm for labels, so you would need to use something like:

MakeBoxes[s_S, form_] ^:= MakeBoxes[Infix[s], form]


Then:

Graph[{S[1,2] -> S[2,S[3,4]]}, VertexLabels->Automatic]


• Thanks! Will try this one out as well. – Mike Feb 13 '19 at 22:30