0

I want pdflatex to take the command \num from the package siunitx, but the command seems to already be defined in the package stata obtainable (in complicated ways, if you don't have stata, unfortunately) from http://repec.sowi.unibe.ch/stata/texdoc/index.html. (I'd provide the whole sty file in a github repo, but I don't know whether the Stata ToS or Ben Jann would allow it, so, sorry about that.)

Main question

How do I tell LaTeX to take the definition of \num from siunitx.sty without altering stata.sty (like, say, just going ahead and deleting that line in stata.sty, which would solve the problem instantly, but I might need that definition later in another document)? Other adviceful comments welcome whatsoever.

Here is an MWE, the desired and faulty output:

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{stata} % <--- deactivate to get desired output
\usepackage{siunitx}

\begin{document}
    \begin{align*}
        P(x \leq 2) & = \num{1e-9} + \num{8.1e-8} 
    \end{align*}

    \num{1e-9}
\end{document}

what it should look like

desired output equation

what it does look like

current output equation

the error I get (logfile)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! LaTeX error: "xparse/command-already-defined"
! 
! Command '\num' already defined!
! 
! See the LaTeX3 documentation for further information.
! 
! For immediate help type H <return>.
!...............................................  

l.7289 }

|'''''''''''''''''''''''''''''''''''''''''''''''
| You have used \NewDocumentCommand with a command that already has a
| definition.
| The existing definition of '\num' will not be altered.
|...............................................

and (error list in texstudio)

LaTeX error: "xparse/command-already-defined" Command '\num' already defined! For immediate help type H <return>. }

the definition of \num in siunitx.sty

\NewDocumentCommand \num { o m } {
  \leavevmode
  \group_begin:
    \bool_set_false:N \l__siunitx_font_set_bool
    \IfNoValueF {#1}
      { \keys_set:nn { siunitx } {#1} }
    \__siunitx_number_output:n {#2}
  \group_end:
}

and the same definition in stata.sty

\def\num{{\it \#\/}}

(Annotation: I know the command \it is deprecated, since I am told so by the program, if I invert the load order ot the packages stata and siunitx, but that's a different matter I shall need to discuss with Dr. Jann)

thymaro
  • 1,507
  • 1
    I don't have stata.sty but as a work-around you could put \let\num\relax or (maybe better?) \let\num\undefined between loading stata and siunitx. – campa Mar 07 '18 at 16:23
  • or \let\num\undefined as in https://tex.stackexchange.com/questions/35962/undefining-custom-commands. – Marijn Mar 07 '18 at 16:26
  • 2
    You could load siunitx first, then \let\SInum\num and \let\num\relax. Then, load stata package. Use \SInum when you want the siunitx version. – Steven B. Segletes Mar 07 '18 at 16:26
  • funnily enough, any of those produce the right math syntax in the main document font in my main document, but work in the MWE I provided here. Well, it answers the question, as far as I'm concerned, but now I have another problem and I'm not sure I will be able to pin down this one. Any of you is welcome to write an answer. Personally, I think I prefer the option to still be able to use stata's \num command, but inverting the order might produce other, yet unknown, issues down the road. – thymaro Mar 07 '18 at 16:45

0 Answers0