4

The default definitions of \min and \max insert basically no space after them, which looks really awful when stating optimisation problems, etc., in display equations. I could not figure out any way automatically insert space after them? The following, for one, did not work:

\renewcommand{\min}{\expandafter\,\operatorname*{min}}

The space still came before min. Is there a way that still causes super- and subscripts to be parsed correctly?

Addition: What I basically want is

\min_u\, G(u) + F(Ku)

in a display equation, without having to enter \, manually. A more complete statement, giving a better idea of the type of expressions, would be

\min_{u \in X}\, G(u)+F(Ku) \quad\text{subject to}\quad Au=b.

You really want that extra space there, but it would be nice not have to enter it manually.

10
  • 3
    \min and \max add a thin space after them if the following item is not a delimiter (parenthesis, square bracket, \lvert and so on). This is what the standard typesetting rules prescribe. Can you make an example of what you mean?
    – egreg
    Jul 16, 2014 at 16:47
  • What I want, basically, is \[ \min_u\,G(u) + F(Ku) \] without having to enter \, manually. The standard spacing is too thin in this kind of expressions, denoting optimisation problems instead of just simple min/max expressions. It is very uncommon to enter parenthesis around the expression to be minimised, and a pain to enter the \, manually.
    – Thom
    Jul 16, 2014 at 19:08
  • @Thom If you think it's too small, you might want to change the \thinmuskip value which controls the spacing around (for instance) operators. You can change it with \thinmuskip=2\thinmuskip or whatever value. However, I'm not sure why would you that… What is so bad? You can't spot the space that is already inserted?
    – Manuel
    Jul 16, 2014 at 19:20
  • 1
    In the optimisation literature, parentheses are uncommon. I do not need style advise from someone clearly not working in the same field. I just want the (La)TeX code to do this.
    – Thom
    Jul 16, 2014 at 19:36
  • 1
    Sorry, but “I want” ends the discussion: “l'erba voglio non cresce nemmeno nel giardino del re” mothers used to say. I'm sure there's a similar saying in English.
    – egreg
    Jul 16, 2014 at 19:38

3 Answers 3

8

The default definition of \min is

\def\min{\mathop{\operator@font min}}

so it is an operator like \log and will get a thin space in \min x but not in \min(x)

Your redefinition

\renewcommand{\min}{\expandafter\,\operatorname*{min}}

is the same as

\renewcommand{\min}{\,\operatorname*{min}}

and puts an additional thin space before the operator. the only effect of the \expandafter is to expand \operatorname one step before executing \, so your definition is actually equivalent to

\renewcommand{\min}{\,\protect\operatorname_*{min}}

where _ denotes a space character as one level of expansion just reveals the \protect that makes it a robust command.

5
  • 1
    I know my definition is useless. That's why I'm asking.
    – Thom
    Jul 16, 2014 at 19:30
  • @Thom I guessed you had spotted it didn't work I was just explaining why not. I didn't address the other part of your question as your initial sentence is false, \min typically does add space after, it has the same space rules as \log so I wasn't sure there was anything to do there. Jul 16, 2014 at 21:44
  • all this squeezed between makeatletter and makeatother right?
    – PatrickT
    Nov 7, 2017 at 6:40
  • @PatrickT I am not sure what you mean by your comment but no, none of the code sections shown above uses @ except the first, and that doesn't need an explicit \makeatletter as it is in the format code wher , like package code @ is implicitly a letter. Nov 7, 2017 at 9:12
  • Thanks David. Oh, okay. I wasn't able to make the first line of code work (the one with the @), unless it was between the make construct. Tested in a MWE. pastebin.com/ZqEjt348
    – PatrickT
    Nov 7, 2017 at 9:21
7

As explained by egreg in his first comment, \min et. al. have the correct spacing when followed by a delimiter, because by intention, they operate on a set of values (over which to take the minimum). As you use it,

\min_u G(u) + F(Ku)

the expression is itself ambiguous, and the natural parsing as "minimum of G(u), plus...oh wait" causes some dissonance halfway through. So the real answer is not to do this, and write

