I want to define a command to shorten formula like this a^1,\cdots,a^n, using a placeholder (-) instead of index, the code is
\usepackage{xstring}
\newcommand{\replaceStr}[2]{\begingroup\expandarg\StrSubstitute{#1}{(-)}{#2}\endgroup}
\newcommand\coordsnn[1]{\replaceStr{#1}{^1},\cdots,\replaceStr{#1}{^n}}
It works, e.g. $\coordsnn{A(-)B(-)C}$ results in $A^1B^1C,\cdots,A^nB^nC$.
However, if I go further and extend it to situation like a_{01},\cdots,b_{0n}, the command looks like:
\newcommand\coordsnX[1]{\replaceStr{#1}{1},\cdots,\replaceStr{#1}{n}}
It doesn't work any more, leaving (-) unchanged. How to realize this kind of command? How about supscript?
Following is the sample testing code:
\documentclass{article}
\usepackage{xstring}
\newcommand{\replaceStr}[2]{\begingroup\expandarg\StrSubstitute{#1}{(-)}{#2}\endgroup}
\newcommand\coordsnn[1]{\replaceStr{#1}{^1},\cdots,\replaceStr{#1}{^n}}
\newcommand\coordsnX[1]{\replaceStr{#1}{1},\cdots,\replaceStr{#1}{n}}
\begin{document}
Working example:
$$
\coordsnn{a(-)b(-)c}
$$
Not working example:
$$
\coordsnn{a_{0(-)}b_{0(-)}c}, \coordsnn{a^{0(-)}b^{0(-)}c}
$$
\end{document}
\[…\]preferable to$$? – Werner May 16 '14 at 06:07