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:

enter image description here

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:

enter image description here

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:

enter image description here

  • 3
    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 at 23:06
up vote 4 down vote accepted

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}

enter image description here

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}

enter image description here

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}

How about using:

\documentclass{article}

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

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

to produce:

enter image description here

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}

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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