Thanks for the answer! This works, but sometimes not all terms were collected. In this case I would receive terms, which belong together, in different orderings, e.g. I define an ordering through
{N, Q_#, g_#, R_#, \tau_#, \omega_#}::SortOrder;
and $Q_{ij}$ as symmetric,
Q_{i j}::Symmetric;
However, the result after using factor_in(_, \$N\$) would be something like
$(5 N^2+12 N) Q{ij} + Q{ij} (10 N^3 -13) - (6 N^3+50 N^2) Q_{ji}$
(swapped indices, or tensors and scalars in different order). Unfortunately, I wasn't able to make up a minimal example; as soon as I go from the full computation to a simple example, the problem disappears (so it might be something else that causes the problem).
Any ideas what could be wrong with my code? Or how to tell Cadabra to order the terms correctly and apply symmetries?
Thank you!