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?

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

5 Answers 5


As mentioned in my comment to the question, I think the best solution is to use a Unicode character (see also the answer by The Vee). Here is a modified version of my earlier answer:

 InputAliases -> 
   Join[{"'" -> FromCharacterCode[700]}, 
    InputAliases /. 
      Quiet[Options[EvaluationNotebook[], InputAliases]] /. 
     InputAliases -> {}]]

eʼ = 1

(* ==> 1 *)

eʼʼ = 2

(* ==> 2 *)

eʼ + eʼʼ

(* ==> 3 *)

The only modification is that I defined the shortcut so that you can now really enter the prime by typing the actual prime symbol on the keyboard, just surrounded by escape, i.e., Esc'Esc.

As you can see in the example, the input alias immediately converts this to primed variable names, which can be used like any other symbol.


This is following Jens's suggestion to use a different Unicode glyph, but different from the answer linked in the corresponding comment. We can use Unicode directly, so let's just find a letter-like modifier glyph that looks good. A quick search for "prime" gives a nice solution in MODIFIER LETTER PRIME. You can type it using the notation \:02b9 which renders as ʹ, or just copy and paste the character itself:

enter image description here

This does not require any packages or prior code.

Closely related \:02c8 and \:02ca are also options and work just as well, the choice is a matter of preference.

  • $\begingroup$ Thanks for mentioning my answer (+1) - I think I'll re-post it here with a modification that would make typing even easier... $\endgroup$
    – Jens
    Apr 1, 2016 at 1:27
  • $\begingroup$ @Jens Oh, mine is more similar than I originally thought. Only now I noticed that your constant 700 is simply 0x2bc and thus FromCharacterCode[700] = \:02bc, just a different one from the same list. I did not understand that the code is there just to simplify the keyboard input, I thought it was using some sort of invisible surrogate. $\endgroup$
    – The Vee
    Apr 1, 2016 at 1:33

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]

(* -> 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.

  • $\begingroup$ 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. $\endgroup$
    – swish
    Oct 3, 2012 at 19:29
  • $\begingroup$ @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. $\endgroup$ Oct 3, 2012 at 19:48
  • $\begingroup$ That causes q to display as q^\[Prime]. But you could instead use InterpretationBox[SuperscriptBox[name, "\[Prime]"], Symbol[name <> "\[Prime]"]]. $\endgroup$ Dec 6, 2012 at 23:19
  • $\begingroup$ @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. $\endgroup$ Dec 7, 2012 at 7:57
  • $\begingroup$ @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. $\endgroup$ Dec 8, 2012 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];

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

enter image description here

  • $\begingroup$ 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. $\endgroup$
    – swish
    Oct 3, 2012 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

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

but no reason to do that by hand )

  • $\begingroup$ Trying the first two lines, I get a Notation::noexbtag error. (V10.0.1) $\endgroup$
    – Michael E2
    Oct 20, 2014 at 13:35
  • 1
    $\begingroup$ NB: This only worked for me when I reproduced the second line with the Notation Palette. $\endgroup$
    – evanb
    Oct 20, 2014 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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