Skip to main content
added 693 characters in body
Source Link
b3m2a1
  • 47.1k
  • 3
  • 95
  • 245

And here's a way to get those infix-types that are more hard-coded:

ucDataset[
   Select[
    StringStartsQ[#MathematicaName, "Raw"] && #FormattingType == 
       "Alias" &],
   "MathematicaName"
   ] // Normal // StringTrim[#, "Raw"] &

{"Exclamation", "DoubleQuote", "NumberSign", "Dollar", "Percent", \
"Ampersand", "Quote", "LeftParenthesis", "RightParenthesis", "Star", \
"Plus", "Comma", "Dash", "Dot", "Slash", "Colon", "Semicolon", \
"Less", "Equal", "Greater", "Question", "At", "LeftBracket", \
"Backslash", "RightBracket", "Wedge", "Underscore", "Backquote", \
"LeftBrace", "VerticalBar", "RightBrace", "Tilde"}

Note that we can use this for other things, too, say for all the open-close forms:

Note that we can use this for other things, too, say for all the open-close forms:

And here's a way to get those infix-types that are more hard-coded:

ucDataset[
   Select[
    StringStartsQ[#MathematicaName, "Raw"] && #FormattingType == 
       "Alias" &],
   "MathematicaName"
   ] // Normal // StringTrim[#, "Raw"] &

{"Exclamation", "DoubleQuote", "NumberSign", "Dollar", "Percent", \
"Ampersand", "Quote", "LeftParenthesis", "RightParenthesis", "Star", \
"Plus", "Comma", "Dash", "Dot", "Slash", "Colon", "Semicolon", \
"Less", "Equal", "Greater", "Question", "At", "LeftBracket", \
"Backslash", "RightBracket", "Wedge", "Underscore", "Backquote", \
"LeftBrace", "VerticalBar", "RightBrace", "Tilde"}

Note that we can use this for other things, too, say for all the open-close forms:

Source Link
b3m2a1
  • 47.1k
  • 3
  • 95
  • 245

So the idea will be to scrape from the UnicodeCharacters.tr file. Mr.Wizard shows some of that here.

First we get the file and split it by line:

ucTR =
  FrontEndExecute@
   FrontEnd`FindFileOnPath["UnicodeCharacters.tr", 
    "PrivatePathsTextResources"];
ucLines = Rest[StringSplit[ucTR // Import[#, "Text"] &, "\n"]];

Then we parse the file into a Dataset (hopefully I didn't miss anything):

ucDataset =
  Dataset@Flatten@
    StringCases[ucLines,
     codePoint : ("0x" ~~ WordCharacter ..) ~~ 
       Whitespace ~~
       ("\\[" ~~ name : WordCharacter ... ~~ 
         "]") ~~ Whitespace ~~
       "(" ~~ 
       inputAliases : Except[")"] ... ~~ ")" ~~ Whitespace ~~
       
       formattingType : (WordCharacter ..) ~~ Whitespace | "" ~~
     
         precedence : (NumberString | "") ~~ Whitespace | "" ~~
      
        associativity : (WordCharacter ...) ~~ Whitespace | "" ~~
    
          leftWhiteSpace : (NumberString | "") ~~ Whitespace | "" ~~
 
             rightWhiteSpace : (NumberString | "") ~~ 
       Whitespace | "" ~~
       
       interPaddingMaybe : (NumberString | "") ~~ Whitespace | "" ~~
 
             partnerCharacter : (WordCharacter ...) :>
      <|
       "CodePoint" -> codePoint,
       "DisplayForm" ->
        Quiet@
         Check[
          
          ToExpression[
           "\"" <> StringReplace[codePoint, "0x" -> "\\:"] <> "\""],
          None
          ],
       "MathematicaName" -> name,
       "InputAliases" -> 
        StringCases[inputAliases, 
         "$" ~~ inner : Except["$"] .. ~~ "$" :> inner],
       "FormattingType" -> formattingType,
       "OperatorPrecedence" ->
        If[StringLength@precedence === 0,
         Missing["NotAvailable"],
         ToExpression[precedence]
         ],
       "OperatorAssociativity" ->
        If[StringLength@associativity === 0,
         Missing["NotAvailable"],
         ToExpression[associativity]
         ],
       "WhitespacePaddingLeft" ->
        If[StringLength@leftWhiteSpace === 0,
         Missing["NotAvailable"],
         ToExpression[leftWhiteSpace]
         ],
       "WhitespacePaddingRight" ->
        If[StringLength@rightWhiteSpace === 0,
         Missing["NotAvailable"],
         ToExpression[rightWhiteSpace]
         ],
       "WhitespacePaddingInner" ->
        If[StringLength@interPaddingMaybe === 0,
         Missing["NotAvailable"],
         ToExpression[interPaddingMaybe]
         ],
       "PartnerCharacter" ->
        If[StringLength@partnerCharacter === 0,
         Missing["NotAvailable"],
         "0x" <>
          ToUpperCase@
           
           StringTrim[partnerCharacter, 
            StartOfString ~~ ("0" | "") ~~ "x"]
         ]
       |>
     ];

Then finally we can just use a simple Select:

ucDataset[Select[#FormattingType == "Infix" &], "MathematicaName"] // 
  Normal // RandomSample[#, 25] &

{"DotEqual", "LeftTeeVector", "DownRightTeeVector", \
"NotLeftTriangleBar", "Cap", "UpTeeArrow", "NotSucceedsTilde", \
"NotLeftTriangle", "NotElement", "Distributed", "Times", \
"NotGreaterTilde", "NotLess", "NotGreaterGreater", \
"DoubleLongLeftArrow", "NotLessEqual", "TildeTilde", \
"LeftArrowRightArrow", "Equilibrium", "Coproduct", \
"InvisibleApplication", "DownLeftTeeVector", "DoubleUpArrow", \
"DownTee", "DoubleLeftTee"}

Note that we can use this for other things, too, say for all the open-close forms:

Map[
  With[{openChar = #},
    <|
     "Opener" ->
      If[openChar["MathematicaName"] =!= "",
       openChar["MathematicaName"],
       openChar["DisplayForm"]
       ],
     "Closer" ->
      With[{
        closeChar =
         Select[Normal@ucDataset,
           #["CodePoint"] === openChar["PartnerCharacter"] &
           ][[1]]
        },
       If[closeChar["MathematicaName"] =!= "",
        closeChar["MathematicaName"],
        closeChar["DisplayForm"]
        ]
       ]
     |>
    ] &,
  Normal@ucDataset[Select[#FormattingType == "Open" &]]
  ] // Dataset

bloop