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)
- Outputs processed Headings as plain text
- Option to Add/Remove and Promote/Demote only some heading levels (1-6)
- Option to restart numbering when a Title paragraph occurs
- Option to restrict to selected paragraphs
Check the How to install if you like it!
💡 The easiest way to use it is through 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 your mouse:
Or you can use the "Open sidebar" function to access the interactive version, which lets you change options and also outputs the plain text headings:
Feel free to add issues or send pull requests! 😉
If you do send pull requests please make sure to use the autoNumberHeadings oficial Test Document to create updated images.
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.