# angle brackets in math and text mode

I use \textlangle and \textrangle in a command

\newcommand{\qdist}[1]{\textlangle#1\textrangle}


which is used in math and text mode. In math mode, I get the error message

LaTeX Warning: Command \textrangle invalid in math mode on input line 952.


what similar symbol could be used in both modes? I use Lualatex.

the MWE

\documentclass[msmallroyalvopaper
]{memoir}

\newcommand{\qdist}[1]{\textlangle#1\textrangle}

\begin{document}

text with \qdist{word}

and some math
$a = \qdist{symbol}$
The multiple applications of a GIS can be summarized in three prototypical situations:

more text

\end{document}


You could incorporate an \ifmmode conditional, to use \langle and \rangle in math mode and \textlangle and \textrangle in text mode.

This approach works with pdfLaTeX, LuaLaTeX, and XeLaTeX.

\documentclass{memoir}
\usepackage{textcomp} % for \textlangle and \textrangle macros
\newcommand{\qdist}[1]{\ifmmode\langle#1\rangle\else\textlangle#1\textrangle\fi}
\begin{document}
\qdist{word}, $\qdist{symbol}$
\end{document}



• works perfectly - but I had hoped for some way to avoid the difference between math symbols and regular text symbols. I understand that the symbols in math are graphically different, but why are different names required (which confuse the user)? – user855443 Jun 16 '18 at 12:00
• @user855443 - I'm not in a position to answer a why-type question with any kind of authority. I can only offer a guess -- which, hopefully, isn't too implausible: the macros \langle and \rangle are specialized for math mode; in particular, they have status math-open and math-close, respectively, and they can generate "large" fences when used as \left\langle and \right\rangle. Rather than redefine these macros to make them usable in text mode, it was probably more straightforward to create new text-mode macros (\textlangle and \textrangle) from scratch. – Mico Jun 16 '18 at 12:08
• thank you for the explanation. The drawback of this 'straightforward' solution is to learn two more commands and the possible interactions/incompatibilities between them. Latex is wonderful, but hard to learn (and I would not know how to do it without all the help I regularly get from StackOverflow and nice people like you!) – user855443 Jun 16 '18 at 12:39
• @Mico Try $\begin{array}{c}\qdist{\alpha}\end{array}$ and smile! ;-) – egreg Jun 16 '18 at 18:10
• @thymaro It's the column specifier for array. – egreg Jun 16 '18 at 19:30

I guess you don't want that the typesetting of the argument to \qdist changes font when in math or in text, so a simpler

\newcommand{\qdist}[1]{\text{\textlangle#1\textrangle}}


might suffice. On the other hand, if this appears in an italic context such as a theorem statement, the effect would be unpleasant:

\newcommand{\qdist}[1]{\textup{\textlangle#1\textrangle}}


seems better.

If you intend that in math the argument to \qdist should be some math symbol, then in my opinion you should use two distinct commands, because the situations are different and semantics of commands is important.

\DeclareRobustCommand{\qdist}[1]{%