Get POSIX-compatible script working

Add license
master
Marc Hiatt 2 years ago
parent 440f296bf7
commit 7c9a600046
  1. 1476
      LICENSES/GPL-3.0-or-later.txt
  2. 99
      worddiv

File diff suppressed because it is too large Load Diff

@ -0,0 +1,99 @@
#!/bin/sh
# worddiv - query LaTeX’s word division (hyphenation) patterns
#
# SPDX-FileCopyRightText: Marc Hiatt (hiatt@campus.tu-berlin.de)
# SPDX-License-Identifier: GPL-3.0-or-later
# TODO: add languages other than English
project_path=$HOME/.config/fish/conf.d/worddiv
tmpdir=$project_path/.cache/tempdir_$(date -Ins)
template_filename=latex-hyphenation-template.tex
expression_filename=latex-target.tex
secondary_filename=latex-target-scd.tex
# welcome message
tex_version=`tex -version | head -n 1`
latex_version=`latex -version | head -n 1`
printf "Let’s query \n %s and\n %s !\n" "$tex_version" "$latex_version"
printf "\nEnter an expression to see its hyphenation, or ‘q’ to quit.\n\n"
# set languages
language=american
label=AE
secondary_language=british
secondary_label=BE
# interact
expression=""
until test "$expression" = "q" ; do
read -p "divide > " expression
if test ! -d "$tmpdir" ; then
# set up temporary directory for our own .tex files and LaTeX's logfiles
mkdir -p "$tmpdir" || echo "Unable to create temporary directory!"
fi
if test ! "$expression" = "q" ; then
## latex+babel
# generate input and output
cp $project_path/$template_filename $tmpdir
# for now, $language just = american
sed "s/language/$language/g" $tmpdir/$template_filename |
sed "s/expression/$expression/g" |
# modify template: uncomment its \input ushyphex line so that
# the exceptions list for AE will be included
sed "s/% \\\input/\\\input/g" > $tmpdir/$expression_filename
# let's check and see if british english divides this expression differently
# for now, $secondary_language just = british
sed "s/language/$secondary_language/g" $tmpdir/$template_filename |
sed "s/expression/$expression/g" > $tmpdir/$secondary_filename
# american
babel_output=$(latex -draftmode $tmpdir/$expression_filename |
grep "\\[\\] .OT1" | sed -E "s/.* ([-a-z]*)$/\1/")
# british
babel_output_secondary=$(latex -draftmode $tmpdir/$secondary_filename |
grep "\\[\\] .OT1" | sed -E "s/.* ([-a-z]*)$/\1/")
## tex+showhyphens
tex_output=$(echo "\showhyphens{$expression}" |
tex -output-directory "$tmpdir" |
sed -nE --posix "/tenrm/s/.* ([-a-z])/\1/p")
## run comparisons ...
# babel AE vs plain TeX
if test "$babel_output" = "$tex_output" ; then
# babel AE vs babel BE
if test ! "$babel_output" = "$babel_output_secondary" ; then
printf "\nbabel (%s): %s\n" "$label" "$babel_output"
else
printf "\nbabel (%s & %s): %s\n" "$label" "$secondary_label" "$babel_output"
fi
else
printf "\nbabel (%s): %s\n" "$label" "$babel_output"
printf "\nplain TeX (%s): %s\n" "$label" "$tex_output"
fi
# one more comparison
# babel AE vs babel BE
if test ! "$babel_output" = "$babel_output_secondary" ; then
printf "babel (%s): %s\n\n" "$secondary_label" "$babel_output_secondary"
fi
fi
done
# clean up
if test -d "$tmpdir" ; then
rm -r "$tmpdir"
fi
Loading…
Cancel
Save