13

I am trying to use both the physics and siunitx packages, which both have a definition for the command \qty. I want to ignore the one from physics and use only that from siunitx. This is my minimum non working example, what I would like to see instead of "{10}" is "10 m."

\documentclass{article}

\usepackage{siunitx}
\usepackage{physics}

\begin{document}

I want to express a quantity: \qty{10}{\meter}.

\end{document}
1
  • 11
    Welcome to TeX.SE. Many macros in the physics package are either provided by other packages as well or are so poorly implemented that users are often better off providing their own macro definitions instead of relying on those of the physics package. Please tell us which macros of the physics package you tend to use.
    – Mico
    Commented Dec 27, 2021 at 1:55

1 Answer 1

11

Since the originally accepted answer seems to have gone obsolete, Joseph suggests this alternative:

\documentclass{article}
\usepackage{siunitx}
\usepackage{physics}
\AtBeginDocument{\RenewCommandCopy\qty\SI}
\begin{document}

I want to express a quantity: \qty{10}{\meter}.

\end{document}

ORIGINAL ANSWER

You need to load siunitx first, save a copy of the defined \qty and, once physics is loaded, restore the original meaning assigned to \qty by siunitx.

The siunitx developer @Joseph Wright adds useful comments below the answer.

\documentclass{article}
\usepackage{siunitx,letltxmacro}
\LetLtxMacro{\svqty}{\qty}
\usepackage{physics}
\LetLtxMacro{\qty}{\svqty}

\begin{document}

I want to express a quantity: \qty{10}{\meter}.

\end{document}

or, more simply

\documentclass{article}
\usepackage{siunitx}
\let\svqty\qty
\usepackage{physics}
\let\qty\svqty

\begin{document}

I want to express a quantity: \qty{10}{\meter}.

\end{document}
8
  • 1
    1) As siuntix always provides \SI, you don't need to save and restore, just \let\qty\SI (although I'd be tempted to use \RenewCommandCopy); 2) As physics predates siunitx using \qty, the current approach is 'by design' (physics 'owns' \qty in that sense) - worth at least mentioning
    – Joseph Wright
    Commented Dec 27, 2021 at 9:40
  • This solution does not work anymore :( Commented Jan 7, 2023 at 13:48
  • @RubemPacelli I have no problem compiling either of the given solutions using up-to-date packages. Commented Jan 8, 2023 at 2:51
  • @StevenB.Segletes well, copying and pasting both solutions on overleaf did not work... Commented Jan 8, 2023 at 18:28
  • 3
    @StevenB.Segletes Ruben is right: you'll want \NewCommandCopy to make this work here, or as I suggest in the docs use \AtBeginDocument{\RenewCommandCopy\qty\SI}
    – Joseph Wright
    Commented Jan 8, 2023 at 21:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .