I want to define a simple macro that will be used in math mode formulae. The macro represents a mathematical relation. The way the relation is displayed (boldface etc) is not important. What matters is the spacing around it.

Specifically, if my macro is \likes, I want $a \likes b$ to appear with a space before the b, but I also want $\likes(a, b)$ not to appear with a space before the bracket. Is there a way to write a single macro that will behave as intended in those different contexts?

The question is not about what's natural for LaTeX but what's legible for the user of the macro. I would rather avoid having to write \likes{} or having two versions of the macro, one with spaces and one without.

Rendered example

    I want to be able to write all of the following:

    \verb+``$a \likes b$''+, yielding ``$a\ \textbf{likes}\ b$''

    \verb+``$\likes(a,b)$''+, yielding ``$\textbf{likes}(a,b)$''

    \verb+``$(a,b) \in \likes$''+, yielding ``$(a,b) \in \textbf{likes}$''

    With the definition \verb+\newcommand{\likes}{\textbf{likes}}+ I get:


    \verb+``$a \likes b$''+ gives ``$a \likes b$'' (BAD, missing space
    before and after)

    \verb+``$\likes(a,b)$''+ gives ``$\likes(a,b)$'' (GOOD)

    \verb+``$(a,b) \in \likes$''+ gives ``$(a,b) \in \likes$'' (GOOD)

    With the definition \verb+\newcommand{\likes}{\textbf{ likes }}+ I

    \renewcommand{\likes}{\textbf{ likes }}

    \verb+``$a \likes b$''+ gives ``$a \likes b$'' (GOOD)

    \verb+``$\likes(a,b)$''+ gives ``$\likes(a,b)$'' (BAD, unwanted spaces)

    \verb+``$(a,b) \in \likes$''+ gives ``$(a,b) \in \likes$'' (BAD, unwanted  

  • To my knowledge it's possible to do if-then-else like things in macros. However, it might be easier and more straight forward to just define a handful of simple macros, like \likesA, \likesB etc. and use them depending on context.
    – MS-SPO
    Commented Jul 26, 2023 at 8:28

1 Answer 1


You can define \likes as \mathbin:

\def\likes{\mathbin{\rm likes}}

%% TEST:
$a \likes b$       % prints: a likes b

$\likes(a,b)$      % prints: likes(a,b)

$(a,b) \in \likes$ % prints: (a,b) ∈ likes

  • 1
    Excellent, thank you, just what I needed! And works in Latex too as \newcommand{\likes}{\mathbin{\textbf{likes}}}.
    – st01
    Commented Jul 26, 2023 at 11:40

You must log in to answer this question.

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