How can I use Feynman slash notation, e.g., $\require{cancel} \cancel{A}$, in Mathematica? I've seen some answer from 2008 which doesn't seem to work well in Mathematica 10. I'd like this to be part of the text and not a graphic such that I can use it as part of the text in a legend.
3 Answers
Here is a palette that does the slashing when you select a character and press the button:
CreatePalette[{Button["Slash it!",
NotebookWrite[InputNotebook[],
Replace[FromCharacterCode[
Join[ToCharacterCode[
ToString[NotebookRead[InputNotebook[]]]], {824}]],
FromCharacterCode[{8706, 824}] :>
OverlayBox[{"\<\[PartialD]\>", "\</\>"}]]]]}];
It uses the unicode character for a combining solidus (824
). This adds the slash to whatever character is printed in front of it.
Edit
Because operators such as $\partial$ don't allow combining marks in Mathematica, I had to add special treatment for $\partial$ in the form of an OverlayBox
. All I do is look for the result of the unicode combination to contain the sequence of characters corresponding to $\partial$ and the combining solidus, then replace that particular combination by an overlay. Using an Overlay
in all cases may also be workable, but I thought it's better to rely on the alignment provided by the built-in Unicode functionality.
Edit 2
While the above palette yields (I think) a cleverer representation of most slashed characters based on the Unicode standard, it doesn't seem to work on all platforms (it does work on Mac). Therefore, here is a simpler version that uses only OverlayBox
es:
CreatePalette[{Button["Slash it!",
NotebookWrite[InputNotebook[],
OverlayBox[{"\<" <> ToString[NotebookRead[InputNotebook[]]] <>
"\>", "\</\>"}]]]}];
To use either of these palettes, select the desired character in the notebook, hit the button, and you're done.
-
1$\begingroup$ I tried this on
\[PartialD]
— e.g. as in the Dirac equation — and the slash is placed after the derivative operator rather than through it. $\endgroup$ Commented Aug 5, 2015 at 20:21 -
$\begingroup$ Unfortunately I have the same problem that @StephenLuttrell does. I am on MMA 10.2 on Win7-64bit, in case that matters. $\endgroup$– MarcoBCommented Aug 5, 2015 at 22:16
-
$\begingroup$ @MarcoB I just added a fix for that (more a workaround). It could be extended to other special operators that aren't letters, if needed. $\endgroup$– JensCommented Aug 5, 2015 at 22:18
-
$\begingroup$ @Jens I tried your fix, but couldn't get it to work with any characters. Here's what I do: I executed your code, which generated the palette as expected. I then typed a character in an empty cell, selected it, and pressed "Slash it!". A slash was added following the character. Have I misunderstood how to use your tool? $\endgroup$– MarcoBCommented Aug 5, 2015 at 22:23
-
$\begingroup$ @MarcoB You did it exactly the way I intended. That's got to be a system-specific issue. It works for on Mac OS X, with Mathematica 10.1. You're saying it doesn't work with the $\partial$ character, either? $\endgroup$– JensCommented Aug 5, 2015 at 22:26
The position of any character can be shifted within Mathematica cells by highlighting the character, holding "Alt", and pressing arrow keys. Using this method, one can move slashes onto any other character.
For example,
becomes
which returns
The slash used here is not the standard keyboard forward slash but instead big solidus "⧸", which I copied and pasted from the output of FromCharacterCode[10744]
. (You can also copy it from this text!)
Other slash options include:
-
1
You can do this by first typing the symbol you want slashed and then adding negative spaces. The negative space is added by pressing escape followed by a - sign and the followed by between 1 to 4 spaces and the pressing escape again. I usually find I need to do 4 negative space twice followed by a negative space three times. I then type the slash which will generally align nicely over the symbol.