[Tex/LaTex] Alternatives to the physics package

best practicesmacrospackage-writingpackagesphysics

The physics package is useful

A lot of my LaTeX documents make heavy use of the physics package. Aside from it overloading several standard commands (e.g. \sin, \abs, etc.), it also makes a few abbreviations very convenient (e.g. \order). It also makes typesetting vector calculus, ordinary/partial/variational derivatives, linear algebra (bra-ket notation and matrices), and other areas much less painful. I think it's safe to say it fills a gap in the market.

The physics package is unpopular

Despite the advantages I've listed from using the package, there are some short comings. It makes use of \xparse which can give several spacing issues (these are usually edge cases but aren't too uncommon), and the syntax can be counter-intuitive. Because of this, whenever I (or others) post a problem that involves the package, a frequent theme is to give physics a wide berth:

(I am sure there are likely more unfavourable reviews of the package out there).

What alternatives are there?

I am curious to know what people think good alternatives are? Off the top of my head:

  • Keep on using physics and hope the macros are improved (unlikely?).
  • Try to re-write the few macros I use most often, but better (I doubt my implementation would be great).
  • There is another equivalent package already which addresses these issues which I haven't found yet.
  • Type it all out in full and abandon all hope of convenient math macros.

While the last option is a bit melodramatic, I think the overarching question of: "Is it preferable to use a supported package which is not ideal/buggy, or should I try and re-invent the wheel?" is one I encounter a fair bit when considering packages. My current ethos is to always use a package/module, and never re-invent the wheel. What would more proficient/experienced users recommend?

Best Answer

This most likely won't help you and I even don't know if it's 'a good' solution, but I just copied the code I need from physics as a first entry point (mostly \bra, \ket for quantum physics) and then looked at it. The problem(s) with physics are the white spaces caused by \vphantom that is in the code for no reasons whatsoever. Take \ket as example:

\DeclareDocumentCommand\ket{ s m }
{ % Ket
    \IfBooleanTF{#1}
    {\vphantom{#2}\left\lvert\smash{#2}\right\rangle} % No resize
    {\left\lvert{#2}\right\rangle} % Auto sizing
}

just delete that \vphantom and it works perfectly. Same with other definitions of this package.