First, look at https://mathematica.stackexchange.com/questions/187654/how-to-build-a-templatebox-with-dynamic-length-gridbox[templatebox-with-dynamic-length-gridbox][1] since similar questions already have answers
My solution (adopted from more general context) is below. With little more adaptation the output even can be copied, edited and reused, assuming that you do not change number of indices (this seems is limitation of current Mathematica two dimensional input template possibilities).
MakeBoxes[mvDownUp[{indown___Integer}, {inup___Integer}],
sf : StandardForm] := With[{
argsa = Riffle[Flatten[Rest /@ Sort[
Transpose[{{indown, inup},
Join[Table[
AdjustmentBox[Slot[i], BoxBaselineShift -> 1], {i,
Length[{indown}]}],
Table[AdjustmentBox[Slot[i], BoxBaselineShift -> -1], {i,
Length[{indown}] + 1, Length[{indown, inup}]}]]}]
]], ","]
},
With[{
pfd =
Function[
StyleBox[RowBox[argsa], FontSize -> Small,
FontTracking -> "Condensed", AutoSpacing -> False]],
pfi =
ReleaseHold[
RowBox[{"mvDownUp", "@@",
MakeExpression[{Take[{##}, Length[{indown}]],
Take[{##}, {Length[{indown}] + 1,
Length[{indown, inup}]}]}, sf]}]] &
},
TemplateBox[
Flatten[{MakeBoxes[#, sf] & /@ {indown},
MakeBoxes[#, sf] & /@ {inup}}], "mvDownUp",
DisplayFunction :> pfd, InterpretationFunction :> pfi,
SyntaxForm -> "fish",
Tooltip -> ToString[mvDownUp[{indown}, {inup}]]]
]
];
With[{baseSymbolN = "S", bs = Symbol["S"]},
MakeBoxes[bs[in_mvDownUp], sf : StandardForm] :=
With[{sty = (FontColor -> Black), inEx = MakeBoxes[in, sf]},
With[{
pfd =
Function[
StyleBox[RowBox[{StyleBox[baseSymbolN, sty], #1}],
AutoSpacing -> False, FontTracking -> "Condensed"]],
pfi = Function[RowBox[{baseSymbolN, "[", #1, ",", #2, "]"}]]},
TemplateBox[{inEx}, baseSymbolN, DisplayFunction :> pfd,
InterpretationFunction :> pfi, SyntaxForm -> "fish"]]]]
S[x_List] := S[mvDownUp[Sort[x], {}]] /; ! OrderedQ[x]
S[x_List] := S[mvDownUp[x], {}]
S[{3, 1, 2, 7}]