Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The siunitx package provides support for "astronomy style" placement of the degree symbol using the angle-symbol-over-decimal switch, and for simple entry of degree-minutes-second values using the form

\ang{6;7;6.5}

Is there a way to used the package's \DeclareSIUnit macro to define a corresponding formatting for right ascension so that, for example, one could use something like

\ra[ra-symbol-over-decimal]{5.237}
\ra{5.237} 
\ra{5;15;6.5} 

to produce (roughly)

enter image description here

with spacing and other behavior that follows the packages current settings for \ang?

share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

Reading the siunitx manual ( 5.15 “Symbols”, pp. 62/63) one can find two ways to achieve this:

  1. Redefinition of \SIUnitSymbolDegree, -Arcminute and -Arcsecond
  2. Using the options text-/math-degree, -arcminute and -arcsecond ( Table 43, p. 63)

For both cases applies:

The new macro \ra takes two arguments:

  • one optional that gets passed to \ang and
  • one mandatory (the angle itself).

All “arc format” options (angle-symbol-over-decimal, arc-separator, …) can be given to \ra, too.

Solution 1

\newcommand*{\ra}[2][]{{% extra pair of braces to keep the \def-intion local!
    \def\SIUnitSymbolDegree{\textsuperscript{h}}%
    \def\SIUnitSymbolArcminute{\textsuperscript{m}}%
    \def\SIUnitSymbolArcsecond{\textsuperscript{s}}%
    \ang[#1]{#2}}%
}

Solution 2

\newcommand*{\ra}[2][]{%
    \ang[
        math-degree=\textsuperscript{h},
        text-degree=\textsuperscript{h},
        math-arcminute=\textsuperscript{m},
        text-arcminute=\textsuperscript{m},
        math-arcsecond=\textsuperscript{s},
        text-arcsecond=\textsuperscript{s},
        #1]{#2}%
}

Code

\documentclass{article}
\usepackage{siunitx}

\newcommand*{\ra}[2][]{{% extra pair of braces for solution 1, doesn't hurt for solution 2
%   \def\SIUnitSymbolDegree{\textsuperscript{h}}%     Solution 1
%   \def\SIUnitSymbolArcminute{\textsuperscript{m}}%  Solution 1
%   \def\SIUnitSymbolArcsecond{\textsuperscript{s}}%  Solution 1
    \ang[
        math-degree=\textsuperscript{h},             % Solution 2
        text-degree=\textsuperscript{h},             % Solution 2
        math-arcminute=\textsuperscript{m},          % Solution 2
        text-arcminute=\textsuperscript{m},          % Solution 2
        math-arcsecond=\textsuperscript{s},          % Solution 2
        text-arcsecond=\textsuperscript{s},          % Solution 2
        #1]{#2}%
}}
\begin{document}
\ra[angle-symbol-over-decimal]{5.237}   \par
\ra{5.237}        \par \ra{5;15;6.5}    \par \vspace{2ex}
\ang{2.3;3.4;4.5} \par \ra{2.3;3.4;4.5} \par \ang{2.3;3.4;4.5} \par
\ra[angle-symbol-over-decimal,arc-separator=\,]{2.3}           \par \vspace{2ex}
$\ra[angle-symbol-over-decimal]{5.237} \quad \ra{5.237} \quad \ra{5;15;6.5}$
\end{document}

Output

Output

share|improve this answer
    
Excellent! And in addition, and to complete the set, if I want to be able to write something like \si{hourra} I'll need to additionally have \DeclareSIUnit\hourra{\textsuperscript{h}}; or is there a way to fold that into the definitions above (I'm using #2)? –  raxacoricofallapatorius Nov 4 '12 at 2:02
1  
@raxacoricofallapatorius You can certainly do that (minor correction, you'd need to use \si{\hourra}). Besides \ang/\ra, I would rather use the standard \hour because a superscript h would look weird, especially in something like \si{\hourra\per\anything}. –  Qrrbrbirlbel Nov 4 '12 at 2:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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