2
$\begingroup$

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}},
 MenuSortingValue->24,
 MenuCommandKey->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"]),
  MenuSortingValue->21,
  MenuCommandKey->"9"]

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.

$\endgroup$

2 Answers 2

1
$\begingroup$
CellPrint @ ExpressionCell[
  U[x, α] == Evaluate[u[x, α]], 
  "DisplayFormulaNumbered"
]

enter image description here

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.

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – Pirx
    Aug 5, 2016 at 15:32
  • $\begingroup$ @Pirx Take a look at the edit. $\endgroup$
    – Kuba
    Aug 5, 2016 at 15:36
  • $\begingroup$ Awesome, this works. Thanks! $\endgroup$
    – Pirx
    Aug 5, 2016 at 15:43
0
$\begingroup$

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 -> 
     False}] // TraditionalForm

with the effect of

enter image description here

Have fun!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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