Get rid of useless space between a symbol and a following superscript \top

Let us assume that in all fonts you are using the transpose operator ⊤ has form similar to the Latin letter T in Computer Modern. How on earth do I move ⊤ to the left, and, if necessary, down, automatically? On the one hand, ⊤ could be moved slightly to the left in $W^{\top}T^{\top}M^{\top}$, but not too much. On the other hand, the vertical and horizontal spacing between the letter and the following ⊤ in $A^{\top} L^{\top} u^{\top} w^{\top}$ is horribly large:

In other words, I need a universal macro, say, \transpose{stuff} that would automatically take care of placing the down tack symbol as a right superscript of stuff but not wasting space. Of course, "universal" is not well-defined; we just want that the macro does the right job for as many fonts and letters as possible. (An aside: the known mitigation attempt uses fixed horizontal length -1\mu and no vertical space change. This is not good enough for me.)

My attempts to do horizontal and vertical spacing at the same time with LaTeX3 have no visible effect. In my example below, tl_case does not work as I expect, e.g., \transpose{u} is the same as u^{\top} (which should not be the case):

\tl_new:N\l_tl_lastTokenOfList
\NewDocumentCommand{\transpose}{m}{
\tl_set:Nn \l_tl_lastTokenOfList {\tl_item:nn {#1} {-1}}
#1^{\tl_case:NnTF \l_tl_lastTokenOfList
{ {A}{\mkern-3mu\top}
{L}{\mkern-3mu\top}
{u}{\mkern-3mu\raisebox{-.1ex}{\top}}
{w}{\mkern-3mu\raisebox{-.1ex}{\top}}
}
{}
{\top}
}
}

• The problem is that while it could be kerned substantially left as a superscript, that is not the case as a subscript. I am not sure that different kerning is normal/possible for sub versus superscripts. In cases like this, I tend to define an alternate version, \def\alttop{\!\top} and then manually employ it where appropriate. – Steven B. Segletes Jun 6 '16 at 13:15
• I have used \transpose{A} and then in the definition of \trankspose I used xstring (I think) to test the end of the string and adjust those combinations that needed adjustment. – daleif Jun 6 '16 at 13:16
• @Mico please reopen this question, IMO that the question is not the same and my proposed solution is definitely not the same – daleif Jun 6 '16 at 13:27
• @daleif - Done. – Mico Jun 6 '16 at 13:27
• @StevenB.Segletes diffferent kerns are possible: compare $P_0$ $P^0$ where a subscript on P is tucked in but a superscript not. – David Carlisle Jun 8 '16 at 8:35

Here is my take on it, the idea is to use xstring to look at the last character in the input and then adjust accordingly. The positive thing here is of course that we can adjust this from the preamble. Of course things like \big) is not something that can be catched with this method.

\documentclass[a4paper]{memoir}
\usepackage{xstring}

% Caveat \transpose{ A } is not allowed as we cannot see the A at the
% end because of the trailing space
\newcommand\transpose[1]{
\begingroup
% define more if needed
\noexpandarg
#1^{
\top
}
\endgroup
}

\begin{document}
$\transpose{A} \transpose{L} \transpose{u} \transpose{w} \transpose{W} \transpose{T} \transpose{M}$
\end{document}


• @MarkMcGregor no, as it is a matter of taste how much should be back kerned. The grouping is both to localize \def but also \noexpandard – daleif Jun 6 '16 at 13:58
• @MarkMcGregor why would you, I see no reason not to use begin/endgroup here – daleif Jun 6 '16 at 14:57
• @MarkMcGregor there is no kerning in math mode (AFAIK) – daleif Jun 6 '16 at 15:03