# Make \scalebox work in subscript mode accordingly

I created a simple macro to type a kind of a range notation (a:b) with a larger colon do distinguish if from normal text.

This is the macro with a MWE:

\documentclass{minimal}
\usepackage{graphicx}

\newcommand{\range}[3][]{%
\def\rangedbldot{\scalebox{1.4}{:}}%
\if\relax\detokenize{#1}\relax%
\ensuremath{#2\rangedbldot#3}%
\else%
\ensuremath{#2\rangedbldot#1\rangedbldot#3}%
\fi%
}

\begin{document}
$$1{:}2$$

$$\range{1}{2}$$

$$a_{\range{1}{2}}$$
\end{document}


This is the result:

What I would expect is that since I'm using a \scalebox, not a \resizebox, the scaled colon would be proportional to the current font size, that in subscripts is a little bit smaller than in normal text. But apparently that's not the case.

What have I got wrong here? And how do I fix the macro to make the colon proportional on both cases?

• \scalebox and \resizebox are essentially the same thing, just a different syntax for the scale factor what you are scaling in either case is \mbox{$:$} which does not get smaller in subscripts – David Carlisle Dec 1 '17 at 23:24
• also it's best not to use minimal class for tests as it does not set up the fonts fully so you can often get artifacts there that will not be a problem in real classes. It'd avoid scaling and use something like \bm{:} to get a bold : or if you want to scale use amsmath then \text{\scalebox{...}} the \text macro will take care of setting the size in subscripts – David Carlisle Dec 1 '17 at 23:27

Use \mathpalette, see The mysteries of \mathpalette

\documentclass{article}
\usepackage{graphicx}

\newcommand{\range}[3][]{%
\if\relax\detokenize{#1}\relax
\ensuremath{#2\rangedbldot#3}%
\else
\ensuremath{#2\rangedbldot#1\rangedbldot#3}%
\fi
}
\newcommand{\rangedbldot}{\mathpalette\dorangedbldot\relax}
\newcommand{\dorangedbldot}[2]{%
\scalebox{1.4}{$#1:$}%
}

\begin{document}
$$1{:}2$$

$$\range{1}{2}$$

$$a_{\range{1}{2}}$$
\end{document}


• Thanks! This worked perfectly. It'll take me a while to understand the mysteries of \mathpalette :P – Phelype Oleinik Dec 1 '17 at 23:41

Here I use \ThisStyle{...\SavedStyle...} of the scalerel package to carry the appropriate math-size into the \scalebox.

\documentclass{minimal}
\usepackage{graphicx,scalerel}

\newcommand{\range}[3][]{%
\def\rangedbldot{\ThisStyle{\scalebox{1.4}{$\SavedStyle:$}}}%
\if\relax\detokenize{#1}\relax%
\ensuremath{#2\rangedbldot#3}%
\else%
\ensuremath{#2\rangedbldot#1\rangedbldot#3}%
\fi%
}

\begin{document}
$$1{:}2$$

$$\range{1}{2}$$

$$a_{\range{1}{2}}$$
\end{document}


I would use a font change, but if you want to scale it is easier to use \text than use mathpalette directly.

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

\makeatletter
\newcommand{\range}[3][\@gobble]{%
\ensuremath{#2\rangedbldot#1\rangedbldot#3}%
}
\makeatother

\begin{document}

\begin{minipage}{.2\textwidth}
\def\rangedbldot{\scalebox{1.4}{:}}

$$1{:}2$$

$$\range{1}{2}$$

$$a_{\range{1}{2}}$$
\end{minipage}
\begin{minipage}{.2\textwidth}
\def\rangedbldot{{\bm{:}}}

$$1{:}2$$

$$\range{1}{2}$$

$$a_{\range{1}{2}}$$
\end{minipage}
\begin{minipage}{.2\textwidth}
\def\rangedbldot{\text{\scalebox{1.4}{:}}}

$$1{:}2$$

$$\range{1}{2}$$

$$a_{\range{1}{2}}$$
\end{minipage}

\end{document}

• Indeed using \text is far less complicated than using \mathpalette. But as a matter of choice I prefer avoiding the dependence on other packages (even though I don't know if I have ever NOT used amsmath). But thanks a lot anyways! – Phelype Oleinik Dec 1 '17 at 23:47
• @PhelypeOleinik amsmath and bm the two packages I used there are part of the required core latex distribution, so using them offers no more dependencies than using minimal class or article class. – David Carlisle Dec 1 '17 at 23:53