24

I am trying to find a way to define the % symbol as a binary operator that behaves essentially like the + symbol. I have heard of the command DeclareMathOperator, but I was under the impression that this was for operators like the logarithm and sine functions. What is an appropriate command? An an example, I would like the following to lines to have similar spacing.

\begin{equation*}
a % b % c
\end{equation*}
\begin{equation*}
a + b + c
\end{equation*}
Carl Morris
  • 761
  • 1
  • 7
  • 14

2 Answers2

26

If using macros to represent the new symbol is fine, then you have a couple of options:

enter image description here

\documentclass{article}
\newcommand{\percA}{\mathbin{\%}}
\newcommand{\percB}{\mathbin{\ooalign{$\hidewidth\%\hidewidth$\cr$\phantom{+}$}}}
\begin{document}
\[\begin{array}{|@{}c@{}|}
  a \percA b \percA c \\[\jot] % Option A
  a \percB b \percB c \\[\jot] % Option B
  a + b + c % Control
\end{array}\]
\end{document}

Option A \percA inserts \% as a binary math symbol using \mathbin{\%}. However, \% is slightly wider than +. That's where option B provides \percB which oversets a zero-width \% with a \phantom{+}.

For the inner working behind \ooalign, see \subseteq + \circ as a single symbol (“open subset”).

Werner
  • 603,163
  • 1
    Why the Google short link? I don't remember exactly where, but I think short links are generally frowned upon on SE. – doncherry Nov 13 '12 at 05:36
  • 1
    http://meta.stackexchange.com/q/29518/162565, http://meta.stackexchange.com/q/99136/162565, http://meta.stackexchange.com/q/64450/162565 -- not a clear ban of shortened URLs, but definitely a distinct dislike. – doncherry Nov 13 '12 at 05:42
  • 1
    @doncherry: The motivation was purely out of self-interest to track badge progress, since Google's URL shortner provides a "CLICKS" tally. There's no other way to estimate progress on badges like Announcer, Booster or Publicist. Do you know whether a tool for tracking these badges exist, even through some Ninja search or the Data Explorer? – Werner Nov 13 '12 at 06:00
  • No, none that I know of. While I don't think it's very likely, there might yet be one; I just recently learned that anonymous and low-rep user feedback is accessible via data.se .. even though it seems broken now, these queries used to work: http://data.stackexchange.com/tex/query/73917/anonymous-feedback-for-a-specific-question-and-its-answers, http://data.stackexchange.com/tex/query/60668/feedback-on-my-posts – doncherry Nov 13 '12 at 06:05
  • 1
    @doncherry: This seems to still be an open question on Meta.SO, dating back to 2010: View progress towards Announcer badge. Even then, one of the mods "suggest" a URL shortner. :-| – Werner Nov 13 '12 at 06:26
0

Late to the party, but here's what I believe to be a better proposal: the percent character at its natural size is too prominent, so I scale it to have the same width as + (but also adding some sidebearing).

\documentclass{article}
\usepackage{graphicx}

\makeatletter \DeclareRobustCommand{\perc}{% \mathbin{\mathpalette\scaletoplus@{\mkern1mu%\mkern1mu}}% } \newcommand{\scaletoplus@}[2]{% \vcenter{% \hbox{\sbox\z@{$\m@th#1+$}\resizebox{\wd\z@}{!}{$\m@th#1#2$}}% }% } \makeatother

\begin{document}

$a\perc b \cdot c + d_{u\perc v}$

$a+b$

\end{document}

enter image description here

egreg
  • 1,121,712