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.

x\[Prime] looks like $x_'$, ugly right? Is there a way to make a symbol with prime to look like $x'$?


That's what I'm trying right now:

Notation[ x_', Primed[x_]]
Primed[x_] := Symbol[SymbolName[x] <> "\[Prime]"]

But how then I use it in patterns? If I do this:

f[q_, q':_] := q + q'

Weird syntax errors appear:

Syntax::sntxf: "T[r_," cannot be followed by "q':_]".
Syntax::tsntxi: "q':_" is incomplete; more input is needed.
Syntax::sntxi: Incomplete expression; more input is needed .

If we replace q':_ with Pattern[q',_] another error:

Pattern::patvar: "First element in pattern Pattern[q',_] is not a valid pattern name. "

But Head[q'] returns Symbol and Pattern requires a Symbol as first parameter.

What is wrong?

share|improve this question
    
Why not type x'? –  rm -rf Oct 3 '12 at 17:33
    
@rm-rf Because it will be a derivative then and not a symbol. –  swish Oct 3 '12 at 17:44
    
Ah, you want to be able to do things like $x^\prime=3$, then? –  J. M. Oct 3 '12 at 17:48
    
@J.M. Yes, but without Needs["Notation`"];Symbolize[x']. –  swish Oct 3 '12 at 17:52
1  
Very closely related: How to Clear variables with apostrophe? There, I suggest using a different unicode glyph that looks better. –  Jens yesterday

3 Answers 3

This is not really ideal, but it gets you most of the way there:

SetAttributes[makeSuperscript, HoldAllComplete];
makeSuperscript[sym_Symbol] := (
   sym /: MakeBoxes[sym, form_] = With[{name = SymbolName[sym]},
     InterpretationBox[SuperscriptBox[name, "\[Prime]"], sym]
    ];
   sym
  );

makeSuperscript[q]
(* -> InterpretationBox[SuperscriptBox["q", "\[Prime]"], q] *)

The symbol is still called q, but it now looks like $q'$, as the InterpretationBox is not visible. You can either copy and paste the superscripted form (to make assignments, or use in other expressions) or enter it as q, as you prefer.

share|improve this answer
    
But I want to have this notation inside input, mostly in patterns, so that functions like f[x'_] := x' would work. Basically I want \[Prime] to be higher. –  swish Oct 3 '12 at 19:29
    
@swish after evaluating makeSuperscript[x], f[x_] := x displays in the way that you want. If you copy and paste the output of Information[f], it works as input, even in a new session. I know this is not quite how you envisioned this working, but unfortunately I'm not aware of any reasonably safe way of accomplishing that. Even if you use a different font that has a higher-up \[Prime], you'll still need a StyleBox for it to display as such unless you edit the font mapping file UnicodeFontMapping.tr. –  Oleksandr R. Oct 3 '12 at 19:48
    
That causes q to display as q^\[Prime]. But you could instead use InterpretationBox[SuperscriptBox[name, "\[Prime]"], Symbol[name <> "\[Prime]"]]. –  Mechanical snail Dec 6 '12 at 23:19
    
@Mechanicalsnail yes, that's right, but the point was to have a symbol that appeared to be primed without having to have ' or \[Prime] in its actual name due to likely confusion (of both the user and Mathematica itself) with Derivative[1]. If you really want \[Prime] in the name then yes, your suggestion is sensible. One could also use any other Unicode character that displays in approximately the right way. –  Oleksandr R. Dec 7 '12 at 7:57
    
@OleksandrR.: The Derivative confusion only occurs with an apostrophe, not \[Prime]. The asker wanted to be able to use unprimed and primed in the same expression. –  Mechanical snail Dec 8 '12 at 0:54

This is an unashamed variation on @Oleksandr R's post but prompted by the OP comment "Basically I want \[Prime] to be higher."

Using adjustment boxes you can position the prime exactly where you want. Easiest way to do set the position is probably to type x\[Prime] and go to the menu Insert > Typesetting and nudge the prime around.

enter image description here

SetAttributes[higherPrime, HoldAllComplete];

higherPrime[
   sym_Symbol] := (sym /: MakeBoxes[sym, form_] = 
    With[{name = SymbolName[sym]}, 
     RowBox[{name, 
       AdjustmentBox["\[Prime]", BoxBaselineShift -> -0.9, 
        BoxMargins -> {{-0.15, 0}, {0, -0}}]}]];
   sym);

enter image description here

share|improve this answer
    
The main problem is that FullForm[higherPrime[x]] is stil x, so it's impossible to use both primed and unprimed versions of one symbol. Nudge Up is a great suggestion, what we need now is the way to automate it. –  swish Oct 3 '12 at 21:54

In Mathematica 10 using

<< Notation`
Notation[x' => xPrime]

seems to work to "disconnect" x' from its meaning as a derivative. (Note- the Notation text used here represents entering using the Notation Palette. Mathematica interprets this to

Notation[ParsedBoxWrapper[
   RowBox[{"x", "'"}]] \[DoubleLongRightArrow] ParsedBoxWrapper["xPrime"]
]

but no reason to do that by hand )

share|improve this answer
    
Trying the first two lines, I get a Notation::noexbtag error. (V10.0.1) –  Michael E2 yesterday
1  
NB: This only worked for me when I reproduced the second line with the Notation Palette. –  evanb yesterday

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.