Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am investigating the use of the Notation package facilities to create strict the equivalence between pretty-printed symbols such as OverBar[SuperStar[af]] that formats as $\overline{af^*}$, and easy to type (but hard to read) symbols such as afstarbar.

My issue is that I fail at making two such symbols strictly equivalent.

I would like that, after typing Notation[ParsedBoxWrapper[\[Beta]]\[DoubleLongLeftRightArrow]ParsedBoxWrapper[beta]], I get the following behavior:

 In[] beta = 3 
Out[] 3

 In[] \[Beta] 
Out[] 3

 In[] \[Beta] = 0 
Out[] 0

 In[] beta     
Out[] 0

 In[] beta = 4 
Out[] 4

In[] Information[beta] 
Out[] \[Beta]
      \[Beta] = 4

It is to be noted that with Mathematica 8.0.0.0, the Notation behaves differently on Windows and Linux and on Mac, as I figured out by starting this reddit discussion, but on all platforms, I could not manage to get assignments to one symbol propagate to the other symetrically.

The behavior that I get instead of the above is:

 In[] beta = 3 
Out[] 3

 In[] \[Beta] 
Out[] 3

 In[] \[Beta] = 0 
Out[] 0

 In[] beta     
Out[] 3

 In[] beta = 4
Out[] 4

In[] Information[beta] 
Out[] \[Beta]
      \[Beta] = 4

Is there a way to get the scrict and robust equivalence between symbols instead of the assymetrical behavior shown above?

share|improve this question
    
I see both beta and \[Beta] being used in the above session. Is this a copy-and-paste issue? –  Sjoerd C. de Vries Jan 18 '12 at 16:40
1  
I do not think so. The OP want to type "beta" to input the symbol "[Beta]". In general the OP wants to type simple strings in order to input more complex strings. –  magma Jan 18 '12 at 17:15
    
@magma Exactly, thanks for clarifying that for me. –  agravier Jan 19 '12 at 4:11

2 Answers 2

up vote 5 down vote accepted

You appear to be looking for the functionality of $PreRead:

$PreRead = # /. "beta" -> "\[Beta]" &;

Mathematica graphics

share|improve this answer
    
Hotness! Thanks, I'll give PreRead a try ASAP. –  agravier Feb 2 '12 at 18:10
    
