14

I'm writing some topology up, and I prefer to use the notation ]a,b[ to denote an open interval as opposed to (a,b), since the ( and ) symbols tend to be over used in this subject.

Is there a preferred practice for writing [ and ] as mathematical symbols as opposed to delimiters? While in my editor, I notice they are highlighted in red as unpaired delimiters. I also figure if ever want to go through and automatically change my notation of open interval, I would not want to change all [ and ] to ) and (, which would greatly mess things up.

Werner
  • 603,163
yunone
  • 3,259
  • Minor comment on the editor matching: if you put \newcommand{\lb}{[}\newcommand{\rb}{]} (note the order!) early on and use \lb and \rb instead of [ and ] then the editor won't get confused. The order of the definitions should ensure that it doesn't think that there are any open groups. – Andrew Stacey Sep 01 '11 at 09:12
  • 1
    minor quibble ... although the aspect of the brackets is reversed, when they indicate an open interval, they are still delimiters, not ordinary symbols. imperative distinction, otherwise the spacing can be compromised. – barbara beeton Sep 01 '11 at 19:58

3 Answers3

21

It is advisable to define a command to handle such notation preferences. As you said, if you ever change your mind in the future, it would be a headache to make sure all your changes were incorporated.

Consequently, I would recommend something like (in LaTeX2e):

\newcommand{\ointerval}[1]{\ensuremath{\left]#1\right[}}% \ointerval{<interval>} -> ]#1[

and use

The open interval \ointerval{a,b} looks better than $(a,b)$.

In future, a change to \ointerval will spread throughout the document. For example, if you wanted to modify (say) the delimiters to ) (, this change will propagate on the next compile.

The choice of using extensible delimiters \left] and \right[ is highlighted by viewing it in comparison to other possible delimiters under different scenarios:

Delimiter choice

Your editor might still recognize unmatched brackets (] and [) since it is hardwired to math left to right, not right to left. However, it removes clutter from your editor view and improves flexibility.

Werner
  • 603,163
  • 11
    actually, \left] and \right[ will improve the spacing with respect to the interval argument, even if the vertical size isn't changed. alternatively, \mathopen{]} and \mathclose{[} (which don't adjust the height), although \left and \right take care of that automatically. (ref: texbook, p.155) – barbara beeton Aug 31 '11 at 19:18
  • 1
    Just to complement barbara's comment: See exercise 18.14 (page 171) and the discussion to its answer (page 322) of the TeXbook. – Gonzalo Medina Aug 31 '11 at 19:32
  • 1
    @Werner: you should really edit your answer to incorporate barbara's suggestion of using \mathopen{]} and \mathclose{[}. It's a shame to use a macro for an interval if it doesn't at least produce the right spacing (e.g. \ointerval{-1,1} will put too much space around the minus sign). – Philippe Goutet Sep 01 '11 at 07:22
  • @Philippe: Thanks for highlighting a case that showed poor spacing. I've updated my answer with some motivation. – Werner Sep 01 '11 at 07:51
12

The mathtools package offers an easy-to-use structure for such expressions.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}   % loads »amsmath«

\DeclarePairedDelimiter{\oiv}{]}{[}

\begin{document}
  \[
    \oiv{a,b}
  \]
  \[
    \oiv*{\frac{a}{b},c}
  \]
\end{document}

For details refer to the package manual.

8

Here is a version that will automatically re-size the brackets depending on the parameters. So if you decide to switch notations this will just require changing this definition to use ) instead of ]. It also has the added benefit that it allows for changing the , separator to something else such as a : in the future if that is desired.

By default a small space gets added following the comma. But some prefer that this extra space not be added. If that is your preference, you can use the commented version of the the 2 parameter version which includes a curly braces around the comma {,} as per Mico's suggestion.

\documentclass{article}
\newcommand*{\Interval}[2]{\left]#1,#2\right[}%
%\newcommand*{\Interval}[2]{\left]#1{,}#2\right[}% Eliminate extra space following the ,
%\newcommand*{\Interval}[1]{\left]#1\right[}% Use this id you prefer using 1 parameter instead of 2


\begin{document}
\[
    \Interval{a}{b}
\]
\[
    \Interval{\frac{a}{b}}{c}
\]
\end{document}

enter image description here

