1

I have a document with equations containing many mathematically not strictly necessary brackets. These brackets are customary in order to simplify the identification of certain blocks of the equations. However, they also bring a lot of noise into the document. I was considering to replace the brackets with a spaces around these blocks. In order to play around with this idea I want to define a macro that defines something like a new math atom that ensures that there is a space whenever two of these new atoms are next to each other or next to a mathord atom. However, when this new atom is next to a mathrel, mathbin or another of the usual math atoms it should just behave like a mathord.

\documentclass{article}
\begin{document}
The $abc$ and $def$ are distinct blocks within the equations.
They are highlighted using brackets.
\[y = x (abc)(def) z\]
\[y = (abc) x + (def) xz\]

I would like to automatically highlight them with spaces using a macro.
The outcome should look similar to this.
\[y = x \;\, abc \;\, def \;\, z\]
\[y = abc \;\, x + def \;\, xz\]
\end{document}
  • Are these “blocks” normal math symbols stuck together by multiplication or “strings of letters”? – egreg May 27 '20 at 10:21
  • Its all math connected by omitted operators, no text involved. – Jan Hajer May 27 '20 at 10:23
  • This looks like \mathop spacing, with a larger \thinmuskip. Alas, you can only have one value of \thinmuskip in a formula. – egreg May 27 '20 at 10:34
  • Yes this is roughly, what I was looking for. – Jan Hajer May 27 '20 at 10:54
2

EDIT

By more testing (even after adding extra double braces), the answer was not correct when:

  • The macro is followed by another similar macro
  • The macro is followed by another operator (+, -, ...)

In both cases an extra thin space is added.


Original Answer

You can use \operatorname in the definition of your macro, instead of spaces \, \; ,... since the former has a better control for inter spacing when two successive macros of this type are used, or when encountering another operator (+, -, =, etc).

enter image description here

\documentclass{article}
\usepackage{amsmath}
\newcommand*{\distinctblock}[1]{{\operatorname\relax {#1} \operatorname\relax}}
%
\begin{document}
%
%
The $abc$ and $def$ are distinct blocks within the equations.
They are highlighted using \textbf{brackets}.
\[y = x (abc)(def) z\]
\[y = (abc) x + (def) xz\]

Highlighted using the custom command \textbf{distinctblock}

\[y = x \distinctblock{abc} \distinctblock{def} z\]
\[y = \distinctblock{abc} x + \distinctblock{def} xz\]
%
\end{document}
  • 1
    Is this different from \mathop{}? – Donald Arseneau May 27 '20 at 10:28
  • @Donald Arseneau Here is a better explanation of the difference than I would ever do!! tex.stackexchange.com/a/84308/91556 – hesham May 27 '20 at 10:48
  • 1
    This macro adds roughly the space I was looking for, but is also adds some space when used after a mathrel or a mathop, which I would like to avoid. – Jan Hajer May 27 '20 at 10:52
  • @hesham yes but as egreg explains there the difference is mostly about setting the argument in a suitable font, but as your argument is just \relax I think it doesn't do anything here. – David Carlisle May 27 '20 at 10:55
  • @David Carlisle As I understand, the \operatorname has two effects, changing of font style and adjusting spacing. If the \relax argument is removed, the \operatorname will affect the argument in question abc by changing its font style to operator fonts style (no longer math font style, i.e. behaves like sin and cos ops) in addition to changing the spacing. The OP is requiring adjusting the spacing only, hence \relax was inserted. – hesham May 27 '20 at 11:10

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.