Use Google Apps Script to Auto Number Headings in a Google Document.
This script¹ lets you easily add or remove numbers to your Google Document Headings and also get them in plain text.
Current functionalities are:
- Menu and Addon UIs.
- Add Headings Numbers
- Remove Heading Numbers
- Promote Headings (H1➙Title ... H6➙H5)
- Demote Headings (Title➙Title, H1➙H2 ... H6➙Normal)
- Output processed Headings as text only
- Add/Remove and Promote/Demote only some heading levels (1-6)
After you install the script, the easiest way to Add/Remove is though the Lord of The Rings shortcut Alt+/
that opens the Help menu with the cursor focused on the find shortcut field. From there you just need to type head
to get the basic features:
Or you can use mouse:
Or you can use the Addon sidebar, which also lets you access the 'interactive' version and outputs the plain text headings:
Feel free to add issues or send pull requests! 😉
Note: You'll only need the files autonumber.gs
and sidebar.html
. The code.gs
is here only for historic reasons.
- Open your document
- Extensions > Apps Script
- Give the project a name and save (this name is how it will appear on the Addons submenu)
- Paste the code from the
autonumber.gs
file over whatever code your file has - Click the ➕ sign and create a HTML file named
sidebar
- Paste the code from the
sidebar.html
file over the default file content - Change back to the
autonumber.gs
file - Click on the Run button on the menu bar to execute the onOpen function and authorize the script for the first time
- Change to your Document and reload it.
If all went well you'll see a Heading Tools menu and also the entry in the Extensions menu.
¹ Modified version of this script.