I have a long expression which I'd like to export to Latex, so I'm using the copy as latex function. However, in my Latex document I'm using different notation, so I'd like to use the replace rule to change to formatting of my expressions before copying them across.

This sounds fine - however, I'm using a package, 'Quantum', which is for non-commutative algebras, and the ordering of items is very specific and important. I'm finding that when I use my replacement rule, things get reordered and the output expression is no longer correct.

So here's my question: How can I use a replacement rule, whilst making sure that the ordering of the expression remains exactly the same?


I've got a solution which almost does what I'm looking for.

Hold[expr]/.Rules nearly does it. The only thing is that one of the rules is $\beta i\to\beta^{-1}$, and this then comes out as $\frac{1}{\beta}$, even with Hold.

  • $\begingroup$ Try replacing \[Beta]i with Superscript[\[Beta], -1] $\endgroup$
    – b3m2a1
    Mar 11 '20 at 8:20
  • $\begingroup$ Try this: βi /. βi -> "\!\(\*SuperscriptBox[\(β\), \(-1\)]\)" That is, to put it as a string. $\endgroup$ Mar 11 '20 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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