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!

Marijn
  • 37,699
tcb93
  • 167

2 Answers2

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.

wipet
  • 74,238
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.

egreg
  • 1,121,712