# Output as numbered display formula

I would like to be able to have Mathematica output appear in my "DisplayFormulaNumbered" style, which puts an automatically incremented equation number at the right margin. My stylesheet defines this as:

Cell[StyleData["DisplayFormulaNumbered"],
CellFrame->False,
CellMargins->{{66, Inherited}, {0, 7}},
StyleKeyMapping->{
KeyEvent["Backspace", Modifiers -> {Shift}] -> "Input",
"Tab" -> "DisplayFormula"},
CellFrameLabels->{{None,
Cell[
TextData[{"(",
CounterBox["DisplayFormulaNumbered"], ")"}],
"DisplayFormulaEquationNumber", FontSlant ->
"Plain"]}, {None, None}},
FontFamily->"Times New Roman",
FontSize->12,
FontWeight->"Plain",
FontSlant->"Italic",
FontVariations->{"StrikeThrough"->False,"Underline"->False},
FontProperties->{"ScreenResolution"->96},
FontColor->RGBColor[0., 0., 0.]]


So now I'd like to do something like

u[x_, f_] := 1 - f (Pi/2 + ArcTan[x])/Pi
Style[U[x, α] == Evaluate[u[x, α]], "DisplayFormulaNumbered"]


which almost works (I get the output in the style I want), but it omits the equation number. How do I fix this?

Part of the story is that, for presentation purposes, I use a special style for Input cells like so:

Cell[StyleData["InputHidden", StyleDefinitions -> StyleData["Input"]],
CellEpilog:>(SelectionMove[EvaluationNotebook[], All, GeneratedCell];
FrontEndTokenExecute["SelectionCloseUnselectedCells"]),


which gives me an input cell that automatically hides when evaluated, leaving only the Output cell to be displayed. The problem with Kubo's suggestion below is that it breaks this mechanism, by producing a new cell that's not considered the Output cell of its Input.

CellPrint @ ExpressionCell[
U[x, α] == Evaluate[u[x, α]],
"DisplayFormulaNumbered"
]


Is this ok? Counter number is displayed as a CellFrameLabel so Style can't use it, we need to generate a Cell or change Output to DisplayFormulaNumbered.

Hmm, not quite. [...] the cell doesn't count as an Output cell anymore, which means I can't hide the Input cell by double-clicking the output cell.

You can mix styles:

 CellPrint @ ExpressionCell[
U[x, α] == Evaluate[u[x, α]],
"Output",   "DisplayFormulaNumbered"
]


Which preserves grouping on Input and Output cells here.

• Hmm, not quite. It works, in principle, but now the cell doesn't count as an Output cell anymore, which means I can't hide the Input cell by double-clicking the output cell.The same happens if I change the Output cell to DisplayFormulaNumbered after the fact: The Input and Output cells are now separated. I edited my original post to clarify. – Pirx Aug 5 '16 at 15:32
• @Pirx Take a look at the edit. – Kuba Aug 5 '16 at 15:36
• Awesome, this works. Thanks! – Pirx Aug 5 '16 at 15:43

I do not know, how to make the numbering automatically, but if you agree to make it manually, try this

 ExpressionCell[
Row[{Spacer[350],
Style["\!$$\*SubsuperscriptBox[\(∫$$, $$a$$, $$b$$]\)x\
\[DifferentialD]x=", Italic, 22], Style[\!$$\*SubsuperscriptBox[\(∫$$, $$a$$, $$b$$]$$x \ \[DifferentialD]x$$\), Italic, 22], Spacer[250], Style["(1)", 20]}],
TextAlignment -> Right,
FractionBoxOptions -> {AllowScriptLevelChange ->