I have two questions about editing my output in Mathematica.

enter image description here

I want the variables to be to the right of the fractions with the parameters.


e = a*Subscript[u, 1] + b*Subscript[u, 2] + c*Subscript[y, 1] + d*Subscript[y, 2]; 
  Solve[e == 0, Subscript[y, 1]], 
  {Subscript[y, 2], Subscript[u, 1], Subscript[u, 2]}]


What I want is


  • $\begingroup$ Please do not post images of your work, especially when the images display at a size that make them difficult to read. Please post your actual Mathematica code in the form of text that can be copied and pasted into a Mathematica notebook. Without such, it will be difficult to reproduce your problem and to experiment with possible solutions. $\endgroup$
    – m_goldberg
    Commented Nov 23, 2016 at 9:18
  • $\begingroup$ here: e = -Subscript[T, samp] Subscript[u, km1] + [Tau] Subscript[y, k] - [Tau] Subscript[y, km1] + Subscript[T, samp] Subscript[y, km1]; Collect[Solve[e == 0, Subscript[y, k]], {Subscript[y, km1], Subscript[ u, km1]}] but difficult to read? $\endgroup$
    – chrisdi91
    Commented Nov 23, 2016 at 9:19
  • $\begingroup$ Please do not post code in comments. Edit your question to show the code. Please use markdown and our editor to format the code readably. $\endgroup$
    – m_goldberg
    Commented Nov 23, 2016 at 9:21
  • 2
    $\begingroup$ Why is the reordering important to you? There is no way to reorder the output will preserve the ability use it for further computation. That is, reordering for display is possible, but reordering of the internal form is not. $\endgroup$
    – m_goldberg
    Commented Nov 23, 2016 at 9:30
  • $\begingroup$ @chrisdi91 copy and paste your code from your notebook!! $\endgroup$ Commented Nov 23, 2016 at 9:34

1 Answer 1


First, as it is already commented by @ m_goldberg : "reordering for display is possible, but reordering of the internal form is not". This means that you can reorder the expression to have a comfortable look at it. But this reordered expression you will not be able to use in the following calculations. It is of coarse, if you intend to have such further calculations. But the good news is that there is a rather simple remedy to that.

Second, one should spend some efforts to reorder that. But finally it is possible and not that complex.

So let us start. Here are your expressions:

e = -Ts*u1 - t*yk - t*yk1 + Ts*yk1;
expr0 = Collect[Solve[e == 0, yk], {yk1, u1}][[1, 1]]

(*  yk -> -((Ts u1)/t) + ((-t + Ts) yk1)/t  *)

Let us look at its TreeForm:


enter image description here

It is now easy to take the parts of the first term of the right-hand part of your result separately:

Evaluate[Take[expr[[2, 1]], {1, 3}]]
Evaluate[expr[[2, 1, 4]]]

(* -(Ts/t)

u1    *)

Evaluate is here very important, since later I will apply HoldForm to the results, and then without Evaluate it will not work.

Now the HoldFormfunction is needed to prevent the fusion of these two expressions. Let us construct the first term of the result:

expr2 = (Evaluate[expr0[[2, 2, 3]]] //HoldForm)*(Evaluate[Take[expr0[[2, 2]], {1, 2}]] // HoldForm)

The result is as follows:

enter image description here

Let us construct the second part in the same way:

expr2 = (Evaluate[expr0[[2, 2, 3]]] // 
    HoldForm)*(Evaluate[Take[expr0[[2, 2]], {1, 2}]] // HoldForm);

and combine them together:

    expr3 = expr1 + expr2;
expr4=yk -> expr3

with the effect:

enter image description here

This seems to be what you need. Let us now have a look at its structure:

expr3 // FullForm

enter image description here

We see lots of the HoldFormfunctions in it, so it will not work in further calculations. To remove it do the following:

expr4 // ReleaseHold

(* yk -> -((Ts u1)/t) + ((-t + Ts) yk1)/t *)

and we returned to the initial state, but you may calculate further.

Have fun!


Your Answer

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

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