Skip to content

Instantly share code, notes, and snippets.

@heitara
Created November 7, 2014 01:23
Show Gist options
  • Save heitara/e9201833a41097a7ba68 to your computer and use it in GitHub Desktop.
Save heitara/e9201833a41097a7ba68 to your computer and use it in GitHub Desktop.
/***
* A script which updates the bibliography numbering if there are some extra recorrd.
* For example if you have added extra [2.1] and [4.1], the script will
* go trhou it and will make [2.1] to [3] and [4.1] to [5], because [4] is already [5]
* The script will print the mapping as well.
**/
function updateBibliography() {
var bodyElement = DocumentApp.getActiveDocument().getBody();
//initial max number or reference, to generate the mapping
var max = 30;
var arr = [];
for(var i = 1; i <= max; i++) {
arr.push("\\["+i+"\\]");
}
//add the extra bibliography recorrds, which should be mapped
arr.splice(4, 0, "\\[4.1\\]","\\[4.2\\]");
var correct = [];
max = arr.length;
//generation of the bibliography mapping
for(i = 1; i <= max; i++) {
correct.push("\["+i+"\]");
}
var output = '';
for(i = arr.length - 1; i >= 0; i--) {
bodyElement.replaceText(arr[i], correct[i]);
output += arr[i] + '=>' + correct[i] + '\n';
}
DocumentApp.getUi().alert(output);
}
@heitara
Copy link
Author

heitara commented Nov 7, 2014

A handy Google App script which updates the bibliography numbering in a scientific document

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment