# Make commas not italicized inside a macro using textit

I'm trying to set up a shortcut for writing semantic types. These are usually written inside $\langle$ and $\rangle$ delimiters, with italicized letters standing for each type and commas separating these. They should look something like this:

I've come up with a macro like the following:

\newcommand{\type}[1]{%
$\langle$\textit{#1}$\rangle$%
}


However, this of course results in the commas being italicized, too, which is not usually done in this context:

Is there a way to exclude commas from being italicized when using this command?

MWE:

\documentclass{article}

\newcommand{\type}[1]{%
$\langle$\textit{#1}$\rangle$%
}

\usepackage[T1]{fontenc}
\usepackage{times}

\begin{document}
\type{e, t} % Don't want comma italicized
$\langle e, t\rangle$ % Don't want math typeface for letters
$\langle$\textit{e}, \textit{t}$\rangle$ % Desired result, but cumbersome
\end{document}


Edit:

To clarify, the reason I don't want to just do $\langle#1\rangle$ is because I want the semantic types to be set in the same typeface as the main text, not the math mode typeface. I've updated the MWE to reflect this, and here's the comparison:

• it seems logically wrong to use the text face here, for \textit will pick up tje current text style eg bold, you seem to be just useing the deprecated times package so using times roman text with computer modern math, if you used compatible math and text types it may look better to use the math font here. – David Carlisle Oct 20 '18 at 23:06

You want the semantic types to be math variables. Note mathptmx below, not the long deprecated times package.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{mathptmx}

\newcommand{\type}[1]{\ensuremath{\langle#1\rangle}}

\begin{document}

\type{e, t}

$\langle$\textit{e}, \textit{t}$\rangle$

\end{document}


As you see, the only difference is in the (excessive) spacing in the complicated version.

An even better version, because newtx provides for much richer Times-like fonts for math:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{newtxtext,newtxmath}

\newcommand{\type}[1]{\ensuremath{\langle#1\rangle}}

\begin{document}

\type{e, t}

$\langle$\textit{e}, \textit{t}$\rangle$

\end{document}


For XeLaTeX and text font set to TeX Gyre Pagella, use newpxmath; a small fix is needed, though.

\documentclass{article}
\usepackage[no-math]{fontspec}
\usepackage{newpxmath}
\usepackage{amsmath}

\setmainfont{TeX Gyre Pagella}

\DeclareSymbolFont{operators}{OT1}{zpltlf}{m}{n}
\SetSymbolFont{operators}{bold}{OT1}{zpltlf}{b}{n}

\newcommand{\type}[1]{\ensuremath{\langle#1\rangle}}

\begin{document}

\type{e, t}

\end{document}


\documentclass{article}

\def\type<#1,#2>{$\langle$\textit{#1}, \textit{#2}$\rangle$}

\begin{document}
\type<e, t>
\end{document}


to produce:

You could also drop the type and just use

\def\<#1,#2>{$\langle$\textit{#1}, \textit{#2}$\rangle$}


and then have \<e,t> in your document.

EDIT

To allow for nesting you should explicitly typeset the comma in \textrm:

\documentclass{article}

\def\<#1,#2>{$\langle$\textit{#1}\textrm{,} \textit{#2}$\rangle$}

\begin{document}
\<e, t>

\<{\<e,t>},{\<e,t>}>
\end{document}