I was trying to find all the Mathematica functions listed in the index of the Elementary Introduction to the Wolfram Language.

I just cut and pasted everything to a text file and then strung together the ugliest nested Select statement I could based on predicates I found by searching:

f = Import["/Users/joe/Documents/z school/mma elementary index.txt"];
firstLetterCapital[x_] := First[ToCharacterCode[x]] < 91
fStringSplitAtSpace = StringSplit[f];
fWordsOnly = Select[
    Select[fStringSplitAtSpace, DictionaryWordQ], 
  , firstLetterCapital]

I'm not winning any prizes for the above but it kinda-mostly works.

My question: is there a straight forward way to find the intersection of the Global rule base(?) with this list? or string yet another Select function with a say, WolframFunctionNameQ predicate?

Of course, more elegant methods of getting there would be appreciated.


3 Answers 3


A more rigours way to get function names is to examine the html elements. Here I assumed the bold text of functions are intended functions, so things like Alignment is not included.

data = Import["https://www.wolfram.com/language/elementary-introduction/2nd-ed/book-index.html", "Source"];
   "<span class=\"FunctionName\">" ~~ Shortest[fun__] ~~ "</span>" :> 
    fun]], Names["System`*"]]
  • $\begingroup$ thanks - with my xp level, this answer makes sense. also, that garden path that i went down set me up to think that it should be a simple Intersection question so your answer was a perfect moment for me to learn about Names. I have no idea what MB1965 is doing... $\endgroup$
    – Joe
    Commented May 24, 2017 at 5:29
  • $\begingroup$ @Joe more or less this but I applied a StringCases to pull a more compact set of function names so that we don't get anything that's in the headers or footers of the page. I used Cases instead of Intersection. $\endgroup$
    – b3m2a1
    Commented May 24, 2017 at 5:35
  • $\begingroup$ @happyfish bizarre I get Abs fine. Did you have text = Import["https://www.wolfram.com/language/elementary-introduction/2nd-ed/book-index.html"];? I forgot to include that line it seems. Also sans duplicates I have 594. $\endgroup$
    – b3m2a1
    Commented May 24, 2017 at 5:51
  • $\begingroup$ @happyfish interestingly your method returns 642 unique functions. I wonder how many of those are ones my rather-string StringCases missed and how many come from the header and footer and things. I'm betting most are in the former set. $\endgroup$
    – b3m2a1
    Commented May 24, 2017 at 5:57
  • $\begingroup$ @happyfish I think you should stick a StringTrim[__, Except[("$"|WordCharacter)]..] in your code. I applied some StringCases to drop the footer and header and with that plus the string trim I get some 647 functions (vs 636 without the trim). And using a cleaner (I think) version of my code I get 597 there. $\endgroup$
    – b3m2a1
    Commented May 24, 2017 at 6:07

I think you'll be better served by taking the data you can find from Names:

rawText = 
text =
    StringCases[rawText, "Index" ~~ Whitespace ~~ "\n" ~~ __][[1]],
    (func : (("$" | "") ~~ WordCharacter ..) ~~ ___ ~~ NumberString) :> 
    ] // Flatten // Cases[Alternatives @@ Names["System`*"]] // Sort

I get about 597 unique functions from that.

Mentioned this in a comment to happyfish but rather than parsing the HTML it is often nicer to use an XMLObject representation:

xml = Import[
   "https://www.wolfram.com/language/elementary-introduction/2nd-ed/book-index.html", {"HTML", "XMLObject"}

     XMLElement[_, {___, "class" -> "FunctionName", ___}, f_] :> f,
     ] // Flatten // DeleteDuplicates,


url = "https://www.wolfram.com/language/elementary-introduction/2nd-ed/book-index.html";
xmlElements[url_] := Import[url, "XMLObject"];
functionElements[xes_] := Position[xes, XMLElement["span", {"class" -> "FunctionName"},{_String}]] // Extract[xss, #] &
systemFunctionNames[xss_] := Map[#[[3]] &, xss] // Union // Flatten // Intersection[#,Names["System`*"]] &
importSystemFunctionNames[url_] := Composition[systemFunctionNames, functionElements, xmlElements][url]

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.