[Tex/LaTex] Use emulateapj/aastex with siunitx

aastexincompatibilitysiunitx

I am trying to use siunitx in an emulateapj document, however it reports a conflict of command:

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

generate by pdflatex of the following document:

\documentclass[apj]{emulateapj}
%\documentclass{aastex}
%\let\tablenum\relax
\usepackage{siunitx}

\begin{document}
\title{emulateapj with siunitx}

\author{Jerry Ma}

\begin{deluxetable}{rr}
\tabletypesize{\scriptsize}
\tablewidth{\the\columnwidth}
\tablecaption{\label{tab:test}
A dummy table}
\tablehead{\colhead{col1} &
\colhead{col2} \\
\colhead{\left(\si{\gram}\right)} &
\colhead{\left(\si{\milli\meter}\right)}
}
\startdata
 80.76 & 50.4 \\
 19.28 & 33.4 \\
\enddata
\tablecomments{siunitx doesn't work}
\end{deluxetable}

\end{document}

Naively I put the following just before I load siunitx:

\let\tablenum\relax

to solve the confliction.
This time it compiles through (means I can see the output pdf file which contains a table as expected)
but with errors like the following:

! Package array Error:  Illegal pream-token (\lt@expand@linewidth@): `c' used.

See the array package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.13 \begin{deluxetable}{rr}

? 
! Missing $ inserted.
<inserted text> 
                $
l.22 }

? 

So, the question is, How could I make emulateapj to work with siunitx?
Thank you in advance!

Best Answer

I had the same problem with the aastex documentclass. I was able to use the savesym package as a workaround:

\usepackage{savesym}
\savesymbol{tablenum}
\usepackage{siunitx}
\restoresymbol{SIX}{tablenum}

The savesym package is used to "redefine symbols where names conflict." In this case, the conflict is with the tablenum symbol.

Note that this only solves the problem of siunitx trying to define a symbol that already exists. There is another problem pointed out by Joseph Wright: the deluxetable environment is not compatible with the array package. This is only a problem if one actually uses the deluxtable environment.

In order to use the deluxetable environment, I need to modify the environment as follows:

% redefine deluxetable for compatibility with the array package.
\let\oldenddeluxetable\enddeluxetable
\let\olddeluxetable\deluxetable
\makeatletter
\renewenvironment{deluxetable}[1]{
\olddeluxetable{[#1]}
\def\pt@format{#1}%
}{\oldenddeluxetable}
\makeatother

This can be done right after the \restoresymbol{SIX}{tablenum}. The redefinition changes \def\pt@format{\string#1}% from aastex.cls to \def\pt@format{#1}%.

There may still be some other issues lurking around, but so far these changes have worked for me.

Related Question