You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.5 KiB
107 lines
3.5 KiB
#!/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 "\nLet’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=$(cd $tmpdir && latex -draftmode $tmpdir/$expression_filename |
|
|
# print nothing (sed -n) except the line that matches
|
|
# the regexp "/] .OT1/", but only after replacing the
|
|
# whole of that line with part of itself, namely last
|
|
# glob of letters and hyphens that comes after a space:
|
|
sed -nE "/] .OT1/s/.* ([-a-zA-Z]*)$/\1/p")
|
|
|
|
# british
|
|
babel_output_secondary=$(cd $tmpdir && latex -draftmode $tmpdir/$secondary_filename |
|
|
sed -nE "/] .OT1/s/.* ([-a-zA-Z]*)$/\1/p")
|
|
|
|
## tex+showhyphens
|
|
tex_output=$(echo "\showhyphens{$expression}" |
|
|
tex -output-directory "$tmpdir" |
|
|
sed -nE --posix "/tenrm/s/.* ([-a-zA-Z])/\1/p")
|
|
|
|
## run comparisons ...
|
|
#
|
|
# test these by querying the words 'multifacted', 'important', 'rearranged', and 'Switzerland'
|
|
#
|
|
# 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\n" "$label" "$babel_output"
|
|
else
|
|
printf "\nbabel (%s & %s): %s\n\n" "$label" "$secondary_label" "$babel_output"
|
|
fi
|
|
else
|
|
printf "\nbabel (%s): %s\n" "$label" "$babel_output"
|
|
printf "\nplain TeX (%s): %s\n\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
|
|
echo ""
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
# clean up
|
|
if test -d "$tmpdir" ; then
|
|
rm -r "$tmpdir"
|
|
fi
|
|
|