Skip to content

Instantly share code, notes, and snippets.

@rebcabin
Created April 14, 2016 15:45
Show Gist options
  • Select an option

  • Save rebcabin/6ba697716ea2bcbfbe9a3253be4d1a01 to your computer and use it in GitHub Desktop.

Select an option

Save rebcabin/6ba697716ea2bcbfbe9a3253be4d1a01 to your computer and use it in GitHub Desktop.
ClearAll[myNotebook, myStyles, myDemoIntegral, myDemoSolution,
myMathGroup, myItemGroup, myNumberedGroup, myCode, myProgramText,
myMeatyContentGroup, mySectionGroup, myDocumentGroup,
myFontFunction, myDefaultStyles, myNonDefaultStyles];
myNotebook[myStyles_, myDocumentGroup_] :=
Module[{result},
CreateDocument[
result = Notebook[
{Cell[myDocumentGroup]},
StyleDefinitions -> Notebook[
myStyles,
Visible -> False]]];
result];
myDemoIntegral[] :=
RowBox[{
RowBox[{"\[Integral]",
RowBox[{"x", RowBox[{"\[DifferentialD]", "x"}]}]}],
"+", SqrtBox["z"]}];
myDemoSolution[] :=
RowBox[{
FractionBox[SuperscriptBox["x", "2"], "2"],
"+", SqrtBox["z"]}];
myMathGroup[input_, output_] := CellGroupData[{
Cell[BoxData[input], "Input"],
Cell[BoxData[output], "Output"]},
Open];
myItemGroup[] := CellGroupData[{
Cell["Item", "Item"],
Cell["ItemParagraph", "ItemParagraph"],
Cell[CellGroupData[{
Cell["Subitem", "Subitem"],
Cell["SubitemParagraph", "SubitemParagraph"],
Cell[CellGroupData[{
Cell["Subsubitem", "Subsubitem"],
Cell["SubsubitemParagraph", "SubsubitemParagraph"]},
Open]]},
Open]]},
Open];
myNumberedGroup[] := CellGroupData[{
Cell["ItemNumbered", "ItemNumbered"],
Cell["ItemParagraph", "ItemParagraph"],
Cell[CellGroupData[{
Cell["SubitemNumbered", "SubitemNumbered"],
Cell["SubitemParagraph", "SubitemParagraph"],
Cell[CellGroupData[{
Cell["SubsubitemNumbered", "SubsubitemNumbered"],
Cell["SubsubitemParagraph", "SubsubitemParagraph"]},
Open]]},
Open]]},
Open];
myCode[] := RowBox[{RowBox[{"fun", "[", "x_", "]"}], ":=", "1"}];
myProgramText[] :=
"\<DLLEXPORT int fun(WolframLibraryData libData, mreal A1, mreal \
*Res)
{
mreal R0_0;
mreal R0_1;
R0_0 = A1;
R0_1 = R0_0 * R0_0;
*Res = R0_1;
funStructCompile->WolframLibraryData_cleanUp(libData, 1);
return 0;
}\>";
myMeatyContentGroup[] := CellGroupData[{
Cell["Subsubsection", "Subsubsection"],
Cell["Text", "Text"],
Cell[myMathGroup[myDemoIntegral[], myDemoSolution[]]],
Cell[myItemGroup[]],
Cell[myNumberedGroup[]],
Cell["DisplayFormula", "Text"],
Cell[BoxData[FormBox[myDemoIntegral[], TraditionalForm]],
"DisplayFormula"],
Cell[TextData[{
"InlineFormula: ",
Cell[BoxData[FormBox[myDemoSolution[], TraditionalForm]]],
"."}],
"Text"],
Cell["NumberedDisplay", "Text"],
Cell[BoxData[FormBox[myDemoIntegral[], TraditionalForm]],
"DisplayFormulaNumbered"],
Cell["Code", "Text"],
Cell[BoxData[myCode[]], "Code"],
Cell["Program", "Text"],
Cell[myProgramText[], "Program"]},
Open];
mySectionGroup[] := CellGroupData[{
Cell["Section", "Section"],
Cell[CellGroupData[{
Cell["Subsection", "Subsection"],
Cell[myMeatyContentGroup[]]},
Open]]},
Open];
myDocumentGroup[] := CellGroupData[{
Cell["Title", "Title"],
Cell["Subtitle", "Subtitle"],
Cell["Subsubtitle", "Subsubtitle"],
Cell["Author", "Author"],
Cell["Department", "Department"],
Cell["Date", "Date"],
Cell["Chapter", "Chapter"],
Cell["Subchapter", "Subchapter"],
Cell[mySectionGroup[]]},
Open];
myFontFunction[siz_, fam_: "Candara", wgt_: "Plain",
slt_: "Plain"] := {FontFamily -> fam, FontSize -> siz,
FontWeight -> wgt, FontSlant -> slt};
myDefaultStyles[] := {
{"Title", 44}, {"Subtitle", 24}, {"Subsubtitle", 16},
{"Author", 14}, {"Department", 11}, {"Date", 11},
{"Chapter", 34}, {"Subchapter", 28},
{"Section", 28}, {"Subsection", 20}, {"Subsubsection", 19},
{"Text", 14},
{"Item", 15}, {"ItemParagraph", 14},
{"Subitem", 13.5}, {"SubitemParagraph", 13.5},
{"Subsubitem", 13}, {"SubsubitemParagraph", 13},
{"ItemNumbered", 15}, {"SubitemNumbered",
13.5}, {"SubsubitemNumbered", 13},
{"DisplayFormula", 14}, {"DisplayFormulaNumbered", 14}};
myNonDefaultStyles[] := {
{"InlineFormula", 12.6, "Palatino", "Plain"},
{"Code", 12, "Inconsolata", "Bold"},
{"Program", 12, "Courier", "Plain"},
{"Input", 13, "Inconsolata", "Bold"},
{"Output", 13, "Inconsolata", "Plain"}};
myStyles[] := {
Cell[StyleData[
StyleDefinitions ->
FrontEnd`FileName[{"Report"}, "StandardReport.nb",
CharacterEncoding -> "UTF-8"]]],
Sequence @@ MapThread[
Cell[StyleData[#1], myFontFunction[#2]] &,
Transpose[myDefaultStyles[]]],
Sequence @@ MapThread[
Cell[StyleData[#1], myFontFunction[#2, #3, #4]] &,
Transpose[myNonDefaultStyles[]]]};
myNotebook[myStyles[], myDocumentGroup[]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment