2

I have a problem with a space after a comma in a subscript. I created a command called \segN, for intervals with integers. I want a \thinspace between the first integer and the comma, so I typed #1\,,#2 in my command. The second integer should be separated from the comma by the regular space after a comma. It works fine but not in a subscript. Here is a MWE:

\documentclass[a4paper,10pt]{article}

\usepackage{mathtools} \usepackage[frenchmath]{newtxmath}

\makeatletter \newcommand{\segN}{@ifstar\segN@star\segN@nostar} \newcommand{\segN@star}[2]{\left\dlb#1,,#2\right\drb} \newcommand{\segN@nostar}[3][]{#1\dlb#2,,#3#1\drb} \makeatother

\begin{document} $\segN{1}{2}$,\qquad$\displaystyle\sum_{k\in\segN{1}{2}}x_k$ \end{document}

In the first \segN{1}{2}, it's ok: the 2 is separated from the comma. But in the second (with the subscript), the 2 is sticked to the comma and I don't understand why.

campa
  • 31,130
Didier
  • 1,311

2 Answers2

2

The space between a punctuation symbol and an ordinary symbol is a "conditional" \thinmuskip: "conditional" in the sense that it's not used in script styles: that's why you see it in the first example but not in the second one. (See this answer for more details.)

Quick fix: make everything a \mathord and insert both spaces manually.

\documentclass[a4paper,10pt]{article}

\usepackage{mathtools} \usepackage{newtxtext} \usepackage[frenchmath]{newtxmath}

\DeclarePairedDelimiterX{\segN}[2]{\dlb}{\drb}{{#1},{,},{#2}}

% also a possibility but more complicated %\DeclarePairedDelimiterX{\segN}[2]{\dlb}{\drb}{#1,,,\nonscript!#2}

\begin{document} $\segN{1}{2}$,\qquad$\displaystyle\sum_{k\in\segN{1}{2}}x_k$ \end{document}

enter image description here

Miscellaneous comments:

  • mathtools already provides a way to define a paired delimiter with a starred version.
  • Loading newtxmath without newtxtext looks weird to me.
campa
  • 31,130
  • Thank you all for your answers. @campa: I use newtxtext but I didn't put it in the MWE. I didn't know DeclarePairedDelimiterX. I only knew DeclarePairedDelimiter. Big change for me – Didier Sep 23 '21 at 19:41
  • Since it is in scriptstyle, shouldn’t the space before and after the comma be smaller than in textstyle and displaystyle? – Didier Sep 25 '21 at 10:44
  • @Didier I'm not sure I understand your question. The space is a \thinmuskip, which scales with the current style. – campa Sep 25 '21 at 14:11
  • Ok, campa. I didn’t know it was scaling with the current style. Thank you for your help – Didier Sep 25 '21 at 17:39
0

Is it what You need? enter image description here

\documentclass[a4paper,10pt]{article}

\usepackage{mathtools} \usepackage[frenchmath]{newtxmath}

\makeatletter \newcommand{\segN}{@ifstar\segN@star\segN@nostar} \newcommand{\segN@star}[2]{\left\dlb#1,,#2\right\drb} \newcommand{\segN@nostar}[3][]{#1\dlb#2, ,#3#1\drb} \makeatother

\begin{document} $\segN{1}{2}$,\qquad$\displaystyle\sum_{k\in\segN{1}{2}}x_k$ \end{document}

WinnieNotThePooh
  • 3,008
  • 1
  • 7
  • 14