\min_u \{ G(u) + F(Ku) \}

instead. As a bonus, you can drop the subscript and add some more lengthy conditions that would look bad in small print, like

\min_u \{ G(u) + F(Ku) \mid u \in X, Au = b \}

which has the advantage over your second snippet,

\min_{u \in X}\, G(u)+F(Ku) \quad\text{subject to}\quad Au=b

of not incorrectly making an external reference to the "bound variable" u outside its scope.

I realize that you may believe you are following some kind of convention in your field by omitting the delimiters. However, unless you have given the matter specific thought and developed a strong opinion, you should consider changing your style here, since it has both typographic issues (as you observed) as well as mathematical ones.

P.S. If you really must do it this way, probably the easiest workaround is to use an argument rather than a subscript. For instance,

\newcommand*\mymin[1][]{\min_{#1}\,}

See this minimal document comparing it with the "standard":

\documentclass{article}
\newcommand*\mymin[1][]{\min_{#1}\,}
\begin{document}
$\min A \quad \min_u A$

$\mymin A \quad \mymin[u] A$
\[ \min A \quad \min_u A\]
\[ \mymin A \quad \mymin[u] A\]
\end{document}

Comparison of two min macros

Why not use the subscript character directly? First, because parsing it is a pain, as it does not "collect" its argument conveniently as macros do, and therefore, it makes moving that argument difficult. And second, from a programming standpoint, there is only one thing you want to do with \min, which is subscript it, so it is more logical to associate it with an abstract "do this" operation. The abstraction has the nice side effect of enabling an abstract implementation, namely, to place a space afterwards.

3
  • One has to differentiate between two different 'min'. One is an operator, that one could use inside a longer expression, like x+ min\{1,y\}. I would always use the braces there. In the optimisation literature, one also has a min 'command'. One could equivalently, and perhaps more correctly, write 'minimise G(u)+F(Ku)' instead of 'min', but 'min' is a standard shorthand. Here one rarely uses parentheses. Some authors use a LaTeX array to lay out 'minimise' and 'subject to' in the left column, and the expression in the right column. But simple extra space is more common in my experience.
    – Thom
    Jul 17, 2014 at 14:34
  • 1
    @Thom I see, thanks. Otherwise, does my solution work for you?
    – Ryan Reich
    Jul 17, 2014 at 14:35
  • It does, of course work. I'm sticking to Manuel's solution for now, although was thinking of also something else: \min_u\objective{G(u)+F(Ku)}, where \objective uses phantom parentheses to get a more parenthesis-like spacing. The problem with actually adding \, automatically at the end is that \min \max becomes clumsy -- one does not want the extra space between them.
    – Thom
    Jul 17, 2014 at 14:40
1

Temporary solution. This one just checks if there is a subscript next to it. Nothing more.

\documentclass{scrartcl}
\usepackage{mathtools}
\makeatletter
\def\raremin{\@ifnextchar_\@rareminsub\@raremin}
\def\@rareminsub_#1{\min_{#1}\,}
\def\@raremin{\min\,}
\makeatother
\begin{document}
$ \raremin_u G(u) + F(Ku) $
\[ \raremin_u G(u) + F(Ku) \]
\end{document}

enter image description here

9
  • Of course this won't center the subscript below “min”.
    – egreg
    Jul 16, 2014 at 19:36
  • Hence the temporary.
    – Manuel
    Jul 16, 2014 at 19:36
  • This is not too bad, actually, but most importantly will fall apart in inline math. But there the spacing is not really wanted, and one can easily define a version that works differently there.
    – Thom
    Jul 16, 2014 at 19:41
  • @Thom It would be easy to make a macro that adds \, after looking if there is a subscript/superscript (or both); easy with \@ifnextchar and a few helper macros. But I hope someone comes with some magic that introduces the \, after the subscript/superscript in a more straightforward way.
    – Manuel
    Jul 16, 2014 at 19:44
  • The latest version works perfectly well. Thanks a lot.
    – Thom
    Jul 16, 2014 at 21:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .