Commit a55bec61 authored by User expired's avatar User expired
Browse files

Merge bib-jabbr replacements into bib-conv[ul]

parent 2f2a344d
......@@ -4,9 +4,10 @@
function usage() {
echo "$(basename $0): Convert special characters from unicode to latex"
echo ""
echo "USAGE: echo text | $(basename $0) [-i file] [-f str]"
echo "USAGE: echo text | $(basename $0) [-i file] [-f str] [options]"
echo "Options (position sensitive):"
echo " -h print this help"
echo " -s short replacement list for journal names"
echo " -i file edit file in place (do not read stdin)"
echo " -f str filter pattern for sed"
exit $1
......@@ -15,11 +16,13 @@ function usage() {
# Default options.
FILE="" # No filename, read from stdin.
FILTER="" # No filter, edit all contents.
SHORTLIST="0" # Use all replacement lists.
# Parse command line options.
for arg; do
# With option '-h' print usage and exit.
if [[ "$arg" == "-h" ]]; then usage 0; fi
if [[ "$arg" == "-s" ]]; then SHORTLIST=1; fi
done
if [[ "$1" == "-i" ]]
......@@ -37,93 +40,117 @@ then
fi
# Replace '{\"a}' and '\"a' to '\"{a}'.
FORMAT="
s/{\\\\\(['\"^v]\)\([^ {]\)}/\\\\\1{\2}/g
s/\\\\\(['\"^v]\)\([^ {]\)/\\\\\1{\2}/g
"
# Minimum single quote list of replacements.
MIN_REPLSQ='
s/ä/\\"{a}/g
s/ö/\\"{o}/g
s/ü/\\"{u}/g
s/Ä/\\"{A}/g
s/Ö/\\"{O}/g
s/Ü/\\"{U}/g
s/â/\\^{a}/g
s/ê/\\^{e}/g
s/î/\\^{i}/g
s/ô/\\^{o}/g
s/û/\\^{u}/g
s/ŝ/\\^{s}/g
s/Â/\\^{A}/g
s/Ê/\\^{E}/g
s/Î/\\^{I}/g
s/Ô/\\^{O}/g
s/Û/\\^{U}/g
s/ç/\\c{c}/g
'
# Additional single quote list of replacements.
ADD_REPLSQ='
s/ı̈/\\"{i}/g
s/n̈/\\"{n}/g
s/ő/\\H{o}/g
s/ű/\\H{u}/g
s/Ő/\\H{O}/g
s/Ű/\\H{U}/g
s/ą/\\k{a}/g
s/ę/\\k{e}/g
s/Ą/\\k{A}/g
s/Ę/\\k{E}/g
s/å/\\r{a}/g
s/Å/\\r{A}/g
s/č/\\v{c}/g
s/ř/\\v{r}/g
s/š/\\v{s}/g
s/ž/\\v{z}/g
s/Č/\\v{C}/g
s/Ř/\\v{R}/g
s/Š/\\v{S}/g
s/Ž/\\v{Z}/g
s/ã/\\~{a}/g
s/ñ/\\~{n}/g
s/Ã/\\~{A}/g
s/Ñ/\\~{N}/g
s/æ/{\\ae}/g
s/œ/{\\oe}/g
s/ß/{\\ss}/g
s/ł/{\\l}/g
s/Ł/{\\L}/g
s/ø/{\\o}/g
s/Ø/{\\O}/g
'
# Minimum double quote list of replacements.
MIN_REPLDQ="
s/à/\\\\"'`'"{a}/g
s/è/\\\\"'`'"{e}/g
s/á/\\\\'{a}/g
s/é/\\\\'{e}/g
s/í/\\\\'{i}/g
s/ó/\\\\'{o}/g
s/ú/\\\\'{u}/g
s/Á/\\\\'{A}/g
s/É/\\\\'{E}/g
s/Í/\\\\'{I}/g
s/Ó/\\\\'{O}/g
s/Ú/\\\\'{U}/g
"
# Additional double quote list of replacements.
ADD_REPLDQ="
s/ć/\\\\'{c}/g
s/ń/\\\\'{n}/g
s/ý/\\\\'{y}/g
"
# For option '-s' use short list of replacements.
if [ $SHORTLIST -eq 1 ]
then
# Add ampersand escaping (for journal names).
ADD_REPLSQ='/&/s/\([^\\]\)&/\1\\\&/g'
ADD_REPLDQ=""
fi
# Function to replace unicode characters by latex code.
function utf_to_latex() { # echo text | utf_to_latex
sed "$@" \
-e "${FILTER}"'{
s/ä/\\"{a}/g
s/ö/\\"{o}/g
s/ü/\\"{u}/g
s/ı̈/\\"{i}/g
s/n̈/\\"{n}/g
s/Ä/\\"{A}/g
s/Ö/\\"{O}/g
s/Ü/\\"{U}/g
s/ő/\\H{o}/g
s/ű/\\H{u}/g
s/Ő/\\H{O}/g
s/Ű/\\H{U}/g
s/â/\\^{a}/g
s/ê/\\^{e}/g
s/î/\\^{i}/g
s/ô/\\^{o}/g
s/û/\\^{u}/g
s/ŝ/\\^{s}/g
s/Â/\\^{A}/g
s/Ê/\\^{E}/g
s/Î/\\^{I}/g
s/Ô/\\^{O}/g
s/Û/\\^{U}/g
s/à/\\`{a}/g
s/è/\\`{e}/g
s/ç/\\c{c}/g
s/ą/\\k{a}/g
s/ę/\\k{e}/g
s/Ą/\\k{A}/g
s/Ę/\\k{E}/g
s/å/\\r{a}/g
s/Å/\\r{A}/g
s/č/\\v{c}/g
s/ř/\\v{r}/g
s/š/\\v{s}/g
s/ž/\\v{z}/g
s/Č/\\v{C}/g
s/Ř/\\v{R}/g
s/Š/\\v{S}/g
s/Ž/\\v{Z}/g
s/ã/\\~{a}/g
s/ñ/\\~{n}/g
s/Ã/\\~{A}/g
s/Ñ/\\~{N}/g
s/æ/{\\ae}/g
s/œ/{\\oe}/g
s/ß/{\\ss}/g
s/ł/{\\l}/g
s/Ł/{\\L}/g
s/ø/{\\o}/g
s/Ø/{\\O}/g
' \
-e "
s/á/\\\\'{a}/g
s/é/\\\\'{e}/g
s/í/\\\\'{i}/g
s/ó/\\\\'{o}/g
s/ú/\\\\'{u}/g
s/ć/\\\\'{c}/g
s/ń/\\\\'{n}/g
s/ý/\\\\'{y}/g
s/Á/\\\\'{A}/g
s/É/\\\\'{E}/g
s/Í/\\\\'{I}/g
s/Ó/\\\\'{O}/g
s/Ú/\\\\'{U}/g
}"
sed "$@" "$FILTER{
$FORMAT
$MIN_REPLSQ
$MIN_REPLDQ
$ADD_REPLSQ
$ADD_REPLDQ
}"
}
# Function to replace '{\"a}' and '\"a' to '\"{a}'
function default_syntax() { # echo text | default_syntax
sed -r "$@" \
-e "${FILTER}{
s/\\{\\\\(['\"^v])([^ {])\\}/\\\\\1{\2}/g
s/\\\\(['\"^v])([^ {])/\\\\\1{\2}/g
}"
}
if [ -z "$FILE" ]
then
cat /dev/stdin | default_syntax | utf_to_latex
cat /dev/stdin | utf_to_latex
else
default_syntax -i "$FILE"
utf_to_latex -i "$FILE"
fi
......@@ -4,9 +4,10 @@
function usage() {
echo "$(basename $0): Convert special characters from latex to unicode"
echo ""
echo "USAGE: echo text | $(basename $0) [-i file] [-f str]"
echo "USAGE: echo text | $(basename $0) [-i file] [-f str] [options]"
echo "Options (position sensitive):"
echo " -h print this help"
echo " -s short replacement list for journal names"
echo " -i file edit file in place (do not read stdin)"
echo " -f str filter pattern for sed"
exit $1
......@@ -15,11 +16,13 @@ function usage() {
# Default options.
FILE="" # No filename, read from stdin.
FILTER="" # No filter, edit all contents.
SHORTLIST="0" # Use all replacement lists.
# Parse command line options.
for arg; do
# With option '-h' print usage and exit.
if [[ "$arg" == "-h" ]]; then usage 0; fi
if [[ "$arg" == "-s" ]]; then SHORTLIST=1; fi
done
if [[ "$1" == "-i" ]]
......@@ -37,93 +40,117 @@ then
fi
# Replace '{\"a}' and '\"a' to '\"{a}'.
FORMAT="
s/{\\\\\(['\"^v]\)\([^ {]\)}/\\\\\1{\2}/g
s/\\\\\(['\"^v]\)\([^ {]\)/\\\\\1{\2}/g
"
# Minimum single quote list of replacements.
MIN_REPLSQ='
s/\\"{a}/ä/g
s/\\"{o}/ö/g
s/\\"{u}/ü/g
s/\\"{A}/Ä/g
s/\\"{O}/Ö/g
s/\\"{U}/Ü/g
s/\\^{a}/â/g
s/\\^{e}/ê/g
s/\\^{i}/î/g
s/\\^{o}/ô/g
s/\\^{u}/û/g
s/\\^{s}/ŝ/g
s/\\^{A}/Â/g
s/\\^{E}/Ê/g
s/\\^{I}/Î/g
s/\\^{O}/Ô/g
s/\\^{U}/Û/g
s/\\c{c}/ç/g
'
# Additional single quote list of replacements.
ADD_REPLSQ='
s/\\"{i}/ı̈/g
s/\\"{n}/n̈/g
s/\\H{o}/ő/g
s/\\H{u}/ű/g
s/\\H{O}/Ő/g
s/\\H{U}/Ű/g
s/\\k{a}/ą/g
s/\\k{e}/ę/g
s/\\k{A}/Ą/g
s/\\k{E}/Ę/g
s/\\r{a}/å/g
s/\\r{A}/Å/g
s/\\v{c}/č/g
s/\\v{r}/ř/g
s/\\v{s}/š/g
s/\\v{z}/ž/g
s/\\v{C}/Č/g
s/\\v{R}/Ř/g
s/\\v{S}/Š/g
s/\\v{Z}/Ž/g
s/\\~{a}/ã/g
s/\\~{n}/ñ/g
s/\\~{A}/Ã/g
s/\\~{N}/Ñ/g
s/{\\ae}/æ/g
s/{\\oe}/œ/g
s/{\\ss}/ß/g
s/{\\l}/ł/g
s/{\\L}/Ł/g
s/{\\o}/ø/g
s/{\\O}/Ø/g
'
# Minimum double quote list of replacements.
MIN_REPLDQ="
s/\\\\"'`'"{a}/à/g
s/\\\\"'`'"{e}/è/g
s/\\\\'{a}/á/g
s/\\\\'{e}/é/g
s/\\\\'{i}/í/g
s/\\\\'{o}/ó/g
s/\\\\'{u}/ú/g
s/\\\\'{c}/ć/g
s/\\\\'{n}/ń/g
s/\\\\'{y}/ý/g
s/\\\\'{A}/Á/g
s/\\\\'{E}/É/g
"
# Additional double quote list of replacements.
ADD_REPLDQ="
s/\\\\'{I}/Í/g
s/\\\\'{O}/Ó/g
s/\\\\'{U}/Ú/g
"
# For option '-s' use short list of replacements.
if [ $SHORTLIST -eq 1 ]
then
# Remove ampersand escaping (for journal names).
ADD_REPLSQ='s/\\&/\&/g'
ADD_REPLDQ=""
fi
# Function to replace latex code by unicode characters.
function latex_to_utf() { # echo text | latex_to_utf
sed "$@" \
-e "${FILTER}"'{
s/\\"{a}/ä/g
s/\\"{o}/ö/g
s/\\"{u}/ü/g
s/\\"{i}/ı̈/g
s/\\"{n}/n̈/g
s/\\"{A}/Ä/g
s/\\"{O}/Ö/g
s/\\"{U}/Ü/g
s/\\H{o}/ő/g
s/\\H{u}/ű/g
s/\\H{O}/Ő/g
s/\\H{U}/Ű/g
s/\\^{a}/â/g
s/\\^{e}/ê/g
s/\\^{i}/î/g
s/\\^{o}/ô/g
s/\\^{u}/û/g
s/\\^{s}/ŝ/g
s/\\^{A}/Â/g
s/\\^{E}/Ê/g
s/\\^{I}/Î/g
s/\\^{O}/Ô/g
s/\\^{U}/Û/g
s/\\`{a}/à/g
s/\\`{e}/è/g
s/\\c{c}/ç/g
s/\\k{a}/ą/g
s/\\k{e}/ę/g
s/\\k{A}/Ą/g
s/\\k{E}/Ę/g
s/\\r{a}/å/g
s/\\r{A}/Å/g
s/\\v{c}/č/g
s/\\v{r}/ř/g
s/\\v{s}/š/g
s/\\v{z}/ž/g
s/\\v{C}/Č/g
s/\\v{R}/Ř/g
s/\\v{S}/Š/g
s/\\v{Z}/Ž/g
s/\\~{a}/ã/g
s/\\~{n}/ñ/g
s/\\~{A}/Ã/g
s/\\~{N}/Ñ/g
s/{\\ae}/æ/g
s/{\\oe}/œ/g
s/{\\ss}/ß/g
s/{\\l}/ł/g
s/{\\L}/Ł/g
s/{\\o}/ø/g
s/{\\O}/Ø/g
' \
-e "
s/\\\\'{a}/á/g
s/\\\\'{e}/é/g
s/\\\\'{i}/í/g
s/\\\\'{o}/ó/g
s/\\\\'{u}/ú/g
s/\\\\'{c}/ć/g
s/\\\\'{n}/ń/g
s/\\\\'{y}/ý/g
s/\\\\'{A}/Á/g
s/\\\\'{E}/É/g
s/\\\\'{I}/Í/g
s/\\\\'{O}/Ó/g
s/\\\\'{U}/Ú/g
}"
sed "$@" "$FILTER{
$FORMAT
$MIN_REPLSQ
$MIN_REPLDQ
$ADD_REPLSQ
$ADD_REPLDQ
}"
}
# Function to replace '{\"a}' and '\"a' to '\"{a}'
function default_syntax() { # echo text | default_syntax
sed -r "$@" \
-e "${FILTER}{
s/\\{\\\\(['\"^v])([^ {])\\}/\\\\\1{\2}/g
s/\\\\(['\"^v])([^ {])/\\\\\1{\2}/g
}"
}
if [ -z "$FILE" ]
then
cat /dev/stdin | default_syntax | latex_to_utf
cat /dev/stdin | latex_to_utf
else
default_syntax -i "$FILE"
latex_to_utf -i "$FILE"
fi
......@@ -46,90 +46,11 @@ for arg; do
done
 
 
# Function to replace latex by utf8 characters
function latex_to_utf() { # echo text | latex_to_utf
sed \
-e '/^ Journal/{
s/\\"{a}/ä/g
s/\\"{o}/ö/g
s/\\"{u}/ü/g
s/\\"{A}/Ä/g
s/\\"{O}/Ö/g
s/\\"{U}/Ü/g
s/\\^{a}/â/g
s/\\^{e}/ê/g
s/\\^{i}/î/g
s/\\^{o}/ô/g
s/\\^{u}/û/g
s/\\^{A}/Â/g
s/\\^{E}/Ê/g
s/\\^{I}/Î/g
s/\\^{O}/Ô/g
s/\\^{U}/Û/g
s/\\`{a}/à/g
s/\\`{e}/è/g
s/\\c{c}/ç/g
s/\\&/\&/g
' \
-e "
s/\\\\'{a}/á/g
s/\\\\'{e}/é/g
s/\\\\'{i}/í/g
s/\\\\'{o}/ó/g
s/\\\\'{u}/ú/g
s/\\\\'{A}/Á/g
s/\\\\'{E}/É/g
s/\\\\'{I}/Í/g
s/\\\\'{O}/Ó/g
s/\\\\'{U}/Ú/g
}"
}
# Function to replace utf8 characters by latex code.
function utf_to_latex() { # echo text | utf_to_latex
sed \
-e '/^ Journal/{
s/ä/\\"{a}/g
s/ö/\\"{o}/g
s/ü/\\"{u}/g
s/Ä/\\"{A}/g
s/Ö/\\"{O}/g
s/Ü/\\"{U}/g
s/â/\\^{a}/g
s/ê/\\^{e}/g
s/î/\\^{i}/g
s/ô/\\^{o}/g
s/û/\\^{u}/g
s/Â/\\^{A}/g
s/Ê/\\^{E}/g
s/Î/\\^{I}/g
s/Ô/\\^{O}/g
s/Û/\\^{U}/g
s/à/\\`{a}/g
s/è/\\`{e}/g
s/ç/\\c{c}/g
/&/s/\([^\\]\)&/\1\\\&/g
' \
-e "
s/á/\\\\'{a}/g
s/é/\\\\'{e}/g
s/í/\\\\'{i}/g
s/ó/\\\\'{o}/g
s/ú/\\\\'{u}/g
s/Á/\\\\'{A}/g
s/É/\\\\'{E}/g
s/Í/\\\\'{I}/g
s/Ó/\\\\'{O}/g
s/Ú/\\\\'{U}/g
}"
}
# Function to print journal names in bibtex files.
function printuniq() { # formatted sorted unique names
if [ $PRINTNAMES -eq 1 ]
then
cat /dev/stdin | bib-convu | sed 's/\\&/\&/g' | sort -u
cat /dev/stdin | bib-convu -s | sort -u
else
cat /dev/stdin
fi
......@@ -138,7 +59,7 @@ function printuniq() { # formatted sorted unique names
 
# Function to replace journal names by abbreviations.
function abbreviate() { # abbreviate filename
cat "$1" | latex_to_utf \
cat "$1" | bib-convu -f '/^ Journal/' -s \
| sed \
-e "/^ Journal/{
/^ Journal *= { *A/{
......@@ -4777,13 +4698,13 @@ function abbreviate() { # abbreviate filename
s/{ *Österreichische botanische Zeitschrift *}/{Österr. bot. Z.}/
}
}" \
| utf_to_latex
| bib-convl -f '/^ Journal/' -s
}
 
 
# Function to replace journal abbreviations by full name.
function unabbreviate() { # unabbreviate filename
cat "$1" | latex_to_utf \
cat "$1" | bib-convu -f '/^ Journal/' -s \
| sed \
-e "/^ Journal/{
/^ Journal *= { *A/{
......@@ -9350,7 +9271,7 @@ function unabbreviate() { # unabbreviate filename
s/{ *Österr. bot. Z. *}/{Österreichische botanische Zeitschrift}/
}
}" \
| utf_to_latex
| bib-convl -f '/^ Journal/' -s
}
 
 
......@@ -9381,9 +9302,7 @@ fi
if [ $JOURNALLIST -eq 1 ]
then
grep '^ *s/{ \*' "$0" | grep -o '[^ *{}/][^*{}/]*[^ *{}/]' \
| sed 's/.*/ Journal{&}/' \
| latex_to_utf \
| sed 's/ Journal{\(.*\)}/\1/' \
| bib-convu -s \
| sort -u
exit
fi
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment