I use \textlangle and \textrangle in a command


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




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 


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

enter image description here

This approach works with pdfLaTeX, LuaLaTeX, and XeLaTeX.

\usepackage{textcomp} % for \textlangle and \textrangle macros
\qdist{word}, $\qdist{symbol}$

Addendum -- As @egreg has pointed out in a comment and in his separate answer, using \newcommand to create the \qdist macro, as is done above, can run into trouble. It's necessary to use \DeclareRobustCommand instead of \newcommand.

  • 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
  • 1
    @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
  • 1
    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
  • 1
    @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


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


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.

If you don't want to follow the advice, use


which differs from Mico's suggestion in two important details: it will work correctly in every situation (Mico's wouldn't) and keeps the output upright in any an italic context.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.