Compare commits

...

5 Commits

Author SHA1 Message Date
Marc Hiatt c45e05032f Describe worddiv 2 years ago
Marc Hiatt eb74e117c7 Small code fixes 2 years ago
Marc Hiatt a632ea627e Remove superfluous check for dir 2 years ago
Marc Hiatt acd223b6ed Neaten TUI 2 years ago
Marc Hiatt caf75bc4ba No need for grep, just use sed's addressing capability 2 years ago
  1. 15
      README.md
  2. 16
      worddiv
  3. 131
      worddiv.fish

@ -1,3 +1,16 @@
## installation
## worddiv - query LaTeX’s word division (hyphenation) dictionary ##
The LaTeX typesetting software includes high quality dictionaries of word division patterns, which define the points at which a word may be broken across the end of a line.
worddiv is a simple script that makes it convenient to query the LaTeX word division dictionary interactively using a terminal emulator. This can help, for example, when proofreading galleys that do not adhere to the word hyphenations presented in an approriate high quality dictionary.
## installation ##
## usage ##

@ -17,7 +17,7 @@ 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 "\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
@ -57,21 +57,25 @@ until test "$expression" = "q" ; do
sed "s/expression/$expression/g" > $tmpdir/$secondary_filename
# american
babel_output=$(cd $tmpdir && latex -draftmode $tmpdir/$expression_filename |
grep "\\[\\] .OT1" | sed -E "s/.* ([-a-z]*)$/\1/")
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 |
grep "\\[\\] .OT1" | sed -E "s/.* ([-a-z]*)$/\1/")
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-z])/\1/p")
sed -nE --posix "/tenrm/s/.* ([-a-zA-Z])/\1/p")
## run comparisons ...
#
# test these by querying the words 'multifacted', 'important', and 'rearranged'
# test these by querying the words 'multifacted', 'important', 'rearranged', and 'Switzerland'
#
# babel AE vs plain TeX
if test "$babel_output" = "$tex_output" ; then

