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.

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?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

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

share|improve this answer
    
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}
share|improve this answer

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.