Skip to main content

Input cell numbering in Mathematica notebook

After some googling about cell numbering, I ended up being able to number inline formula, text, output, but not input cells.

Of course, there is already the In[_] numbering or the possibility of numbering the corresponding output cell (if it exists), so that input cell numbering may not be necessary after all.

However, when input is reevaluated, the In[_] numbering changes and the output cell numbering is lost so input cell numbering is really important.

According to CounterTutorial.nb by P. J. Hinton, 1998:
A CounterBox[ ] can appear only in a TextData[ ] expression of a cell, so that means you can use them only [in] cell styles associated with headings and body text.  They cannot be used in the contents of typeset math cells.
Therefore, input cell numbering may not be so easy.  However:
You can inspect the low level trickery that is used by opening up the notebook's style sheet and unformatting the prototype cell for NumberedEquation.  I won't go into too much more detail except to say that frame labels for a cell are set with the option CellFrameLabels, which is somewhat similar to the FrameLabel option for graphics objects.
Here is the idea of CellFrameLabels:

CellPrint[
 Cell[BoxData["1+1"], "Input",
  CellFrameLabels -> {{None,
     Cell[TextData[CounterBox["InputNumbered"]], "Input",
      Brown]}, {None, None}}]]


Actually, the InputNumbered cell style happens to be already in the shared style sheet PublicationDefault.nb (a Mathematica system file).  Choose this style sheet.  Although InputNumbered is not in the Format > Style menu, it can be found with Format > Style > Other and the search box.  As expected, InputNumbered cells are numbered.

However, when trying to reference a tagged input cell (with Insert > Automatic Numbering), the reference number is zero.  The counter is not incremented.  Thus the "low level trickery" must be inspected.

Format > Edit style sheet.
The private style definition notebook (or style sheet) opens.
Click the link to PublicationDefault.nb.
Find the style definition for EquationNumbered.
Copy it into the private style sheet.
Edit the metadata with Input instead of Equation, save, then referencing works.

Moreover, in order to share the same style sheet with other notebooks, it can be installed, which means exported.  Enter the new style sheet name, InputNumberedPublication.nb, click install.  It is indeed copied in $BaseDirectory or $UserBaseDirectory.


Comments

Popular posts from this blog

How to change word completion language in iOS 12 applications using the keyboard, like Mail, Skype, Whatsapp, Viber... ?  On the keyboard, press the globe, this shifts the language. If the language you need is not available, go to Settings > General > Language & Region and choose the language you need.  This will install it.  You can revert to English later.

Cleaning iTunes calendar sync list

iTunes can be used to sync calendars on Mac and iPhone. However, iTunes calendar sync list gets cluttered with deleted calendars. See for example https://discussions.apple.com/thread/6840043 In order to clean iTunes calendar sync list, check the unwanted calendars, sync, delete them on iPhone.  Go back to iTunes, uncheck the unwanted calendars, sync again, and the unwanted calendars should disappear before your eyes. This worked for me with iTunes 12.8.12, Mac OS 10.11.6, iOS 12.1.2.