Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Lets say I have a file named test.m containing some functions.

test[arg1_, arg2_] := (
test3[arg1_, arg2_] := (

What would be a good way to generate a list of butons that would allow you to invoke the functions easily? For example.

enter image description here

The tricky part here (and is mainly why I am asking this question) is calling the functions, which will have several different argument types? I had thought about using an InputField with a MessageDialog, but I would bet there is better way to incorporate Mathematica's features.

loadFile[path_String?FileExistsQ] := DeleteCases[ToExpression[
    , InputForm, HoldComplete], Null];
x = ReleaseHold[
   loadFile["test.m"] /.
    HoldPattern[sym_[args__] := eval_] :>
     Button[sym, eval]
x[[0]] = List;
share|improve this question
up vote 2 down vote accepted

The following code allows you to click the button which will allow you call the function. (functionality still buggy, 2 options 1) add functions to Global namespace 2) figure out some way to allow you to call the functions ).

loadFile[path_String?FileExistsQ] := 
   ToExpression[FromCharacterCode[BinaryReadList[path]], InputForm, 
    HoldComplete], Null];

 loadFile["test.m"] /. 
    HoldPattern[sym_[args___] := eval_] :> 
     Button[Defer[sym], CellPrint[Cell[
         , "Input", Evaluatable -> True, 
         CellEvaluationFunction -> Function[ToExpression[#];], 
         ShowStringCharacters -> True
      ] /.
   HoldPattern[Pattern][a__, _[x___]] :> Placeholder[a _ x] /. 
  List :> CompoundExpression,

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.