1

Right now I'm doing some math homework that has lots of ordered pairs. Being lazy, I got tired of writing \langle x, y \rangle and so I was wondering if there's a way to define a command, say \ordered, that receives parameters x, y and returns \langle x, y \rangle . For example \ordered{1, 3} would return enter image description here.

Thanks in advance!

2

2 Answers 2

1

Just do

\newcommand{\ordered}[1]{\langle #1\rangle}

which will also cover ordered triples, quadruples and so on. You can do

\ordered{x,y}
\ordered{x,y,z}

and the output would be as expected.

It's not just laziness! Suppose at some point your coauthor tells you that angle brackets are awful and round parentheses must be used (you're not in the position to contradict your coauthor). Having a command for the thing is the best, because you comply with the diktat by modifying into

\newcommand{\ordered}[1]{(#1)}

and recompile. But maybe your coauthor has a different idea: use semicolons instead of colons.

Not a big deal: change the code into

\ExplSyntaxOn
\NewDocumentCommand{\ordered}{m}
 {
  \langle % or (, maybe
  \clist_use:nn { #1 } { ; }
  \rangle % or ), maybe
 }
\ExplSyntaxOff

and recompile. No change at all in the document input.

Explanation: you need \ExplSyntaxOn to access the expl3 programming layer; \NewDocumentCommand is better in this context, but also \newcommand{\ordered}[1] would do. With \clist_use:nn we tell LaTeX to digest a comma separated list of items and deliver it with semicolons in between items.

3
  • I think any solution like this should include an interface for scaling the brackets.
    – Gaussler
    Jul 28, 2022 at 6:37
  • @Gaussler I don't think this is needed for the particular case of ordered tuples.
    – egreg
    Jul 28, 2022 at 8:16
  • Depends on the vertical size of what you are ordering.
    – Gaussler
    Jul 28, 2022 at 8:17
2

Just do

\def\ordered#1{\langle #1\rangle}

This defines a macro \ordered with one parameter #1. If you use e.g. \ordered{1,3} then the parameter #1 is 1,3 and the macro expands to \langle 1,3\rangle.

You must log in to answer this question.

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