6

When I put a number into a variable and put that variable into \ang, I get an siunitx error:

\documentclass{article}
\usepackage{siunitx,pgfplots}

\begin{document}
\def\degreed{129.2234}
\pgfkeys{/pgf/number format/.cd,int trunc}
\pgfmathprintnumberto{\degreed}{\degree}
\degree\\
\ang{\degree}% Returns:
%! siunitx error: ``restricted-number''
%!
%! Token '$' forbidden in restricted numerical input.

\ang{129}%works
\end{document}

Is it possible to put a variable into \ang?

1

1 Answer 1

7

The problem here is that pgf is returning not just 129 but a more complex piece of data. If you \show\degree you get

> \degree=macro:
->\pgfutilensuremath {129}.

As siunitx can round anyway, a simple approach would be

\documentclass{article}
\usepackage{siunitx}

\begin{document}
\def\degreed{129.2234}
\ang[round-precision = 0, round-mode = places]{\degreed}
\end{document}
3
  • I suppose that \begingroup\let\ifmmode\iftrue\edef\x{\endgroup\noexpand\ang{\degree}}\x is not really handy. ;-)
    – egreg
    Oct 4, 2013 at 12:37
  • Not really, but I can't think of anything much better. Not that I mean't to post this. I'm still getting used to stackexchange.
    – Fog_Watch
    Oct 5, 2013 at 12:00
  • I started this thread in an attempt to resolve a component of a decimal-degrees to degrees-minutes-seconds macro, but it has become too complicated. I'll move on. Thanks for the replies.
    – Fog_Watch
    Oct 5, 2013 at 12:05

You must log in to answer this question.

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