Message Boards Message Boards

0
|
5508 Views
|
3 Replies
|
7 Total Likes
View groups...
Share
Share this post:

Need to define a new special character and save it for further use?

Posted 10 years ago

Hi,

More concrete, I need to define a kind of "partial function arrow" i.e. a circle ([EmptyCircle] for example) superimposed over an arrow ([LongRightArrow] for example) and I'd like to save it such that to easily use it anytime.

Thank you !

3 Replies

Thank you very much Jesse ! and Thank you very much David !

All the best to both of you!

Picking up on Jesse's excellent answer, here is a way that you can get an evaluable expression and not just a character. (With just a character you may have trouble using it in Input expressions.)

Define a PartialFunction expression:

PartialFunction::usage = 
  "PartialFunction[x,y] displays as a function with a partial function notation.";

Then define a MakeBoxes for it:

MakeBoxes[PartialFunction[x_, y_], 
  form : StandardForm | TraditionalForm] :=
 InterpretationBox[#1, #2] & @@ {RowBox[{MakeBoxes[x, form], 
     MakeBoxes[
      Style[Overlay[{"\[EmptyCircle]", "\[LongRightArrow]"}, 
        Alignment -> Center], ShowStringCharacters -> False], form], 
     MakeBoxes[y, form]}], PartialFunction[x, y]}

Now evaluate and also look at the full form.

PartialFunction[X, Y]
% // FullForm

This can be copied and pasted. And you can actually get some evaluable expressions using Rule programming. Here's my attempt at the square root as a function of the positive integers.

f = PartialFunction[{x, x \[Element] Integers && NonNegative[x]}, 
  ConditionalExpression[Sqrt[x], Sqrt[x] \[Element] Integers]]
f /. x -> 4
f /. x -> 3
f /. x -> \[Pi]

One could probably do better as a way of notation, but I'm not up to it.

I'm afraid you can't create a special character of the form \[PartialFunctionArrow], (that would require changing the Mathematica font) but you can define a constant at startup that contains that character.

Here's my super-beautiful partial function arrow:

PartialFunctionArrow=Overlay[{"\[EmptyCircle]", "\[LongRightArrow]"}, Alignment -> Center];

Put the following in $UserBaseDirectory/Autoload/Custom Characters/init.m: (create any nonexistent folders in that path)

(** User Mathematica initialization file **)

PartialFunctionArrow=Overlay[{"\[EmptyCircle]", "\[LongRightArrow]"}, Alignment -> Center];

Now when you start Mathematica, the symbol PartialFunctionArrow will be your special character. You can't have it autoinsert in text like other special characters, but at least it's there.

POSTED BY: Jesse Friedman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract