3
$\begingroup$

This provides a useful input format, extendable with Ctrl+Enter:

CellPrint[Cell[
  BoxData[RowBox[{"(", "\[NoBreak]", 
     TagBox[GridBox[{{"1"}, {"2"}, {"3"}, {"4"}, {"5"}}], Column], "\[NoBreak]", 
     ")"}]], "Input"]]

enter image description here

The generated cell evaluates to a flat List:

{1, 2, 3, 4, 5}

However adding a comment produces a spurious Null:

enter image description here

{1, 2 Null, 3, 4, 5}

Without the TagBox[. . ., Column] comments work normally, but input is not recognized as a flat list:

CellPrint[Cell[
  BoxData[RowBox[{"(", "\[NoBreak]", GridBox[{{"1"}, {"2"}, {"3"}, {"4"}, {"5"}}], 
     "\[NoBreak]", ")"}]], "Input"]]

enter image description here

{{1}, {2}, {3}, {4}, {5}}

Is there a similar flat-list input construction that allows comments?

$\endgroup$
2
  • $\begingroup$ @xzczd Thanks for tagging; I'm out of practice. $\endgroup$
    – Mr.Wizard
    Commented May 1, 2020 at 11:10
  • $\begingroup$ Some testing shows that no matter where you put the TagBox it breaks when you add a comment, because the FE interprets RowBox[{"a", RowBox[{"(*", "b", "*)}]}] incorrectly. On the other hand TemplateBox has a flexible InterpretationFunction option that you could use to take a GridBox input and handle it correctly, I believe. $\endgroup$
    – b3m2a1
    Commented May 25, 2020 at 4:30

1 Answer 1

1
+50
$\begingroup$

Here's a fragile hack

CellPrint@
 Cell[
  BoxData[
   TemplateBox[
    {
     GridBox[{{"1"}, {"2"}, {"3"}, {"4"}, {"5"}}]
     },
    "InputListColumn",
    DisplayFunction -> (RowBox@{"(", #, ")"} &),
    InterpretationFunction -> (
      DeleteCases[
        RowBox[Prepend["{"]@Append["}"]@Riffle[Flatten@#[[1]], ","]],
        RowBox[{"(*", ___, "*)"}], 
        Infinity
        ] &
      )
    ]
   ],
  "Input"
  ]

But it works:

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks! btw youtu.be/QWGjjw0ZwXk?t=130 $\endgroup$
    – Mr.Wizard
    Commented May 25, 2020 at 12:20
  • $\begingroup$ This appears more resilient: InterpretationFunction -> (DeleteCases[#, RowBox[{"(*", ___, "*)"}], Infinity] /. gb_GridBox :> TagBox[gb, Column] &) $\endgroup$
    – Mr.Wizard
    Commented May 27, 2020 at 0:34

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.