I want to programmatically create a "Code" style cell with commands separated by ; and a new line (from some list). Say for example I have a list {set[a,1],set[b,2],...} I would like to create the cell.


This can almost be done by following the answer to a similar question here, and replacing "Input" with "Code". I find that CompoundExpression@@{a,b,...} does show as a;b;..., as I would like, but I don't know how to add the appropriate newlines.


How about this?:

format[l_List] := 
  ToBoxes@# /. {"set", "[", RowBox[{a_, ",", b_}], "]"} :> {a, "=", b, ";", "\n"} & /@ 
       l // RowBox // BoxData // Cell[#, "Code"] & // CellPrint;

format@{set[a, 1], set[b, 2], set[c, 2]}

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.