I have a command to display subsequences, which I defined as follows:
\newcommand{\stx}[3] {\ensuremath{#1[#2\!:\!#3]}\xspace}
My initial intention was to render things like this:
The problem is that, in order to get the desired spacing around +
, I have to write code like this:
\stx{s}{a\!+\!m}{b\!+\!n}
Otherwise the spacing around +
is too large and the indices get unclear/unpleasant. But this problematic in case I want (and I probably will) change the definition of \stx
.
I thought of changing the spacing around the operators with a command, like this
\newcommand{\tightBinOps}[1] {\medmuskip=1mu\relax #1}
\newcommand{\stx}[3] {\ensuremath{#1[\tightBinOps{#2}\!:\!\tightBinOps{#3}]}\xspace}
However, this has two problems:
- It affects the whole document. I don't know how to restrict the spacing modification only to that specific expression;
- I guess I shouldn't rely on the spacing between operators being
\medmuskip
or any other particular measure in every circumstance.
How could I safely write \tightBinOps
—and, more importantly, should I write it or is there a better solution?
MCVE
\documentclass{article}
\newcommand{\tightBinOps}[1] {\medmuskip=1mu\relax #1}
\newcommand{\stxOriginal}[3] {#1[#2\!:\!#3]}
\newcommand{\stxModified}[3] {#1[\tightBinOps{#2}\!:\!\tightBinOps{#3}]}
\begin{document}
Too much space in $a+1$ here: $\stxOriginal{s}{a}{a+1}$
Desired space in $a+1$ here: $\stxModified{s}{a}{a+1}$.
But this affects the + operator when I use it in the same math
entry as a subsequence:
Compare:
\noindent$1+1~\stxModified{s}{a}{a+1}$\\
$1+1~\stxOriginal{s}{a}{a+1}$
\end{document}
{+}
or{:}
. much less complicated than trying to redefine the spacing. another approach is to use\mathord
as shown in answers to this question: Correct spacing when using \sim as negation – barbara beeton Feb 8 '17 at 20:24$1{,}25$
, for instance gives the correct spacing, while$1,25$
does not. – giusti Feb 8 '17 at 23:08