9
$\begingroup$

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.

$\endgroup$
8
$\begingroup$

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 OverlayBoxes:

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.

$\endgroup$
  • 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$ – Stephen Luttrell Aug 5 '15 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$ – MarcoB Aug 5 '15 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$ – Jens Aug 5 '15 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$ – MarcoB Aug 5 '15 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$ – Jens Aug 5 '15 at 22:26
0
$\begingroup$

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.

$\endgroup$

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.