5
GeneralUtilities`GetUsages["System`Sin"]

I want to get $\color{red}{\textbf{1}}$ plain string,but this function actually will give me some RowBox:

And the same case:

GeneralUtilities`GetUsages["System`Plot"]

I want to get $\color{red}{\textbf{4}}$ plain string from it:

{"Plot[f,{x,Subscript[x, min],Subscript[x, max]}] generates a plot of f as a function of x from Subscript[x, min] to Subscript[x,max].","Plot[{Subscript[f, 1],Subscript[f,2],…},{x,Subscript[x,min],Subscript[x, max]}] plots several functions Subscript[f,i].","Plot[{…,w[Subscript[f, i]],…},…] plots Subscript[f,i] with features defined by the symbolic wrapper w.","Plot[…,{x}∈reg] takes the variable x to be in the geometric region reg."}

Can any method do this?

rhermans
  • 36,518
  • 4
  • 57
  • 149
yode
  • 26,686
  • 4
  • 62
  • 167

1 Answers1

5

How can I get the unchanged Box form of an arbitrary expression?

toBoxes = MathLink`CallFrontEnd[
    FrontEnd`UndocumentedTestFEParserPacket[#, True]
][[1]] &

How to convert arbitrary raw boxes directly into String?

toText = FrontEndExecute[
    FrontEnd`ExportPacket[#, "PlainText"]
][[1]] &

Composition[
    Map[toText]
  , Map[toBoxes]
  , StringSplit[#[[1]], "\n"] &
] @ GeneralUtilities`GetUsages["System`Plot"]
{
 "Plot[f,{x,Subscript[x, min],Subscript[x, max]}]generates a plot of \
 f as a function of x from Subscript[x, min]to Subscript[x, max]."
 ,
 "Plot[{Subscript[f, 1],Subscript[f, 2],\[Ellipsis]},{x,Subscript[x, \
 min],Subscript[x, max]}]plots several functions Subscript[f, i]."
 , 
 "Plot[{\[Ellipsis],w[Subscript[f, i]],\[Ellipsis]},\[Ellipsis]]plots \
 Subscript[f, i]with features defined by the symbolic wrapper w."
 ,
 "Plot[\[Ellipsis],{x}\[Element]reg]takes the variable x to be in the \
 geometric region reg."
} 
Kuba
  • 136,707
  • 13
  • 279
  • 740