8

Let's say I don't like the way the + symbol is printed inside equation: is there a way to change its appearance without defining a new command?

More generally, is it possible to create a command without the initial backslash?

3
  • 3
    Welcome to TeX.SE. Please be a bit more specific regarding your dislike for the way the + symbol is printed in math mode. Is it its size, shape, height above the baseline, spacing relative to adjoining symbols, or something else entirely? Separately, which (math) font do you use?
    – Mico
    Commented Nov 24, 2015 at 16:36
  • Related: tex.stackexchange.com/questions/2969/… Commented Nov 24, 2015 at 16:39
  • I asked a new question on how to redefine multiple symbols. e.g. minus, plus and plusminus: tex.stackexchange.com/questions/361807/…
    – lblb
    Commented Apr 2, 2017 at 20:28

2 Answers 2

17

Yes, of course.

\documentclass{article}

\begingroup
\catcode`+=\active
\gdef+{\mathbin{\mathrm{blurb}}}
\endgroup
\AtBeginDocument{\mathcode`+="8000 }

\begin{document}
$x+y$
\end{document}

enter image description here

Of course you can think to better definition for the “math active” +. ;-)


A more general approach where you can also use an equivalent of the character being “redefined”.

\documentclass{article}

\makeatletter
\newcommand{\mathactivedef}[3][]{%
  \begingroup\lccode`~=`#2\lowercase{\endgroup\def~}{#3}%
  \if\relax\detokenize{#1}\relax
  \else
    \@ifdefinable{#1}{\mathchardef#1=\mathcode`#2\relax}%
  \fi
  \AtBeginDocument{\mathcode`#2="8000 }%
}
\@onlypreamble{\mathactivedef}
\makeatother

\mathactivedef[\keptplus]{+}{\mathbin{(\mkern-2mu\keptplus\mkern-2mu)}}

\begin{document}

$x+y$

\end{document}

In the optional argument to \mathactivedef you set the equivalent name that you can use in the body of the redefinition.

enter image description here

The previous “blurb” (without keeping the meaning of +) would be

\mathactivedef{+}{\mathbin{blurb}}
7
  • 11
    I understand the making + active part. But can you elaborate on what the \mathcode does and why it must occur \AtBeginDocument? Commented Nov 24, 2015 at 16:55
  • You could have chosen something more interesting than blurb. How about this\ is\ Sparta?
    – Gaussler
    Commented Jun 24, 2021 at 14:08
  • Actually, I would like to know the answer to Steven’s question, too. Are you gonna answer? ;-)
    – Gaussler
    Commented Jul 2, 2021 at 16:03
  • 1
    @antshar I added a more general way that copes with your problem
    – egreg
    Commented Jul 3, 2022 at 9:47
  • 1
    @antshar Not completely, though.
    – egreg
    Commented Jul 3, 2022 at 10:42
0

I found a really great, more general answer at https://newbedev.com/make-characters-active-via-macro-in-math-mode (at the bottom of the page).

1

You must log in to answer this question.

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