Is there a shortcut to inserting a CounterBox as you type in text mode? I haven't yet made extensive use of them but I can foresee them in my near future and the current method of inserting them is a little bit of a pain. Here is the current method:

Start by opening a new notebook. Create a text cell with the following content:

The current counter of title is: XXX.

Select the XXX and go to Insert > Automatic Numbering.... This will give you some options. For Counter leave it as it is (Title). And select "This counter object".

After clicking OK now the XXX will be replaced by 0 since the current count for title cells is 0. If you now create a Title cell above the one you just created then that 0 will become a 1.

I don't mind using the little GUI asking me what counter to insert. What I do not like is having to go to Insert > Automatic Numbering... all the time. I would actually prefer if possible to do some sort of input autoreplacement but this clearly would not work since we need to define what gets replaced. I thought about maybe using input alias but this again requires me to define the inputs. What I want to be able to do is something like this...

The current counter of title is [AliasDelimiter]ref[Title][AliasDelimiter]

and get

The current counter of title is 0

I'm trying to emulate $\LaTeX$ here using ref. I don't know if I have explored this question enough but so far I'm running out of ideas to make the process of entering counterboxes as painless as possible. The last idea I had was to create a palette with an input box in which you entered the tag or counter but then I realized that even if this is possible (I highly doubt it is) it would then just be the same as the Insert > Automatic Numbering... gui. So the question again:

Is there a some sort of shortcut to inserting a CounterBox?

  • $\begingroup$ I'm having trouble understanding this one. If you add e.g. "cb" -> CounterBox["Text"] to InputAliases you can add a Text counter-box with ESC cb ESC -- I don't understand what ref does. $\endgroup$
    – Mr.Wizard
    Jun 8, 2012 at 8:21
  • $\begingroup$ @Mr.Wizard, correct, if you add "cb" then we always get that counterBox, the "ref" notation that is something that doesn't make sense in mathematica. I was wondering if there is some sort of input alias in which ref would be replaced by CounterBox but the input for this alias would be something else. Yeah, sorry for the nonsense here. I was just trying to throw some ideas. $\endgroup$
    – jmlopez
    Jun 8, 2012 at 8:25
  • $\begingroup$ I'm still not sure I follow; what exactly would you enter, and what would be the result? I am not familiar with LaTeX -- how would ref be used? $\endgroup$
    – Mr.Wizard
    Jun 8, 2012 at 8:28
  • 1
    $\begingroup$ @Mr.Wizard, in latex you use labels (Mathematica equivalent of cellTag). To refer to that label in the text you would simply write \ ref{NameofTag} . In mathematica, I was wondering if we could achieve something similar. Unfortunately, I just realized that the Insert > Automatic Numbering... is actually a function that modifies the whole cell so that it can insert the CounterBox, so creating an alias to just insert this is well.. I don't know anymore. If it helps a little here is some latex reference. $\endgroup$
    – jmlopez
    Jun 8, 2012 at 8:36
  • 1
    $\begingroup$ I must have: it has my vote on it. $\endgroup$
    – Mr.Wizard
    Jun 8, 2012 at 8:46

1 Answer 1


This is slightly related to the question How to create a notebook element that can replace itself?

As you state, input aliases don't have inputs, so you have no way of giving it the label you want to reference, so instead, you could use document manipulation to read the current selection and replace it with a counterbox using that label. A very simplistic implimentation would be:

 autoCounter[] := With[{label = NotebookRead[EvaluationNotebook[]]}, 
    NotebookWrite[EvaluationNotebook[], CounterBox[label]]]]

Naturally to use this you need to add a shortcut to the function, but just to give an example of it's usage, here's a button that when pressed executes it, allowing you to select a bit of text and execute the function without losing your selection.

  Button["Insert counter", autoCounter[]]

So for example you would write "See Figure Figure" select the last text bit "Figure" and press the button.

This question might help with how to impliment a keyboard shortcut for the function: Automating Esc [[ Esc formatting? Otherwise searching the site will yield a lot of coverage.

  • $\begingroup$ jVincent, I think I'm sold!, All I have to do now is put this into a palette and I can have a nice editor. As I type equations say: "Using eq1 we ..." given that "eq1" is a CellTag now I I just select it press the button and bingo. Thanks again. $\endgroup$
    – jmlopez
    Jun 8, 2012 at 15:10

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.