Beginners question. I am trying to get mathematica to format my Stirling number formulas using curly braces instead of
(sorry for the images). This is just for display purposes so it does not have to be linked to StirlingS2. I have the same question for square brackets (for the stirling numbers of the first kind)
-
$\begingroup$ Please take a tour to learn how to express your appreciation via upvotes and an accept. $\endgroup$– Kuba ♦May 7, 2017 at 20:07
4 Answers
Custom output-formatting is one way:
MakeBoxes[StirlingS2[n_, k_], StandardForm] :=
RowBox[{
"{",
GridBox[{{"n"}, {"k"}}, AutoDelete -> False,
GridBoxItemSize -> {"Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}],
"}"}]
StirlingS2[n, k]
The Notation
package can work very well for this. I would suggest you read the documentation as it allows you to input your notation in a friendly and intuitive form, whose appearance does not survive cut and paste to this website. (Though it should work functionally)
Needs["Notation`"]
Notation[ParsedBoxWrapper[
RowBox[{"{",
GridBox[{{"n_"}, {"k_"}}], "}"}]] \[DoubleLongLeftRightArrow]
ParsedBoxWrapper[
RowBox[{"StirlingS2", "[",
RowBox[{"n_", ",", "k_"}], "]"}]]]
If for display only, another option is using Matex
. Here are two versions, one for curly and one for solid braces.
<< MaTeX`
stirling1[n_,k_]:=MaTeX["{"<>ToString[n]<>"\\brace "<>ToString[k]<>"}",Magnification->2]
stirling2[n_,k_]:=MaTeX["{"<>ToString[n]<>"\\brack "<>ToString[k]<>"}",Magnification->2]
And now
stirling1[n,k]
stirling2[n,k]
Grid[Table[
Row[{stirling1[n, k], stirling2[n, k]}], {n, 1, 5}, {k, 6, 10}], Frame -> All]
In:
Subscript[\[ScriptCapitalS], n] // Superscript[#, (\[ScriptK])] &
% // FullForm
{{n, k} // TableForm}
% // FullForm
Out: