3

I use ConTeXT and I want to put bars over and under the integral sign.

For LaTeX, there is a similar question here, and I think that the answer given by egreg looks indeed very nice (see image below).

Question: How to do this in ConTeXt? The result should look like this:

egregs result

Below is a very naive try from my side, based on the comment by @Manuel (it is not Manuel's fault that it does not work, but mine!) but that does not compile. Since I don't understand the code, there is probably something simple I forgot (I changed the name \tb@int to \tbint, maybe that is a no-no). My hope is that, with the code, someone will easily spot what is wrong and be able to correct.

\def\tint{\mathop{\mathpalette\tbint{t}}\!\int}
\def\bint{\mathop{\mathpalette\tbint{b}}\!\int}
\def\tbint#1#2{%
  \sbox\zeropoint{$\mathsurround\zeropoint#1\int$}%
  \if#2t%
    \rlap{\hbox to\wd\zeropoint{%
      \hfil
      \vrule width .35em height \dimexpr\ht\zeropoint+1.4pt\relax depth -\dimexpr\ht\zeropoint+1pt\relax
      \kern.05em % a small correction on the top
    }}
  \else
    \rlap{\hbox to\wd\zeropoint{%
      \vrule width .35em height -\dimexpr\dp\zeropoint+1pt\relax depth \dimexpr\dp\zeropoint+1.4pt\relax
      \hfil
    }}
  \fi
}

\starttext
\startformula
\tint_a^b f(x)\,dx \bint_a^b f(x)\,dx.
\stopformula
\stoptext

Finally, to avoid the "obvious" answer: using \overline{\int} and \underline{\int} does not look good enough.

  • 1
    \m@th = \mathsurround\zeropoint, \z@ = \zeropoint. I think that's enough, altough may be it's better to use conventions of ConTeXt that I'm not aware of. – Manuel Sep 8 '16 at 10:22
  • @Manuel Thank you, that helps a bit in the understanding the code. – mickep Sep 8 '16 at 11:35
  • 1
    There are two mistakes. First, \sbox in ConTeXt is something completely different from \sbox in LaTeX. Second, saying \sbox\z@ in LaTeX is equivalent to \setbox0 (i.e., box 0, which is used as a scratchbox in LaTeX); you translated it to \zeropoint which is not a box. Usually, ConTeXt uses \scratchbox for such calculations (rather than relying on the number of the box) – Aditya Sep 9 '16 at 2:47
1

Here is an almost literal translation of egreg's answer. I have just changed the coding style to match the usual coding style used in ConTeXt:

\unprotect
\define\tint{\mathop{\mathpalette\tb@int{t}}\!\int}
\define\bint{\mathop{\mathpalette\tb@int{b}}\!\int}
\define[2]\tb@int
 {\setbox\scratchbox\hbox{$\mathsurround\zeropoint#1\int$}%
  \if#2t%
    \rlap{\hbox to \wd\scratchbox
      {\hfil
      \vrule width .35em height \dimexpr\ht\scratchbox+1.4pt\relax depth -\dimexpr\ht\scratchbox+1pt\relax
      \kern.05em % a small correction on the top
    }}
  \else
    \rlap{\hbox to\wd\scratchbox
      {\vrule width .35em height -\dimexpr\dp\scratchbox+1pt\relax depth \dimexpr\dp\scratchbox+1.4pt\relax
      \hfil
    }}
  \fi
}
\protect

\starttext
\startformula
\tint_a^b f(t)\,dt=\bint_a^b f(t)\,dt
\textstyle
\tint_a^b f(t)\,dt=\bint_a^b f(t)\,dt
\stopformula
\stoptext

which gives

enter image description here

  • Thank you very much Aditya! This solves my problem completely. The output you show me also reminds of wondering why\setupmathematics[integral=nolimit] is not the default setting. Coming from Mathematics, I really think it should be. Anyways, thanks again for a good answer! – mickep Sep 9 '16 at 4:10
  • In ConTeXt, the default in almost all cases is do nothing. That is the reason, there is almost no styling of section headings, no default value for parskip, no default value of indentation, etc. The idea is that a user needs to actively decide all parts of the document design. With math, one could envision a module with sensible defaults. – Aditya Sep 9 '16 at 5:23
  • I understand the philosophy, and I like it, but I thought that "do nothing" here was to leave the limits "to the right" of the integral sign, and not above. I guess they are "to the right" if you write in plain TeX (not that plain TeX has to be what one compares with) without changing any setting. – mickep Sep 9 '16 at 5:34
  • To place the limits on the right, \int has to be defined as \mathop{\intop}\nolimits. To do nothing, it has to be defined as \mathop{\intop}. So, the current behavior is the default behavior of \mathop. – Aditya Sep 9 '16 at 5:36
  • I see. Now I have more respect for that default choice (but still do not agree with it). Since I use the same setting in all files, it might be a good idea to put it in a module. Thanks again, and sorry for discussing off topic stuff in the comments to your answer. – mickep Sep 9 '16 at 5:42

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.