You can create your own ...Form
wrapper that will format Times
as you want it.
Let's start with ordering function that can be used in SortBy
. It puts numeric coefficients in front, expressions present in par
are ordered according to their position in par
, all other expressions are moved to the end.
ClearAll[par, order]
par = {(1 - p), p, k, Subscript[k, a], Subscript[k, b]};
order[_?NumericQ] := 0
order[x_] := Replace[Position[par, x, {1}, 1], {{i_}} :> i]
Now a small helper "wrapper" that will vanish after conversion to boxes. It will also remove boxes resulting from HoldForm
used directly inside wrapper.
ClearAll[vanishingWrapper]
MakeBoxes[vanishingWrapper[expr_], form_] ^:= MakeBoxes[expr, form];
MakeBoxes[vanishingWrapper[HoldForm[expr_]], form_] ^:=
First@MakeBoxes[HoldForm[expr], form];
Now the main ...Form
function that, when converted to boxes, wraps some sub-expressions with our vanishingWrapper
:
ClearAll[istvanForm]
MakeBoxes[istvanForm[expr_], _] ^:=
With[
{heldExpr =
HoldComplete[expr] /. HoldPattern[Times][args__] :>
With[
{eval =
With[
{heldArgs =
Replace[
SortBy[HoldComplete[args], order],
pow_Power :> vanishingWrapper[pow],
{1}
]}
,
Function[Null,
vanishingWrapper@HoldForm@Times[##],
HoldAllComplete
] @@ heldArgs
]}
,
eval /; True
]}
,
Function[Null, MakeBoxes[#, TraditionalForm], HoldAllComplete] @@
heldExpr
]
When Times
function is converted to TraditionalForm
boxes, its arguments are sorted, unless Times
is inside HoldForm
. This sorting is done in addition to ordinary sorting, occurring due to Orderless
attribute, when Times
is evaluated. To prevent this additional sorting, istvanForm
wraps Times
with HoldForm
and vanishingWrapper
. So we get boxes coming from HoldForm[Times[...]]
, but thanks to vanishingWrapper
all additional boxes from HoldForm
are gone, so when we copy resulting expression there will be no HoldForm
inside it.
When Power
expression, with negative numeric exponent, is found directly inside Times
, it triggers special formatting rules putting everything in one fraction. To prevent this special formatting, istvanForm
wraps all Power
expressions on first level of Times
with vanishingWrapper
. So that, when expression is converted to boxes, special formatting is not triggered.
To make istvanForm
behave like proper ...Form
wrapper we must add it to $OutputForms
:
If[FreeQ[$OutputForms, #, {1}],
Unprotect@$OutputForms;
PrependTo[$OutputForms, #];
Protect@$OutputForms;
]& @ istvanForm
Now let's see istvanForm
in action:
-A Subscript[k, b] B p k (1 - p) 1/(B + A) Subscript[k, a] // istvanForm

TeXForm
and I'm not sureRow
-s in Silvia's answer are ok with TeX. Will check it tomorrow all your answers, have to sleep now. $\endgroup$