Message Boards Message Boards


RawBoxes to expression?

Posted 4 years ago
5 Replies
6 Total Likes

Does anyone know how to turn RawBoxes into an expression?

In particular, I am looking at the first part of

WolframLanguageData["List", "DocumentationBasicExamples"](*[[1,1]] looks like List[a,b,c,d]*)

I was hoping for a held expression or something that is Inactive.

5 Replies

Perhaps you could do:



Posted 4 years ago
In[]:= Cases[WolframLanguageData["List","DocumentationBasicExamples"],c_Cell :>MakeExpression[c,StandardForm],Infinity]
Out[]= {HoldComplete[{a,b,c,d}],HoldComplete[{a,b,c,d}],HoldComplete[List[a,b,c,d]],HoldComplete[{a,b,c,d}]}

Thanks Carl. I was looking for something that could be done automatically, and maybe one way is to use CellPrint and then a NotebookImport to get the Input cells.

Also thanks Data Computist. Apparently MakeExpression is making an ExpressionCell object, which presumably is something that can be ignored.

I guess that MakeExpression is an old function, while AllCases is a new one (which could replace Cases[...,Infinity])

Todd I will also post an answer that I got from some folks, so just being the messenger here.

There's no guarantee that a particular RawBoxes or Cell represents a valid WL expression. But if it did, then yes, MakeExpression would be the low-level way to extract it. (See also: StripBoxes.) For example:

WolframLanguageData["Array", "DocumentationBasicExamples"][[1, 1]] // 

The higher-level NotebookImport can also be very convenient for processing multiple cells at once. Riffing on Carl's posted answer:

    "DocumentationBasicExamples"], _Cell, Infinity] // Notebook // NotebookImport

Thanks everyone. I woke up in the middle of the night realizing that NotebookImport[Notebook[AllCases[expr,_Cell]] would work. Only learned about NotebookImport a few days ago although it's been around for a couple years.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract