1

I would like to typeset generic types (eg Foo<T>) in math mode; for instance:

$\mathbf{Foo<T>} = R^3$

But the spacing around < and > is of course incorrect for this. Is there an easy way to have them be treated as normal characters in this context ?

6
  • Isn't this all considered as text, I mean both the word Foo and the <T> ? Aug 18, 2017 at 9:40
  • $\mathbf{Foo{\boldsymbol<}T{\boldsymbol>}}$ does it.
    – Bernard
    Aug 18, 2017 at 9:44
  • 2
    Maybe \langle and \rangle instead of < and >?
    – egreg
    Aug 18, 2017 at 9:44
  • @Bernard this seems to do it, but is there a way to use the "boldness" of the context instead ? Thanks! Aug 18, 2017 at 9:51
  • Boldness in text has nothing to do with boldness in math. But ‘Foo’ in the real document is what? Text?
    – Bernard
    Aug 18, 2017 at 10:04

2 Answers 2

3

You can tell TeX that < and >, in a specific context, should issue \langle and \rangle, additionally applying \bm to them:

\documentclass{article}
\usepackage{amsmath,bm}

\makeatletter
\newcommand{\type}[1]{%
  \begingroup
  \activate@angle@brackets
  \mathcode`<="8000 \mathcode`>="8000
  \mathbf{#1}%
  \endgroup
}
\newcommand{\activate@angle@brackets}{%
  \begingroup\lccode`~=`< \lowercase{\endgroup\def~}{\bm{\langle}}
  \begingroup\lccode`~=`> \lowercase{\endgroup\def~}{\bm{\rangle}}
}
\makeatother

\begin{document}

$\type{Foo<T>} = R^3 < x$ % second < is normal

For comparison: $\langle\mathbf{T}\rangle$

\end{document}

enter image description here

1
  • @Jean-MichaëlCelerier Sorry for the delay, during vacations I didn't see your question.
    – egreg
    Nov 5, 2017 at 23:56
0

I suggest you should regard such identifiers as verbatim material and write

\( \verb|Foo<T>| = R^3 \)

Sample output

You must log in to answer this question.

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