Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am making a directed graph, but Mathematica keeps trying to evaluate my labels. I know that I can just use " ", but I have a lot of input. Is there a way to turn evaluation off?

LayeredGraphPlot[{"C1.4.4" -> "T1.5.7", "1.23" -> "L1.5.4", 
  "P1.4.3" -> "C1.4.4", "P1.4.3" -> "C1.1.4", "P1.1.9" -> "P1.5.2", 
  "P1.1.9" -> "L1.5.3", "P1.5.2" -> "T1.5.7", "L1.5.3" -> "T1.5.7", 
  "L1.5.4" -> "T1.5.7", "P1.5.5" -> "T1.5.7", "L1.4.6" -> "L1.4.7"}, 
 VertexLabeling -> True]
share|improve this question
    
Welcome. Your code works for me as expected. What is the evaluation looking like? –  Matariki Jul 14 '12 at 10:46
    
In principles you could use Map to wrap ToString around the expressions at each side of each rule, but if you take the quote marks off, Mathematica interprets "C1.4.4" as C1 * 0.4 * 0.4, i.e. 0.16 C1. There should be some version of HoldForm that works but it seems almost impossible to define a function that performs the transformation without releasing Hold somewhere along the line. –  Verbeia Jul 14 '12 at 11:06
    
Welcome to Mathematica.SE, by the way! Please consider registering your account so that the upvotes you get on any future questions and answers will be added to the ones you received for this one. –  Verbeia Jul 14 '12 at 23:11
add comment

2 Answers 2

up vote 7 down vote accepted

Not sure how robust this is but instead of putting quotation marks around the individual vertex labels, you could do something like

split[rulelst_String] := Rule @@@ Partition[
   StringTrim /@ StringSplit[rulelst, {"->", "\[Rule]", ",", "{", "}"}], 2]

LayeredGraphPlot[
 split["{C1.4.4 -> T1.5.7, 1.23 -> L1.5.4, P1.4.3 -> C1.4.4, P1.4.3 -> 
C1.1.4, P1.1.9 -> P1.5.2, P1.1.9 -> L1.5.3, P1.5.2 -> T1.5.7, L1.5.3 -> 
T1.5.7, L1.5.4 -> T1.5.7, P1.5.5 -> T1.5.7, L1.4.6 -> L1.4.7}"], 
 VertexLabeling -> True]

Mathematica graphics

share|improve this answer
add comment

If you take the quote marks out, Mathematica interprets "C1.4.4" as C1 * 0.4 * 0.4, i.e. 0.16 C1.

This works for a single label, but doesn't if you create a function that operates on different bits of rules.

StringJoin @@ StringReplace[(ToString /@ First[List @@@ Hold[C1 .4 .4]]), 
  "0" -> ""]

(* returns string "C1.4.4" *)

But it should point you in the right direction.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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