Peter Grill
  • 223,288
  • Thanks Peter. Mind if I ask why you use \vphantom? I've never used those types of commands before. – yunone Aug 31 '11 at 18:35
  • @Peter: The use of \vphantom here is not necessary, since the extensible \left and \right operators don't care about matching the brackets, just the respective \left and \right pairing. – Werner Aug 31 '11 at 18:37
  • 1
    this does the same! \left]\frac{a}{b},c\right[ –  Aug 31 '11 at 18:47
  • Thanks Herbert, Werner. I guess I just got used to using \vphantom so much that I did not realize that \left did not care about ] or [. – Peter Grill Aug 31 '11 at 18:52
  • 2
    and there is also no need for 2 parameters, one is enough –  Aug 31 '11 at 18:54
  • @Herbert: Thought about that, and while you are correct in that this will work fine as far as LaTeX is concerned with just one parameter {a,b} as opposed to {a}{b} I prefer the two parameter approach as I think of an interval as have two parameters, not one. But the OP should make the final decision. – Peter Grill Aug 31 '11 at 20:08
  • In math mode, TeX automatically inserts a little bit of space after a comma; this may not be desirable if the comma is used as a delimiter of the left- and right-hand ends of an interval. Thus, to make the interval command even more perfect, I recommend placing the comma in curly braces, as in {,}. – Mico Aug 31 '11 at 21:02
  • @Mico: Good suggestion: Have updated the answer to reflect that. – Peter Grill Aug 31 '11 at 21:35
  • 1
    @Mico, @Peter: the only context in which the comma shouldn't be followed by a small space in when you use it as a decimal separator (as in French). It's not a matter of personal preference but of readability (there's a reason why Knuth made \mathpunct atoms always have a small space after them). So you should not use {,} here. – Philippe Goutet Sep 01 '11 at 07:15
  • @Herbert: the two argument macro is actually better, because it allows to painlessly change the interval separator from , to ; as needed in some languages, see http://tex.stackexchange.com/q/24156 – Philippe Goutet Sep 01 '11 at 07:17
  • @Philippe Goutet: that can all be done by the user and , or ; can be set to \mathrel inside the macro. Again, no need for a complicated two argument version. –  Sep 01 '11 at 07:36
  • @Herbert: why would you want to set , and ; to \mathrel inside an interval? The spacing would be wrong (especially if TeX needs to use the stretching component of inline math spacing). Having two arguments is not more complicated, it only slightly changes the input but allows to change at will the separator symbol and space it correctly if need be (e.g. a semicolon by \mathclose{}\mahtpunct{};). – Philippe Goutet Sep 01 '11 at 09:14
  • Sorry, I meant normal characters \mathalpha –  Sep 01 '11 at 09:34
  • @Philippe Goutet: I guess I disagree with the view that the comma, when used as the separator of the limits of an interval, should be thought of as a punctuation character. My preference is to think of it -- when used in the interval context, of course -- as a separator of the same type as \mid, i.e., there should be equal space on either side of the comma. I beg you to stare at the output of ${0,1}$, $[0,1]$, $[0{,1}1]$, $(0,1]$, and $(0{,}1]$ for a while. Thanks. – Mico Sep 01 '11 at 10:53
  • @Mico: personally, I use a semi-colon as a separator with equal spacing before and after (as it's done in French typography). For the comma, it's different as its spacing is always asymmetrical: it has space after and not before. If you're doing otherwise (either by putting a space before and after or by putting no space as you suggested above), there should be an excellent reason for it (the same goes for the semi-colon in English). The analogy with \mid is not valid, as it's a relation, which the comma is not. Punctuation already is a separator, e.g. for vector components in (x,y,z). – Philippe Goutet Sep 01 '11 at 12:12
  • @Philippe Goutet: I suppose I can't quite take to heart your strong declaration that whereas a semicolon (at least in French math typographic usage?) need not always be a punctuation/separator character, a comma must always and everywhere be such a character. Please do look at the output of ${0,1}$ (a set consisting of two numbers) vs. $(0,1)$ (an open interval). I find the space after the comma in the second example to be very disruptive, and that's why I prefer the look of $(0{,}1)$. By the way, IMHO \mid is also "just" a separator; the mathrel definition just enforces equal spacing. – Mico Sep 01 '11 at 13:07
  • @Philippe Goutet: Thanks for your insight. I personally prefer the two parameter version with the extra space following the comma, but the OP can make the final decision. – Peter Grill Sep 01 '11 at 15:13
  • @Mico: punctuation should be spaced in math as it is in text. So in English typography, you wouldn't put a space before a semi-colon used as punctuation/separator (but you would if it's a relation, e.g. in \{f\in E\mathrel{;}f>0\}). I must say I fail to see what is wrong with $(0,1)$ compared to $\{0,1\}$. My point was that your suggestion of using {,} is very personal and against what is normally done. And no, \mid is not just a separator, it's a relation: a\mid b has the same status as a<b, thus the \mathrel. The thick space it introduces may not be wanted in other contexts. – Philippe Goutet Sep 01 '11 at 16:32
  • @Peter: of course the OP does what he wants. My point was that it's better to have a standard default behavior in an answer which is going to be read by a lot of people. Using {,} in an interval is very far from standard. – Philippe Goutet Sep 01 '11 at 16:35
  • @Philippe Goutet: Good point. Have adjusted the answer to reflect this. – Peter Grill Sep 01 '11 at 17:18
  • Philippe: I guess this discussion serves as a reminder that de semantibus non est disputandum. – Mico Sep 01 '11 at 19:11