Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It's convenient to abbreviate often-used function names, eg Dim = Dimension.

Is it possible to abbreviate long context symbols, e.g. Combinatorica when the context is not inserted in the context path, like with

Block[{$ContextPath}, Needs["Combinatorica`"]]

Com = Combinatorica doesn't work, eg: Com`Star[6] is fixed by the interpreter. Is there a way to abbreviate it?

share|improve this question
One of the actual strengths of the Mathematica language design is that it uses spelled-out, meaningful names rather than verbose but possibly cryptic names. – murray Jul 15 '12 at 0:00
@murray, I aint got time for that – alancalvitti Jul 15 '12 at 6:13
My long experience with such things, going back to APL, is that it takes more time to recall the correct terse, cryptic abbreviation than to type a longer but descriptive name. Of course this is predicated upon good touch-typing skills. – murray Jul 15 '12 at 13:43
In exploratory data analysis there's much testing of properties of data structures that is then deleted, so not only do I abbreviate, eg, Dimension, but I use lower case 'dim' because speed is of the essence. What do you think of that? – alancalvitti Jul 15 '12 at 14:12
@alancalvitti Are you aware of the Cmd-K shortcut (on a mac) to autocomplete? So Dim Cmd-K will give you Dimension – R. M. Jul 15 '12 at 14:27
up vote 13 down vote accepted

I am not sure these are the best ways but they should work. You could do what you did with Dimensions for all the symbols in Combinatorica`

For example, running this

replaceAndLoad[context_String -> toContext_String] := 
     toContext <> StringReplace[#, context ~~ sym__ :> sym] <> 
      "=" <> #] &, Names[context <> "*"]]

Now, do

replaceAndLoad["Combinatorica`" -> "Com`"]

You could also overload MakeExpression to change Com to Combinatorica at the parsing stage... But I would probably do something different and basic, like an InputAlias or InputAutoReplacement. With these you could even replace them with a framed box in a special color that means "context combinatorica", or a tooltip, or simply an Interpretation that writes Com`stuff but is interpreted as Combinatorica`...

share|improve this answer

This question is not too distantly related to my own on StackOverflow:

Exposing Symbols to $ContextPath

Leonid provides an interesting approach there that could be adapted to your problem.

Rojo provides a solution that creates "proxy symbols" but these are not 100% equivalent. Information no longer works correctly for example:

?? Com`KSubsets

Mathematica graphics

This only gives the name of the Symbol it points to an not the usage message or the definition.

I prefer using $PreRead for situations like this (e.g. here). Although it only works interactively it has the advantage of using the actual symbols rather than proxies, so all the functions like Unprotect, Information, etc. work correctly.

Block[{$ContextPath}, Needs["Combinatorica`"]]

$PreRead = # /. 
    name_String?(StringMatchQ[#, "Com`*"] &) :> 
     With[{nn = StringReplace[name, "Com`" -> "Combinatorica`"]}, 
      nn /; NameQ[nn]] &;

Now Information et al work correctly:

?? Com`KSubsets
share|improve this answer
Very nice Mr.Wizard - maybe I should have waited to accept. I had no time to test these issues – alancalvitti Jul 15 '12 at 6:15
@alancalvitti as you may know you can always change the Accept later, but it is probably a good idea to wait a bit longer before placing it. Also I'm not claiming that this method is superior and I was specifically looking for an alternative to it when I posted the SO question referenced. Nevertheless I find it to have the best characteristics when it is applicable. – Mr.Wizard Jul 15 '12 at 6:18
Just when I thought I finally got a grip on Mma you made me aware that it was just an illusion. :-( – ndroock1 Jul 15 '12 at 7:01
@ndroock1 I have the same feeling sometimes. I'm curious though, what specifically makes you say that? – Mr.Wizard Jul 15 '12 at 7:04
@alancalvitti, Remember that there's only one $PreRead across the kernel, so if you want to add another context abbreviation or use it in any other way at the same time, you have to be careful – Rojolalalalalalalalalalalalala Jul 15 '12 at 14:13

Your Answer


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.