1

I'd like to have easy access to commonly used relation symbols in text mode, just as they are easily accessible in math mode. An important example is ⊕, or \oplus. I'd like to configure the control symbol \+ to use it:

\documentclass{article}
\usepackage{amsmath}
\NewDocumentCommand{\+}{}{\ensuremath{\oplus}}

\begin{document}
    \section{Upright}
    a \+ b\\ 
    $ \text{a} \oplus \text{b} $
        
    \section{Italics}
    \textit{a} \+ \textit{b}\\
    $a \oplus b$
\end{document}

While this works, I still need to optimise the spacing so that it matches, or is similar to, the spacing in math mode: enter image description here

I've tried the following:

  • changing the value of \mathsurround in the definition, i.e. \NewDocumentCommand{\+}{}{\mathsurround=0pt\ensuremath{\oplus}} (I believe this is already the default)
  • using \mathrel around \oplus in the definition.

None of these approaches have worked. One additional idea I had was to access the \oplus symbol directly, but the Unicode symbol would not link to the math relation symbol in the font I use. Is there another way?

4
  • 1
    You can try \NewDocumentCommand{\+}{}{\ensuremath{\mbox{}\oplus\mbox{}}} and use \+ without surrounding spaces in text mode. – gernot Jan 20 at 16:42
  • this seems to be encouraging very dubious markup, the math and text a and b come from separate fonts for example. TeX markup by design chooses to make a clear distinction between math and text. – David Carlisle Jan 20 at 22:38
  • @DavidCarlisle Yes, this Q doesn't make sense when one has the usual usage pattern of math mode in mind that is used in math or physics, etc. However, in some formal areas of the humanities and SocSci, formalisms work/are used there in a quite different practice. I should have mentioned that. – Felix Emanuel Jan 21 at 11:36
  • @FelixEmanuel sure but in such cases I would have expected that a word space rather than the math space would be what is expected, but anyway feel free to ignore me wipet has already provided the same answer I would have given:-) (except without the hbox) – David Carlisle Jan 21 at 11:59
2

You can try:

\def\+{\leavevmode\unskip\hbox{${}\oplus{}$}\ignorespaces}

This ignores space before and after \+ and adds the spaces from math mode.

1
  • 1
    I'd probably not use the hbox here (to allow the space to stretch) but it depends what the OP wants... – David Carlisle Jan 21 at 12:00
1

If you want math-mode typesetting, what you really want is to switch to math mode, but typeset the arguments as text. Both \textup and \texit work in math mode. You could also use \mathrm or \mathit.

\documentclass{article}
\usepackage{amsmath}

\newcommand\plusify[2]{\( \text{#1} \oplus \text{#2} \)}

\begin{document}
    \section{Upright}
    \( \textup{a} \oplus \textup{b} \)
    \plusify{a}{b}
    \( \text{a} \oplus \text{b} \)
    \(\mathrm{a} \oplus \mathrm{b} \)
        
    \section{Italics}
    \( \textit{a} \oplus \textit{b} \)
    \plusify{\itshape a}{\itshape b}
    \( a \oplus b \)
    \( \mathit{a} \oplus \mathit{b} \)
\end{document}

Computer Modern sample

3
  • From a technical point of view, this is probably the cleanest solution. However, if one needs to use that relation very often, typing a control symbol is much less of a hassle than a sequence + argument, and it makes for more readable code. – Felix Emanuel Jan 21 at 11:32
  • @FelixEmanuel It comes down to personal preference, but I would probably write macros for the text arguments instead. – Davislor Jan 21 at 11:33
  • @FelixEmanuel Besides, you could make the two-argument macro \+ a b, which is just as short. – Davislor Jan 21 at 11:35

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.