Southeast Asian Anarchist Librarian
Some tools I use for library stuff
Tools for footnote mapping and footnote formatting
Automate footnote bracketing in endnotes
Automate conversion of parenthesesed footnotes into bracketed footnotes
I use these tools on Linux Mint. Keep in mind your operating system and programs available when using these scripts.
Please let me know on the Anarchist Library chat if there are ways to improve the following scripts.
Automate footnote mapping
Synopsis: Automated footnote mapping automatically looks for some numbers in the text and then applies brackets to them. So Lorem ipsum.34
where Lorem ipsum.
is the sentence and 34
is the footnote reference in body becomes lorem impsum.[34]
.
You should move the footnotes/endnotes in a separate text file and apply this script only to the body of the text.
Applying the script to:
Lorem ipsum dolor sit amet,1 consectetur adipiscing elit, sed do eiusmod tempor incididunt ut 56 labore et dolore magna aliqua.2 Ut enim ad minim veniam,3 quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.4 Duis aute irure dolor in December 4 reprehenderit in 1956 voluptate velit esse cillum dolore eu fugiat nulla pariatur.5 Excepteur sint occaecat cupidatat non proident,6 sunt in culpa qui officia deserunt mollit anim id est laborum.7
Becomes:
Lorem ipsum dolor sit amet,[1] consectetur adipiscing elit, sed do eiusmod tempor incididunt ut [56] labore et dolore magna aliqua.[2] Ut enim ad minim veniam,[3] quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.[4] Duis aute irure dolor in December [4] reprehenderit in 1[956] voluptate velit esse cillum dolore eu fugiat nulla pariatur.[5] Excepteur sint occaecat cupidatat non proident,[6] sunt in culpa qui officia deserunt mollit anim id est laborum.[7]
Caveat: There are a number of false positives in using this script, as seen in the above example. (1) Years will be cut up and my be recognized as footnote references in the body. These will need to be undone. (2) Numbers in the body will also be bracketed and will also need to be undone. However, in my experience, manually undoing these false positives is a lot easier and quicker than manually applying brackets to each and every footnote reference in the body.
Filename: fix_footnote_mapping.sh
#!/bin/bash # Function to add brackets to one- to three-digit numbers fix_footnotes() { # Process one- to three-digit numbers in the body sed -E 's/([[:space:]])([1-9][0-9]{0,2})([[:space:]])/\1[\2]\3/g' "$1" > temp_file # Process one- to three-digit numbers at the end of the text sed -E 's/([1-9][0-9]{0,2})([[:space:]]|$)/[\1]\2/g' temp_file > "$1" # Clean up temporary file rm temp_file } # Check if a file is provided as an argument if [ -z "$1" ]; then echo "Usage: $0 <filename>" exit 1 fi # Check if the file exists if [ ! -f "$1" ]; then echo "Error: File not found!" exit 1 fi # Run the function to fix footnotes fix_footnotes "$1" echo "Footnotes fixed successfully in $1"
How to use:
./fix_footnote_mapping.sh input.txt
Automate footnote bracketing in endnotes
Synopsis: This script adds brackets to numbers at the beginning of lines. Make sure your endnotes are properly formatted with a newline, a number, a period, and a space before each footnote in the line. See the following:
1. Lorem ipsum footnote 1. 2. Lorem ipsum footnote 2. 3. Lorem ipsum footnote 3.
The above will be converted into
[1] Lorem ipsum footnote 1. [2] Lorem ipsum footnote 2. [3] Lorem ipsum footnote 3.
At this point the footnotes should be ready for AMuseWiki to parse.
Make sure this script is only applied to the footnotes/endnotes and not to the body of the text.
Caveats: (1) Sometimes footnotes are broken across multiple lines, either intentional as new footnote paragraphs or unintentional as conversion errors. These ought be manually fixed when you spot them. (2) Sometimes footnotes are incorrectly rendered i.e. as 25.Lorem ipsum footnote 25.
You need to find these and fix them “Rearrange the footnotes” module should let you know what footnotes are broken.
Filename: fix_start_of_sentences.sh
#!/bin/bash # Function to add brackets to numbers at the beginning of sentences fix_start_of_sentences() { # Process numbers at the beginning of sentences sed -E 's/^([1-9][0-9]*)\.([[:space:]])/\[\1\]\2/g' "$1" > temp_file # Clean up temporary file mv temp_file "$1" } # Check if a file is provided as an argument if [ -z "$1" ]; then echo "Usage: $0 <filename>" exit 1 fi # Check if the file exists if [ ! -f "$1" ]; then echo "Error: File not found!" exit 1 fi # Run the function to fix numbers at the beginning of sentences fix_start_of_sentences "$1" echo "Numbers at the beginning of sentences fixed successfully in $1"
How to use:
./fix_start_of_sentences.sh input.txt
Automate conversion of parenthesesed footnotes into bracketed footnotes
Synopsis: Converts footnotes in parentheses into brackets. Example follows:
(1) Lorem ipsum footnote 1. (2) Lorem ipsum footnote 2. (3) Lorem ipsum footnote 3.
The above will be converted into
[1] Lorem ipsum footnote 1. [2] Lorem ipsum footnote 2. [3] Lorem ipsum footnote 3.
At this point the footnotes should be ready for AMuseWiki to parse.
Make sure this script is only applied to the footnotes/endnotes and not to the body of the text.
Caveats: (1) Sometimes footnotes are broken across multiple lines, either intentional as new footnote paragraphs or unintentional as conversion errors. These ought be manually fixed when you spot them. (2) Sometimes footnotes are incorrectly rendered i.e. as (25)Lorem ipsum footnote 25.
You need to find these and fix them “Rearrange the footnotes” module should let you know what footnotes are broken.
Filename: parenthesis-to-brackets.sh
#!/bin/bash # Function to add brackets to numbers in parentheses fix_footnotes() { sed -E 's/\(([1-9][0-9]{0,2})\)/[\1]/g' "$1" -i } # Check if a file is provided as an argument if [ -z "$1" ]; then echo "Usage: $0 <filename>" exit 1 fi # Check if the file exists if [ ! -f "$1" ]; then echo "Error: File not found!" exit 1 fi # Run the function to fix footnotes fix_footnotes "$1" echo "Footnotes fixed successfully in $1"
How to use:
./parenthesis-to-brackets.sh input.txt