Assume we have an infix binary operator *
with precedence level 0 (highest precedence), and another infix binary operator @
, with precedence level 1 (lower than *). Also, assume we have two relational operators ~
(precedence level 2) and ~
(precedence level 3).
Note: the symbols I have chosen don't matter, I am trying to select arbitrary ones, because I might need to define arbitrary operators in my use case.
An expression involving these operators should look something like this:
a*b @ c*d ~ a*b || a*b ~ c @ d
The spaces in this expression match up with the precedence level (0 spaces for precedence level 0, and so on).
I'd like to do something similar in LaTeX by defining operators with a command that looks something like this:
\precedenceop{<relational or binary operator?>}{<precedence level>}{<symbol>}
I have learned today that:
\medmuskip
controls spacing for binary operators,\thickmuskip
for relational operatorsI can use the
xstring
package to deal with conditional cases
So I envision that my command would look something like:
\usepackage{amsmath}
\usepackage{xstring}
\newcommand{\precedenceop}[3]{%
\IfEqCase{#1}{%
{rel}{<do stuff with \thickmuskip using #2 (the precedence level) and #3 (the symbol)>}%
{bin}{<do stuff with \medmuskip using #2 (the precedence level) and #3 (the symbol)>}%
}[\PackageError{tree}{Undefined option to tree: #1 (should be rel or bin)}{}]%
}
Another question I made attempted to go about the problem a different way, and had a suggested solution of manipulating the skips using something like:
\mspace{-\muexpr\medmuskip/2}
<symbol, #3>
\mspace{-\muexpr\medmuskip/2}
But it would be nicer if the 2
in this solution could be replaced by some function of #2 (preferably, some type of multiplication, because then 0 would map to 0mu, 1 could map to 2mu, and 2 could map to 4mu, and so on).
Anyway, how should I make the pieces come together properly to do what I'd like?
||
is gone). Thus a pure-ascii manipulation could prove more usable than TeX typesetting which is basically final thing. (I get control characters when copying from Acrobat) – user4686 Sep 19 '17 at 17:04