@ -15,7 +15,7 @@ function worddiv --description "Interact with TeX and babel (LaTeX) to show word
# -f : scope our variable to the function
set -f project_path ~/.config/fish/conf.d/worddiv
set -f tmpdir $project_path/.cache/tempdir_(date -Ins)
mkdir -p "$tmpdir" || echo "Unable to create temporary directory!"
# mkdir -p "$tmpdir" || echo "Unable to create temporary directory!" # move this to inside the while loop
set -f template_filename latex-hyphenation-template.tex
set -f expression_filename latex-hyphenation-target.tex
set -f secondary_filename latex-hyphenation-target-british.tex
@ -24,9 +24,9 @@ function worddiv --description "Interact with TeX and babel (LaTeX) to show word
# welcome message
set -f tex_version (tex -version | head -n 1)
set -f latex_version (latex -version | head -n 1)
echo "Let’s query " ; set_color yellow ; echo -n " $tex_version" ; set_color normal
printf "\nLet’s query " ; set_color yellow ; echo -n " $tex_version" ; set_color normal
echo " and " ; set_color yellow ; echo -n "$latex_version" ; set_color normal ; echo " !"
echo -e '\nEnter an expression to see its hyphenation, or ‘q’ to quit.\n'
printf '\nEnter an expression to see its hyphenation, or ‘q’ to quit.\n\n'
# set languages
set -f language american
@ -35,81 +35,82 @@ function worddiv --description "Interact with TeX and babel (LaTeX) to show word
# interact
set -f expression ""
while test $expression != "q"
read -f --prompt hyphenation_prompt expression
if test ! -e $tmpdir
mkdir -p "$tmpdir" || echo "Unable to create temporary directory!"
mkdir -p "$tmpdir" || echo "Unable to create temporary directory!"
end
if test $expression != "q"
## 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
set -f babel_output (
latex -draftmode $tmpdir/$expression_filename |
grep "\\[\\] .OT1" | sed 's_\\[\\] .OT1/cmr/m/n/10 __' )
# british
set -f babel_output_british (
latex -draftmode $tmpdir/$secondary_filename |
grep "\\[\\] .OT1" | sed 's_\\[\\] .OT1/cmr/m/n/10 __' )
## tex+showhyphens
# generate output
set -f tex_untrimmed (echo -e "\showhyphens{$expression}" |
tex --output-directory "$tmpdir" | tail -n +4 | head -n -10 |
sed 's/^\[\] \\\tenrm //' )
# $tex_untrimmed has trailing whitespace; trim it
set -f tex_output (string trim "$tex_untrimmed")
## run comparisons ...
# babel AE vs plain TeX
if test "$babel_output" = "$tex_output"
# babel AE vs babel BE
if test "$babel_output" != "$babel_output_british"
set_color yellow ; echo -en "\nbabel (AE): "
else
set_color yellow ; echo -en "\nbabel (AE & BE): "
end
# ... and output results
set_color normal ; echo -e "$babel_output\n"
else
set_color yellow ; echo -en "\nbabel (AE): " ; set_color normal ; echo $babel_output
set_color yellow ; echo -en "\nplain TeX (AE): " ; set_color normal ; echo -e "$tex_output\n"
end
# one more comparison
## latex+babel
# generate input and output
# grab a copy of the template
cp $project_path/$template_filename $tmpdir/
# modify the template, inserting our two variables
# for now, $language just = american
sed "s/language/$language/g" $tmpdir/$template_filename |
sed "s/expression/$expression/g" |
# also uncomment its \input ushyphex line so that
# the exceptions list for AE will be included
# output to a new file
sed "s/% \\\input/\\\input/g" > $tmpdir/$expression_filename
# let's check and see if british english divides this expression differently
# modify the template with a different language
# for now, $secondary_language just = british
# output to a new file
sed "s/language/$secondary_language/g" $tmpdir/$template_filename |
sed "s/expression/$expression/g" > $tmpdir/$secondary_filename
## operate on the files and filter the output
# american
set -f babel_output (
latex -draftmode $tmpdir/$expression_filename |
grep "\\[\\] .OT1" | sed 's_\\[\\] .OT1/cmr/m/n/10 __' )
# british
set -f babel_output_british (
latex -draftmode $tmpdir/$secondary_filename |
grep "\\[\\] .OT1" | sed 's_\\[\\] .OT1/cmr/m/n/10 __' )
## tex+showhyphens
# generate output
set -f tex_untrimmed (echo -e "\showhyphens{$expression}" |
tex --output-directory "$tmpdir" | tail -n +4 | head -n -10 |
sed 's/^\[\] \\\tenrm //' )
# $tex_untrimmed has trailing whitespace; trim it
set -f tex_output (string trim "$tex_untrimmed")
## run comparisons ...
# babel AE vs plain TeX
if test "$babel_output" = "$tex_output"
# babel AE vs babel BE
if test "$babel_output" != "$babel_output_british"
set_color yellow ; echo -en "babel (BE): "
set_color normal ; echo -e "$babel_output_british\n"
set_color yellow ; echo -en "\nbabel (AE): "
else
set_color yellow ; echo -en "\nbabel (AE & BE): "
end
# ... and output results
set_color normal ; echo -e "$babel_output\n"
else
set_color yellow ; echo -en "\nbabel (AE): " ; set_color normal ; echo $babel_output
set_color yellow ; echo -en "\nplain TeX (AE): " ; set_color normal ; echo -e "$tex_output\n"
end
# one more comparison
# babel AE vs babel BE
if test "$babel_output" != "$babel_output_british"
set_color yellow ; echo -en "babel (BE): "
set_color normal ; echo -e "$babel_output_british\n"
end
end
end
echo -e "\nQuitting...\n"
# clean up
if -e $tmpdir
if test -e $tmpdir
rm -r $tmpdir
end
end

Loading…
Cancel
Save