2

Is it possible to give the optional arguments in this command a comma-separated syntax, i.e. \ads{A,1,2,3,4} or \ads{A}[1,2,3,4]? (I think I'd prefer the first variant.) Despite reading all the relevant posts I could find, I haven't so far managed to figure out to how to apply any of the approaches here.

\documentclass{article}
\usepackage{xparse,amsmath}

% A command to apply adscripts to a base;
% the sequential definition of bases is to avoid spurious vspace from empty over-/under-sets;
% the ordering is anticlockwise from bottom.
\NewDocumentCommand{\ads}{o m o O{} O{} o}{%
    \ifx#1t\def\baseA{\text{#2}}\else\def\baseA{#2}\fi% define the base to be text, if desired
    \def\baseB{\baseA_{#3}^{#4}}% apply subscript and superscript
    \IfValueTF{#3}{\def\baseC{\underset{#3}{\baseB}}}{\def\baseC{\baseB}}% apply underset
    \IfValueTF{#6}{\def\baseD{\overset{#6}{\baseC}}}{\def\baseD{\baseC}}% apply overset
    \baseD%
}
\begin{document}
\[
\ads[t]{A}[1][2][3][4]
\]
\end{document}

1 Answer 1

6

Almost certainly this command can be shortened, but this is very quickly written and seems to work.

\documentclass{article}
\usepackage{amsmath}
\makeatletter
\def\newads@i#1,#2,#3,#4,#5,#6;{\def\myA{#1}\def\myB{#2}\def\myC{#3}\def\myD{#4}\def\myE{#5}}
\newcommand\newads[2][]{%
\expandafter\newads@i#2,,,,,;%
\def\baseB{\text{\myA}_{\myB}^{\myC}}%
\ifx\myD\empty
\def\baseC{\baseB}%
\else
\def\baseC{\underset{\myD}{\baseB}}%
\fi
\ifx\myE\empty
\def\baseD{\baseC}%
\else
\def\baseD{\overset{\myE}{\baseC}}%
\fi
\baseD}
\makeatother
\begin{document}
\[
\newads{A,1,2,3,4}\quad
\newads{A,,2,3,4}\quad
\newads{A,1,,,4}\quad
\newads{A,1,,\mathcal{X},\mathcal{Y}}
\]
\end{document}

enter image description here

You must log in to answer this question.

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