Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #4464 > unrolled thread
| Started by | Ethan Dyer <ethansdyer@gmail.com> |
|---|---|
| First post | 2011-08-19 10:34 +0000 |
| Last post | 2011-08-21 09:31 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
A two part notation question Ethan Dyer <ethansdyer@gmail.com> - 2011-08-19 10:34 +0000
Re: A two part notation question Simon <simonjtyler@gmail.com> - 2011-08-21 09:31 +0000
| From | Ethan Dyer <ethansdyer@gmail.com> |
|---|---|
| Date | 2011-08-19 10:34 +0000 |
| Subject | A two part notation question |
| Message-ID | <j2le74$ndf$1@smc.vnet.net> |
Hi. I have a two part question regarding notation in general and OverBar in particular. Part 1) There seems to be a peculiarity in the notation package which I would like to know how to get around. The following works correctly: <<Notation` Notation[ParsedBoxWrapper[OverscriptBox["x_","a"]]<=>ParsedBoxWrapper[RowBox[List["f","[","x_","]"]]]]. This replaces f[x_] with the letter "a" appearing over x_. What I really want to do is have f[x_] display as OverBar[x] for both input and output. When I try to do this: Notation[ParsedBoxWrapper[OverscriptBox["x_","_"]]<=>ParsedBoxWrapper[RowBox[List["f","[","x_","]"]]]]. I get an error because Notation interprets the underscore that should appear over the argument as another Blank to be matched. My first question is how to do this correctly in the notation package? Part 2) What is the way to do this correctly, not using Notation. I can do Format[f[x_]]:=OverBar[x] which works great for output. What is the correct way to have this also work for input, ie be able to copy and paste expressions with overbar apearing? Thank you very much. Ethan
[toc] | [next] | [standalone]
| From | Simon <simonjtyler@gmail.com> |
|---|---|
| Date | 2011-08-21 09:31 +0000 |
| Message-ID | <j2qjad$ctp$1@smc.vnet.net> |
| In reply to | #4464 |
Sometimes with these things it's easiest to resort to the low level MakeBoxes and MakeExpression. E.g.
f /: MakeBoxes[f[x_], form_] := With[{boxes = ToBoxes[x]},
InterpretationBox[OverscriptBox[boxes, "_"], f[x]]]
Unprotect[OverscriptBox];
OverscriptBox /: MakeExpression[OverscriptBox[x_, "_"], form_] :=
MakeExpression[RowBox[{"f", "[", x, "]"}], form]
Protect[OverscriptBox];
These definitions are stored in FormatValues[f] and FormatValues[OverscriptBox].
Although they don't need to be defined with TagSet (/:). Also, the InterpretationBox is probably overkill since we have the MakeExpression definition.
You can check that things are working with
In[7]:= f[x] // ToBoxes
Out[7]= InterpretationBox[OverscriptBox["x", "_"], f[x]]
In[8]:= Overscript[a+b, _]//FullForm
Out[8]//FullForm= f[Plus[a,b]]
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web