2

I am trying to obtain a black square with a subscript and a superscript in plain TeX. So far I managed to create $\buildrel abc \over\square$.

I could easily use nested \buildrels to achieve the desired result, but then, the font used for superscript is smaller than the one for the subscript, because what TeX sees is a "superscript" above \square above "subscript".

How can I solve this? For example, how does TeX implement the \sum macro with superscript and subscript that are equally scaled?

Thanks!

4

This should be declared as a \mathop; here is an implementation where the symbol is as high as a summation symbol.

% define the extension font also in smaller sizes (not relevant to the problem)
\font\sevenex=cmex7
\font\fiveex=cmex7 scaled 714
\scriptfont3=\sevenex
\scriptscriptfont3=\fiveex

\catcode`@=11

% \squareop is a math operator like \sum
\def\squareop{\mathop{\mathpalette\square@op\relax}\displaylimits}

\def\square@op#1#2{%
  \,\vcenter{
    \kern1pt
    \hrule
    \kern-.4pt
    \hbox to\square@size{#1}{%
      \vrule height \square@size{#1}%
      \hfill
      \vrule
    }
    \nointerlineskip
    \kern-.4pt
    \hrule
    \kern1pt
  }\,%
}

% here we define the size of the square
\def\square@size#1{%
  \ifx#1\displaystyle 14pt \fi
  \ifx#1\textstyle 10pt \fi
  \ifx#1\scriptstyle 7pt \fi
  \ifx#1\scriptscriptstyle 5pt \fi
}
\catcode`@=12

$$
\sum_{i=1}^n\squareop_{i=1}^n
\quad\textstyle
\sum\squareop_{i=1}^n
\quad\scriptstyle
\sum\squareop_{i=1}^n
\quad\scriptscriptstyle
\sum\squareop_{i=1}^n
$$

\bye

enter image description here

| improve this answer | |
2

TeX has the following math "styles":

  • \textstyle, which is the default style for inline maths ($...$);
  • \displaystyle, which is the default style for display maths ($$...$$), which is roughly the same as \textstyle, except \mathop atoms such as the \sum get the \limits after them so that the limits are displayed straight above/below the atoms;
  • \scriptstyle for first level of sub-/superscripts which by default is cmr7; and
  • \scriptscriptstyle for second level of sub-/superscripts which by default is cmr5.

It's not clear to me what is your goal here, so maybe you are after \square which is a \mathrel atom which has limits (so needs to be a \mathop atom, too), you could do

\def\relsquare#1#2{\mathrel{\mathop{\square}\limits^{#1}_{#2}}}

and use it with $A \relsquare xy B.

You can always change the active style explicitly:

\buildrel\displaystyle abc\over{\scriptscriptstyle\square}

By the way, \square is not defined in plain.

| improve this answer | |
  • Thanks for further inside. \square is my own macro, maybe I should have stressed it out. – David Nov 25 '14 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.