6
$\begingroup$

In the system resource file MiscStrings.tr there is a template:

@@resource PackageTemplate
Notebook[{
Cell[BoxData[
    RowBox[{"BeginPackage", "[", "\"\<\[Placeholder]`\>\"", "]"}]], "Code"],
Cell[BoxData[
    RowBox[{"Begin", "[", "\"\<`Private`\>\"", "]"}]], "Code"],
Cell[BoxData[
    RowBox[{"End", "[", "]"}]], "Code"],
Cell[BoxData[
    RowBox[{"EndPackage", "[", "]"}]], "Code"]
}]

I suppose there is also an automatic way to insert or use this template. What is it?

$\endgroup$
6
$\begingroup$

You can get the template using FrontEndResource:

 FrontEndResource["PackageTemplate"]
 (* Notebook[
  {Cell[BoxData[RowBox[{"BeginPackage", "[", "\"\[Placeholder]`\"", "]"}]], "Code"], 
   Cell[BoxData[RowBox[{"Begin", "[", "\"`Private`\"", "]"}]], "Code"],
   Cell[BoxData[RowBox[{"End", "[", "]"}]], "Code"], 
   Cell[BoxData[RowBox[{"EndPackage", "[", "]"}]], "Code"]}] *)

Usage example:

NotebookPut[FrontEndResource["PackageTemplate"]]

enter image description here

$\endgroup$
  • $\begingroup$ I thought I must be missing something; thanks. Is FrontEndResource documented somewhere? $\endgroup$ – Mr.Wizard Aug 13 '12 at 14:08
  • 2
    $\begingroup$ @Mr.Wizard, I have not come across anything in the docs; but, as you must have noticed, text resource files have several example uses such as the piece FrontEndExecute[FrontEnd`NotebookPut[FEPrivate`FrontEndResource["FEExpressions", "SlideshowTemplate"]]] in MenuSetup.tr. Finding the right syntax took several "trial-and-crash" attempts. $\endgroup$ – kglr Aug 13 '12 at 14:35
  • $\begingroup$ @Mr.Wizard This is not your first encounter with FrontEndResource. See your answer here. $\endgroup$ – Sjoerd C. de Vries Aug 13 '12 at 19:59
  • $\begingroup$ @Sjoerd More evidence of my failing memory. ::sigh:: $\endgroup$ – Mr.Wizard Aug 14 '12 at 0:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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