Math & ScienceBinary Operator with Subscript underneath

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
kihanos
Posts: 3
Joined: Wed Mar 07, 2012 4:35 pm

Binary Operator with Subscript underneath

Post by kihanos »

Hi every one,

My question seems to me as a tricky one. I'd like to define a binary operator (using something like \mathbin) whose subscript stands underneath it instead of the usual place, like a limit operator. The point is that the \limits, \DeclareMathOperator* or \operatorname* macros don't stand for binary operators.

Does anyone know of a command \mathbin-like setting the subscript as a \DeclareMathOperator* does (ie underneath in \displaystyle and on the side in \textstyle) ?

Of course, I could use something like :

Code: Select all

\newcommand{\mytimes}[2]{\mathbin{\operatorname*{\times}_{#1}^{#2}}}
(in which I'd have to add a \mathchoice in order to manage the different styles). The issue is that I'd like to be able to use it with a handy _ and ^ notation :

Code: Select all

\[
\A \mytimes_B^C D
\]
instead of :

Code: Select all

\[
\A \mytimes{B}{C} D
\]
I could then turn my question around and ask for a way of using _ and ^ to give arguments to a macro.

Thanks for any help,
Kihanos

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Binary Operator with Subscript underneath

Post by localghost »

Somehow I don't really understand the problem in declaring a new operator.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}

\DeclareMathOperator*{\optimes}{\times}

\begin{document}
  $\optimes_a^b$
  \[
    \optimes_a^b
  \]
\end{document}

Best regards and welcome to the board
Thorsten
kihanos
Posts: 3
Joined: Wed Mar 07, 2012 4:35 pm

Binary Operator with Subscript underneath

Post by kihanos »

Hi,
welcome to the board
Thanks a lot!

The problem stands in the spacing after the operator if the next item is a between ( ).

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}

\DeclareMathOperator*{\optimes}{\times}
\newcommand{\mytimes}[2]{\mathbin{\operatorname*{\times}_{#1}^{#2}}}

\begin{document}
  \[
    X \optimes_a^b Y
  \]
  \[
    X \mytimes{a}{b} Y
  \]
  \[
    X \optimes_a^b (i)
  \]
  \[
    X \mytimes{a}{b} (i)
  \]
\end{document}
It might seem a bit picky, but I'm using a lot of such stuffs and "Hey, why not ask someone?".

Regards,
Kihanos
kihanos
Posts: 3
Joined: Wed Mar 07, 2012 4:35 pm

Binary Operator with Subscript underneath

Post by kihanos »

Hi every one,

I finally build a solution from scratch. Here it is :

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}

  \makeatletter
    \let\OLD@times\times
    \def\optimes{\@ifnextchar_\timesWSB\timesNSB}
    \def\timesWSB_#1{\@ifnextchar^{\timesWSBWXP_{#1}}{\timesWSBNXP_{#1}}}
    \def\timesWSBNXP_#1{\mathbin{\operatorname*{\OLD@times}_{#1}}}
    \def\timesWSBWXP_#1^#2{\mathbin{\operatorname*{\OLD@times}_{#1}^{#2}}}
    \def\timesNSB{\@ifnextchar^\timesWXP\OLD@times}
    \def\timesWXP^#1{\@ifnextchar_{\timesWXPWSB^{#1}}{\timesWXPNSB^{#1}}}
    \def\timesWXPNSB^#1{\mathbin{\operatorname*{\OLD@times}^{#1}}}
    \def\timesWXPWSB^#1_#2{\mathbin{\operatorname*{\OLD@times}^{#1}_{#2}}}
  \makeatother

% WSB = With subscript, NSB = No subscript, WXP = With exponent and so on.

\begin{document}
  $\optimes_a^b$ $\optimes^b_a$
  \[
    \optimes_a^b
  \]
  \[
    \optimes^b_a
  \]
\end{document}
It is a bit complicated, mainly because I had to parse the different configurations (neither _ nor ^, ^ alone, _ alone, ^ then _ and _ then ^). Yet it works.

Thanks anyway,
Kihanos
Post Reply