# Formatting crystallographic indices

I would like to make a command in LaTeX that can be used like this:

\zoneaxis{1 2 -3}
\zoneaxis{2 -1 -1 10}


and would produce this:

$[1\,2\,\overline{3}]$
$[2\,\overline{1}\,\overline{1}\,10]$


That is, the three or four numbers are set into brackets, any minus signs are set as overlines, and there is a little space between the numbers.

It seems like I would have to get into character-by-character parsing, but I have no idea where to look for how to do that.

Does something like this already exist? If not, where could I find out how to do this?

-

The miller package is probably what you are looking for. Makes typesetting Miller indices quite easy.

-
Thanks, that is exactly what I was looking for. I made a little extension for specifying reflexes (without any brackets): \makeatletter \def\reflex#1{\ensuremath{\@millerno#1 \@empty}} \makeatother. – Svante Apr 15 '11 at 13:23

I suggest the use of xstring, which makes the parsing easier:

\documentclass{minimal}
\usepackage{xstring}
\makeatletter
\newcommand\zoneaxis[1]{%
\begingroup
\expandarg
\def\remain@arg{#1 }%
\ensuremath{[\zoneaxis@]}%
\endgroup}

\newcommand\zoneaxis@{%
\StrBefore\remain@arg\space[\current@arg]%
\StrBehind\remain@arg\space[\remain@arg]%
\IfBeginWith\current@arg-%
{\overline{\expandafter\@gobble\current@arg}}%
\current@arg
\ifx\@empty\remain@arg\else
\thinspace\expandafter\zoneaxis@
\fi}
\makeatother
\begin{document}
$[2\,\overline{1}\,\overline{1}\,10]$

\zoneaxis{2 -1 -1 10}
\end{document}

-