4

I want to create a macro for intersections that can switch between cap and bigcap depending on the situation. Here is what I came up with based on browsing other posts on the forum. Are there any hazards to this approach? Is there a better way?

\documentclass{article}

\makeatletter
\newcommand{\intersect}{\@ifnextchar_{\bigcap}{\cap}}
\makeatother

\begin{document}

\[
    A \cap B
\]
\[
    A \intersect B
\]
\[
    \bigcap_{i=1}^{n} A_{i}
\]
\[
    \intersect_{i=1}^{n} A_{i}
\]

\end{document}
11
  • see my Q: tex.stackexchange.com/questions/71150/… and check out mathpalette Jul 6, 2013 at 15:35
  • the hazard comes in when you can't predict exactly what character will come next; if there were no problems with this construction, I've no doubt it would have been done in AMSTeX. Your use of an operator might not line up with another's use (although presumably, they would define another descriptive macro). Jul 6, 2013 at 15:37
  • 1
    @SeanAllred, I looked at that post, but it didn't exactly address my question because I wasn't really concerned about displaystyle versus textstyle: sometimes I want to use \bigcap inline and sometimes I want to use \cap in displayed math. The real difference for me is whether the intersection is indexed, or just a binary operation.
    – Stirling
    Jul 6, 2013 at 15:49
  • In that case, I don't see any problem with this solution ;-) Jul 6, 2013 at 15:57
  • 2
    @Aditya I should flag that comment:-) Jul 6, 2013 at 17:08

1 Answer 1

2

Technically that is probably as good as anything if you want a switch, but actually I wouldn't do it.

It effectively means the infix command is \intersect and the prefix command is \intersect_ both of these are longer than the standard \cap and \bigcap and unless you define lots of other similar commands makes the command inconsistent with the rest of latex which uses different commands eg + and \sum.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .