Google-docs – Google Docs reference to specific number of numbered list

google docs

I am creating a long list with many (>50) references to previous list numbers in Google Docs. Here is a simplified example:

  1. Do A
  2. Go to B
  3. Wash C
  4. Pick up D
  5. Clean E
  6. Repeat Step 2
  7. Buy F

If I delete "1. Do A" the list renumbers, but "Repeat Step 2" does not change to "Repeat Step 1". Is there a way to create a reference or variable in Google Docs to automatically change "6. Repeat Step 2" to "5. Repeat Step 1" when the first step is deleted?

Best Answer

Using the new Reversible Formulas add-on for Google Docs, you can enter any JavaScript in your Google docs. And since it is evaluated in order, you can use counters.

Write the following:

counter = (0)
labels = ({})
step = (function(name) {  counter++; labels[name || ""] = counter; return counter; })
ref = (function(name) { return labels[name]; })

=step(). Do A
=step("b"). Go to B
=step(). Wash C
=step(). Pick up D
=step(). Clean E
=step(). Repeat Step =ref("b")
=step(). Buy F

Click on "Display values". You'll obtain this:

rendered content 1

Delete the first "1. Do A". Click on "Display values" again. You'll obtain this:

rendered content 2

You can hide the initial definitions by clicking on "Extract defs" - this will place the definitions in the right box.

URL of the add-on: https://chrome.google.com/webstore/detail/formulas-for-google-docs/kgjbgmonlnhglokmfnpnklegakfknbeh

Disclaimer: I'm the author of the add-on