[Tex/LaTex] Force inline-type superscript for display equations (but display-type subscript)

math-modemath-operatorsspacingsubscriptssuperscripts

I am trying to create a macro \jjoin for a mathematical operator which roughly produces the following behaviour:

Inline: \bigvee^{(J)}, subscript (typically i \in I) goes in the usual position (as in rendering \bigvee^{(J)}_{i \in I});
Displaystyle: The (J) goes in the same spot as in inline equations, i.e. to the top-right, but the i \in I goes below the \bigvee as is usual in display style.

I have tried the following definitions for \jjoin, to no avail:

  • \mathop{\bigvee{}^{(J)}} (the i \in I appears too far to the right, because the (J) part is taken into consideration for determining the middle of the expression);
  • \makebox[0]{\ensuremath{\hphantom{\bigvee}^{(J)}}}\bigvee (I'm not sure why this fails, but the position of (J) is wildly varying; perhaps because \ensuremath does not remember whether or not \jjoin is invoked in display mode?);

but that's as far as my knowledge of (La)TeX goes.

I have seen #99538 but the result is the same as my first attempt above.


MWE:

\documentclass[a4paper]{article}
\usepackage{amssymb,amsmath}

\newcommand{\jjoin}{\mathop{\bigvee\nolimits^{(J)}}}

\begin{document}
Inline: $\jjoin \qquad \jjoin_{i\in I}$

Display: \[\jjoin \qquad \jjoin_{i\in I}\]
\end{document}

NB. This is my first question here on TeX.SE; I hope that I didn't make too many beginner's errors. Feel free to point them out.

Best Answer

This should work exactly as desired:

enter image description here

\documentclass[a4paper]{article}
\usepackage{amssymb,amsmath}

\pagestyle{empty}

\makeatletter
\newcommand*\jjoin{\@ifnextchar_\jj@in\jj@@n}
\newcommand*\jj@@n{\bigvee\nolimits^{(J)}}
\newcommand*\jj@in[2]{\mathchoice
    {\mathop{\jj@@n}_{#2\phantom{(J)}}}%
    {\jj@@n_{#2}}%
    {\jj@@n_{#2}}%
    {\jj@@n_{#2}}%
}
\makeatother



\begin{document}
Inline: $A=\jjoin B \qquad A=\jjoin_{i\in I} B_i$

Display: \[A=\jjoin B \qquad A=\jjoin_{i\in I} B_i\]
\end{document}