Some feedback: $PreRead = ReplaceAll[#, "afstarbar" -> OverBar[SuperStar["af"]]] & is accepted but then afstarbar gives Syntax::sntxi: Incomplete expression; more input is needed ., so I need to use $PreRead = ReplaceAll[#, "afstarbar" -> OverscriptBox[SuperscriptBox["af", "*"], "_"]] & where the _ is too low, or the same with [HorizontalLine], that makes a too thick bar. –  agravier Feb 3 '12 at 14:38
    
In a comment, @Rojo proposed me a neat solution: MakeBoxes[OverBar[x_], TraditionalForm] := OverscriptBox[#, "_", DiacriticalPositioning -> False] &[ MakeBoxes[x, TraditionalForm]] ; Now this plus $PreRead = ReplaceAll[#, "afstarbar" -> OverscriptBox[SuperscriptBox["af", "*"], "_"]] & works great, now my next goal is to let OverscriptBox[SuperscriptBox["af", "*"], "_"]] be a symbol to which I can assign values like to afstarbar, which I think I just managed to do using Symbolize from the ``Notation``` package: Symbolize[ParsedBoxWrapper["afstarbar"]]. I'm testing it more right now :P –  agravier Feb 3 '12 at 14:39
1  
@agravier I should have pointed out that $PreRead is operating on Box form, and needs to return an expression also in Box form. This is often most conveniently done with ToBoxes: $PreRead = ReplaceAll[#, "afstarbar" -> ToBoxes@OverBar@SuperStar@"af"] & Using that you should be able to assign to afstarbar. –  Mr.Wizard Feb 3 '12 at 17:53
1  
@agravier Related to what you are doing is the Format function, and the MakeBoxes[ ... ] := that you have already been shown. I suggest you look carefully at both of these. –  Mr.Wizard Feb 3 '12 at 17:54

What you are really looking for is InputAutoReplacements.

If I understand your question correctly you are looking for a simple/quick way to input mildly complex strings of characters. In your example you want to find an easy way to input $\beta$. But there is no point in creating another symbol beta, since the 2 symbols are meant to always be "equivalent" as you say. So you need to create an InputAutoReplacements option for the notebook.

This creates a new notebook. As soon as you type beta and then something else like space or "[" or an operation symbol you will get $\beta$.

nb = CreateDocument[{}, 
       InputAutoReplacements -> {"beta" -> "\[Beta]"}];

In case you just want to add this feature to your current notebook, you can use the Option Inspector, change the InputAutoReplacements option and save the notebook, to fix the changes.

A somewhat alternative route would be to use the AddInputAlias template from the Notation package. At the end of the process you would have to type: Esc beta Esc to get $\beta$. Obviously in this simple case it does not make much sense.

To recap: if you do not want to use Esc, use the InputAutoReplacements system, if do you want to use Esc, use the AddInputAlias system.

Why doesn't the Notation template work in this case? Well, first the LHS and the RHS of the Notation template have different meanings (external form versus internal form), so even if they are linked by a DoubleLongLeftRightArrow they are NOT equivalent in a mathematical sense. In your case you want to parse beta and get $\beta$ which displays as $\beta$, so perhaps this should work better:

Notation[ParsedBoxWrapper["beta"] \[DoubleLongRightArrow] 
  ParsedBoxWrapper["\[Beta]"]]

And indeed it works as long as you leave beta without own- or down- values. But this route is not really what you want to do I guess.

share|improve this answer
1  
This is good, but it does not work if, for example, there is an existing definition like f[x_]:=beta^x. Entering beta=3 (which properly replaces) and then f[2] does not give the desired 9, but still just beta^2. (By the way, though I'm pointing this out, I don't know how to get around this) –  billisphere Jan 18 '12 at 18:07
1  
If you type (and evaluate) the definition of f in a notebook whose InputAutoReplacements option is appropriately set, then your approach works. If the definition already exists (e.g. in some other notebook where the InputAutoReplacements option was not appropriately set when the definition was entered), then this approach does not work. Please also note that re-evaluating the cell containing the definition doesn't help, even if InputAutoReplacements is then set appropriately; it would be necessary to actually re-type [parts of] the definition with InputAutoReplacements appropriately set. –  billisphere Jan 19 '12 at 1:58
1  
Thanks for this solution magna. William makes a valid point, but there is another issue: can you get the Mathematica to reparse an input line for auto-replacements? One of the reasons why I want to have this kind of "symbol a is identical to symbol b" equivalence is for pasting equations from other programs where the symbols are just ugly variable names. And when I set up your solution with InputAutoReplacements, pasted symbols are not auto-replaced. Any keyboard shortcut to tell Mathematica to re-parse the input field? –  agravier Jan 19 '12 at 4:26
1  
@agravier Then this is a different problem/setting from what I understood. I suggest you ask a separate question describing exactly what is your setting (Matlab import) and add perhaps some concrete examples of what you want to achieve. In general (if I understand correctly), you might end up making a list of Rule statements which will replace the original variables. You also need a Matlab-MMA translator and perhaps some Hold/HoldForm command on the translated formulas. –  magma Jan 19 '12 at 14:16
1  
@agravier I suggest you simply ask another question, giving the complete context of your situation (matlab import, frequent updates, each update in same/different notebook, ect).Also add some simple examples (1,2 matlab formulas and show how you would like them to be transformed). In general, MMA can automatize "any" workflow. But you need to explain your (desired) workflow, if you ask for help –  magma Jan 19 '12 at 14:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.