Created
November 7, 2014 01:23
-
-
Save heitara/e9201833a41097a7ba68 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A handy Google App script which updates the bibliography numbering in a scientific document