Creating a cross referencing shortcut

What I would suggest is not exactly doing what you want, but I don't see much sense in sticking to $\LaTeX$ notation whe working in a Mathematica notebook and believe the following is even more convenient. What I'd do is this:

  • Define this:

    ref[tag_] := NotebookWrite[SelectedNotebook[],
     RowBox[{"[", CounterBox["DisplayFormulaNumbered", ToString@tag],"]"}]
    ]
    
  • When I need a reference to tag eq1 within some text type: ref@eq1

  • Select ref@eq1, presumably by Ctrl-Shift-backarrow on Windows (Opt-Shift-backarrow on a Mac)

  • Evaluate in place with Ctrl-Shift-Return on Windows (Command-Return on a Mac).

That way I could enter these references when typing with my fingers on the keyboard. Here is a button which also does something useful, but not exactly what you asked for (which has some subtletys I'm trying to avoid, as you might have recognized :-):

CreatePalette[
 Button["Enter Reference",
  Module[{tag = ToString@Input["Enter Tag:"]},
   If[MemberQ[NotebookTools`NotebookCellTags[SelectedNotebook[]], tag],
    NotebookWrite[SelectedNotebook[],
     RowBox[{"[", CounterBox["DisplayFormulaNumbered", tag], "]"}]
     ],
    MessageDialog["could not find tag: " <> tag]
    ]
   ],
  Method -> "Queued"
  ]
 ]

you would press the button, enter a tag in the dialog box, hit Enter (or press the "OK" button) and the CounterBox will be inserted at the current cursor position (be aware that it will replace everything that has been selected).

One thing that would justify a solution as you suggest would be if you have a large text written in the above form and process it in one go. If that's what you'r after maybe you want to make that clear in your question to motiviate someone to write something...

Tags:

Front End