Commit 8c42abb7 authored by User expired's avatar User expired
Browse files

Add two scripts to convert between latex and unicode

This will simplify the definition of replacements for all scripts.
parent 06f71f88
#!/bin/bash
# Convert special characters from unicode to latex
function usage() {
echo "$(basename $0): Convert special characters from unicode to latex"
echo ""
echo "USAGE: echo text | $(basename $0) [-f str]"
echo "Options:"
echo " -h print this help"
echo " -f str filter pattern for sed"
exit $1
}
# Default options.
FILTER="" # No filter, edit all contents.
# Parse command line options.
for arg; do
# With option '-h' print usage and exit.
if [[ "$arg" == "-h" ]]; then usage 0; fi
done
if [[ "$1" == "-f" ]]
then
[[ "$#" -ge 2 ]] && FILTER="$2" \
|| echo "Missing argument to option '-f'!" >/dev/stderr
shift 2 || shift 1
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
}"
}
# 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
}"
}
cat /dev/stdin | default_syntax | utf_to_latex
#!/bin/bash
# Convert special characters from latex to unicode
function usage() {
echo "$(basename $0): Convert special characters from latex to unicode"
echo ""
echo "USAGE: echo text | $(basename $0) [-f str]"
echo "Options:"
echo " -h print this help"
echo " -f str filter pattern for sed"
exit $1
}
# Default options.
FILTER="" # No filter, edit all contents.
# Parse command line options.
for arg; do
# With option '-h' print usage and exit.
if [[ "$arg" == "-h" ]]; then usage 0; fi
done
if [[ "$1" == "-f" ]]
then
[[ "$#" -ge 2 ]] && FILTER="$2" \
|| echo "Missing argument to option '-f'!" >/dev/stderr
shift 2 || shift 1
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
}"
}
# 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
}"
}
cat /dev/stdin | default_syntax | latex_to_utf
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