I want to define a command, call it \dotted, that adds a period at the right place next to certain other math characters*: to the right of function-like tokens, i.e. Ord and Op, and to the left of operator-like ones, i.e., Bin and Rel. This "meta-operator" should of course preserve the spacing of the original "operator". I came up with the following preliminary solution:



\[x = \dottedord{\sigma}(y) \qquad x = \sigma(y)\]
\[x = \dottedop{\log}(y) \qquad x = \log(y)\]
\[x = y \dottedbin{+} z \qquad x = y + z\]
% This case is special...
\[x \dottedrel{=} y \qquad x \mathrel{.=} y \qquad x = y\]

Equation output

How can I unify the four commands into one, dispatching on the type of the argument -- is there something like \mathchoice for math types? And why do I need to place the argument of \dottedrel outside \mathrel to get satisfactory spacing?

If there's something more fundamental to improve, I'd be happy to hear about that as well, of course.

*This is Julia's syntax for vectorization or "broadcasting", which can be applied to all functions and operators, but that's not really relevant here.

  • 1
    Possibly useful to you, if you will be applying the operator to a limited set of symbols: tex.stackexchange.com/a/370253/61644 – Davislor May 13 '19 at 21:39
  • 1
    Another approach might be to pass in the math class as an option, e.g. \broadcast[ord]{\sigma} and use \csname to generate the \mathord command from that. – Davislor May 13 '19 at 21:41
  • Although this is almost the opposite of what you asked, you could also define \arrayplus, \arrayassign, etc. – Davislor May 13 '19 at 22:37
  • @Davislor Thanks, but all of that is not really better than simply \mathord{\sigma.} or \mathop{.+}, in my opinion. The question you linked to seems to be asking the same thing, but -- though I don't really understand the expl3 stuff -- it still seems to check a fixed, given list of symbols... – phipsgabler May 14 '19 at 8:54

You can use the \binrel@ test defined by amsmath (precisely by amsbsy) in order to distinguish between \mathrel and \mathbin. If the test doesn't return one of these, you can define your own for \mathop and others; see this answer of mine for details about \binrel@, the idea for \phg@ordop is similar.

If you don't have to support operators with limits this should suffice.

%\usepackage{amsbsy}% loaded by amsmath

  \ifx\binrel@@\mathbin \mathbin{.{#1}}\else
  \ifx\binrel@@\mathrel \mathrel{.}#1\else
    % operator


x = \dotted{\sigma}(y) \qquad x = \sigma(y) \\
x = \dotted{\log}(y) \qquad x = \log(y) \\
x = \dotted{\log} y \qquad x = \log y \\
x = y \dotted{+} z \qquad x = y + z \\
x \dotted{=} y \qquad x = y


enter image description here

  • 1
    With even better spacing! This is great. – phipsgabler May 14 '19 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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