3
$\begingroup$

I know how to number equations using the DisplayFormulaNumbered style. This creates equation numbers on the right-hand margin using an automatic counter. For example,

enter image description here

How do you add a custom equation number like so?

enter image description here

I know this can be done, but I lost my notes on how to do this. To be precise, I would like to set a custom equation number that can also be used when setting references in text cells, as I show below

enter image description here

Obviously, I could create a custom equation number using any of the hacks I have memorialized below, but if I were to change the custom equation number from EQ Unit Circle to EQ Circle, the change would not be automatically reflected in the following like where I reference (EQ Unit Circle). One could manage this by doing a global find and replace, but the solution is poor given the power of Mathematica.

To be clear, the question is how can we create custom equation numbers that can also be used as references, much in the same way that automatic equation numbers can be used.

UPDATE May 9, 2024@10:38pm PST: I managed to get a very ugly solution to work. I made a copy of Default.nb file in ..\SystemFiles\FrontEnd\StyleSheets\Default.nb (on Mac OS) and called it Default pabfr.nb. I then created a new notebook and set its stylesheet to Default pabfr. I used the Format -> Edit Stylesheet... menu to create a new style called DisplayFormulaCustomNumber that inherits from DisplayFormulaNumbered. I created a cell with the new style, selected the cell, and used the Option Inspector... under the Format menu to show me the CellFrameLabels under Cell Frame Options under Cell Options. I edited the value under CellFrameLabels as shown in the following image.

enter image description here

Notice my custom label both under CellFrameLabels and as a custom cell number. This could not be uglier, but it works.

The one drawback with the method I have used is that equation number references don't update to reflect the change in the equation number from an auto-generated integer to a customer equation number.

Does anybody have a better solution?

UPDATE May 11, 2024@7:20am PST: The best suggestion so far below is from Goofy@. The recommendation is to use the CounterBoxOptions->{CounterFunction:>{"My_Equation_Label"&)} inside the cell. This works the same way my way did above. It does not solve the problem of automatically updating all references to the equation using tags. Instead, you will get the next integer in the counter for the cell style, which makes sense. The disadvantage of this method is that you must manually search and replace your document if you change the custom label.

Here is the step-by-step process

Create a DisplayFormulaNumbered as follows

enter image description here

enter image description here

Now, edit the underlying cell representation by pressing CMD+SHIFT+E on your keyboard of using the menu Cell->Show Expression after having selected the cell.

enter image description here

Append CounterBoxOptions->{CounterFunction:>("EQ1"&)} inside brackets as follows

enter image description here

Voila, you have a custom number on the right-hand side of the cell.

enter image description here

The & after EQ1 in CounterFunction:>("EQ1"&) is required to suppressed the actual DisplayFormulaNumbered counter from being inserted right after your custom label.

Let us try to insert a reference to this equation in a text cell. The first step is to make tags visible

enter image description here

Add a tag to (EQ1) so we may refer to it. Select your equation and hit CMD+J or use the menu Cell->Cell Tags->Add/Remove Cell Tags.... Add the tag EQ1.

enter image description here

Let's create a text cell below the formula cell and add a reference.

enter image description here

Make sure to select the correct counter (i.e., DisplayFormulaNumbered)

enter image description here

You will then see

enter image description here

You now have a reference with the counter's value for DisplayFormulaNumbered cells. This means that if I added another equation of the same type above ours, the reference would update automatically

enter image description here

There reference in the text cell is now 2 instead of 1. Ideally, I would like to see EQ1 as my reference, and I would like to see my reference updated automatically if I ever change the custome equation number EQ1 to something else. Of course, Mathematica is inserting a counter instead of my customer label EQ1 because this whole thing is built on counters of specific cell styles.

I guess one option would be to introduce a new equation style for every custom equation label, but this would be ridiculous. A more sensible, yet manual step, would be to use the approach above to enter the actual custom equation label in the equation's cell and then manually search and replace reference to this cell if I ever change the custom equation number EQ1.

One final comment is that you may want to create a new formula cell style. Otherwise, automatically numbered cells of type DisplayFormulaNumbered will "magically" skip one number in the sequence. References in text cells would still work as expected, so this is okay.

A great reference on counter boxes and counters in Mathematica is here.

$\endgroup$
8
  • 1
    $\begingroup$ Have a look at CounterAssignments in the documentation. $\endgroup$ Commented May 8 at 22:28
  • $\begingroup$ Also look at CounterFunction. $\endgroup$
    – Goofy
    Commented May 9 at 2:12
  • $\begingroup$ Looked at those two. It is not how you specify an arbitrary string to use as a label. $\endgroup$ Commented May 9 at 4:27
  • $\begingroup$ You might want to check ..\SystemFiles\FrontEnd\StyleSheets\Default.nb, see how DisplayFormulaNumbered style uses CellFrameLabels to implement the equation number. $\endgroup$
    – Silvia
    Commented May 9 at 18:01
  • $\begingroup$ I will try that. Will revert if I get nowhere. $\endgroup$ Commented May 9 at 18:43

0

Your Answer

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

Browse other questions tagged or ask your own question.