# Defining a scaling postfix operator

I would like to find a way to scale a one-place defined (postfix) operator to match its surroundings. I would like it if this behavior imitated what can be accomplished using \left and \right.

An example will help make this more clear. This code:

\documentclass{amsart}

\newcommand{\pda}{\mathord{\downarrow}}

\begin{document}

$t\pda^X_Y$

$\left[t\pda^X_Y\right]^a_b\pda^Y_Z$

\end{document}


Produces the following output:

I'm happy with the size of the first arrow, but I would like a way to scale the second arrow so that it matches the scale of the bracketed bit to its left.

Because its stackexchange and because I haven't finished my coffee yet so am still mildly grumpy, I feel I should include these disclaimers: no, I'm not interested in using some completely different notation for this that you think looks better. I promise, I know what I'm doing and I need something that looks (essentially) like this. No, I won't define 'match' more carefully for you. If you're not sure what I mean by 'match', perhaps its best to just leave the question for someone else. Yes, I'm happy to use other packages or to define my arrows differently. Finally, 'pda' is my name for that thingy because its a Postscripted DownArrow.

What I would most love is if I could write something like

\match\pda^Y_Z


and have tex look, see the '\match' and think 'ah yes, I should scale this thing', then actually scale the thing.

When TeX has processed \right, it stores the result in a math list and goes along: the information about the size of the constructed list is not available.

You can do it by redefining \left, but I'm not sure you really want to do it.

\documentclass{article}
\usepackage{xparse}

\NewDocumentCommand{\shayleft}{u{\right}me{^_}}{%
\shayleftaux{#1}{#2}{#3}{#4}%
}

\ExplSyntaxOn

% remember the meaning of \left
\cs_new_eq:NN \shay_left: \left

\NewDocumentCommand{\shayleftaux}{mmmm}
{
\shay_right_or_middle:nnnn { #1 } { #2 } { #3 } { #4 }
}

\cs_new_protected:Nn \shay_right_or_middle:nnnn
{
\peek_meaning:NTF \pda
{
\shay_doubleleft:nnnn { #1 } { #2 } { #3 } { #4 }
}
{
\shay_singleleft:nnnn { #1 } { #2 } { #3 } { #4 }
}
}

\cs_new_protected:Nn \shay_doubleleft:nnnn
{
\shay_left: . \kern-\nulldelimiterspace
\shay_left: #1
\right#2
\tl_if_novalue:nF { #3 } { \sp{#3} }
\tl_if_novalue:nF { #4 } { \sb{#4} }
\bool_set_true:N \l_shay_right_bool
}

\cs_new_protected:Nn \shay_singleleft:nnnn
{
\left#1
\right#2
\tl_if_novalue:nF { #3 } { \sp{#3} }
\tl_if_novalue:nF { #4 } { \sb{#4} }
\bool_set_false:N \l_shay_right_bool
}

\NewDocumentCommand{\pda}{}
{
\bool_if:NTF \l_shay_right_bool
{
\right \downarrow
}
{
\mathord{\downarrow}
}
}

\bool_new:N \l_shay_right_bool

\cs_set_eq:NN \left \shayleft

\ExplSyntaxOff

\begin{document}

$t\pda^X_Y$

$\left[t\pda^X_Y\right]^a_b\pda^Y_Z$

\end{document}