0

The following source includes a definition of \opair for typesetting ordered pairs, or tuples, that use angle-brackets as the initial and terminal delimiters; that definition appears in https://tex.stackexchange.com/a/592421/13492. (I shrank the 3mu spacings in the original.)

\documentclass{article}

\usepackage{amsmath}

\ExplSyntaxOn % \NewDocumentCommand{\opair}{m} { \langle\mspace{1mu} \kaiserkatze_opair:n { #1 } \mspace{1mu}\rangle }

\seq_new:N \l__kaiserkatze_opair_items_seq \tl_new:N \l__kaiserkatze_opair_first_tl

\cs_new_protected:Nn \kaiserkatze_opair:n { \seq_set_from_clist:Nn \l__kaiserkatze_opair_items_seq { #1 } % set off the first item and insert it \seq_pop_left:NN \l__kaiserkatze_opair_items_seq \l__kaiserkatze_opair_first_tl \tl_use:N \l__kaiserkatze_opair_first_tl % now insert commas and allowed breaks \seq_map_indexed_inline:Nn \l__kaiserkatze_opair_items_seq { % comma and thin space ,\mspace{1mu plus 1mu minus 1mu} % but \allowbreak only after the second item and before the penultimate \int_compare:nT { 1 < ##1 < \seq_count:N \l__kaiserkatze_opair_items_seq } { \allowbreak } % the item ##2 } } \ExplSyntaxOff

\begin{document}

$\opair{1,2}$, $(1,2)$ \begin{gather} \opair{\opair{1,2}, \opair{3,4}} \ \bigl((1,2), (3,4)\bigr) \end{gather}

\end{document}

Compare the output with ordinary use of parentheses and big parentheses for the same thing:

ordered pair of ordered pairs

There are two limitations there:

  1. In the case of an ordered pairs of ordered pairs, the parsing is contrary to the intended meaning.
  2. As it stands, the definition of \opair does not allow for having larger angle brackets, as contrasted with using \bigl( ... \bigr) in the case of parentheses.

How can these limitations be overcome?

Note that for the second issue, it would not suffice to use \left\langle...\right\rangle. I want to be able to control the size of the angle brackets more finely, so as to use also \big\langle...\big\rangle and even \bigg\langle...\bigg\rangle. For this, it would be OK to have separate macros, named, say, \bigopair and \biggopair along with \leftrighopair.

Related: big angle brackets

murray
  • 7,944

1 Answers1

2

The problem with \opair{\opair{1,2}, \opair{3,4}} is not due to parsing(*) but to recursion and assignments: when the second \opair is processed, it sets \l__kaiserkatze_opair_items_seq to a sequence containing the items 1 and 2, which disturbs what the outer \opair was doing: that one now sees an “incorrect” value of \l__kaiserkatze_opair_items_seq. Since the assignments done in \kaiserkatze_opair:n are all local, this can be fixed by wrapping the replacement text of \kaiserkatze_opair:n in \group_begin: ... \group_end:.

For the problem of delimiter sizes, you can make \opair accept an optional argument that gives the desired size. Here is one way using mathtools' \DeclarePairedDelimiterX:

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}

\ExplSyntaxOn

\DeclarePairedDelimiterX { \opair } [1] { \langle } { \rangle } { \mspace { 1mu } \kaiserkatze_opair:n {#1} \mspace { 1mu } }

\seq_new:N \l__kaiserkatze_opair_items_seq \tl_new:N \l__kaiserkatze_opair_first_tl

\cs_new_protected:Nn \kaiserkatze_opair:n { \group_begin: \seq_set_from_clist:Nn \l__kaiserkatze_opair_items_seq {#1} % set off the first item and insert it \seq_pop_left:NN \l__kaiserkatze_opair_items_seq \l__kaiserkatze_opair_first_tl \tl_use:N \l__kaiserkatze_opair_first_tl % now insert commas and allowed breaks \seq_map_indexed_inline:Nn \l__kaiserkatze_opair_items_seq { % comma and thin space ,\mspace { 1mu plus 1mu minus 1mu } % but \allowbreak only after the second item and before the penultimate \int_compare:nT { 1 < ##1 < \seq_count:N \l__kaiserkatze_opair_items_seq } { \allowbreak } % the item ##2 } \group_end: }

\ExplSyntaxOff

\begin{document}

$\opair{1,2}$, $(1,2)$\quad $\opair[\big]{1,2}$, $\bigl(1,2\bigr)$ \begin{gather} \opair{\opair{1,2}, \opair{3,4}} \ \opair[\big]{\opair{1,2}, \opair{3,4}} \ \opair[\Big]{\opair[\big]{1,2}, \opair[\big]{3,4}} \ % The starred form causes \left and \right to be used: \opair{\opair{\frac{1}{2},2}, \opair{3,4}} \end{gather*}

\end{document}

enter image description here

(*) Like macro arguments, items in a clist are always brace-balanced.

frougon
  • 24,283
  • 1
  • 32
  • 55
  • How would one include in this a variant \opair[\lr], say, that uses \left\langle...\right\rangle (so that the outer delimiters stretch just enough for the included content, just like \left(...\right)` ? – murray Jul 14 '22 at 18:03
  • You simply need to use \opair* (this is documented in the mathtools manual). I've added an example of this to my answer. – frougon Jul 14 '22 at 18:17
  • The height of the angle brackets with option \big seems much too large as compared with \bigl(...\bigr) whereas normal size parentheses ( .... ) seem to have the same height as \langle...\rangle. – murray Jul 14 '22 at 18:20
  • Sorry, I didn't design the math fonts. – frougon Jul 14 '22 at 18:21
  • (1) I forgot about the * version but should not have! (2) math font design noted! – murray Jul 14 '22 at 18:32
  • Actually, I tried to reproduce this but using the default font, I see the same height with $\opair[\big]{1,2}$ and $\bigl(1,2\bigr)$ (see the edited answer). Are you sure you tried this correctly? Maybe you are using a different font? – frougon Jul 14 '22 at 19:17
  • The size looked OK with the newtx fonts I'm actually using. – murray Jul 15 '22 at 18:58