Small code fixes

master
Marc Hiatt 2 years ago
parent a632ea627e
commit eb74e117c7
  1. 125
      worddiv.fish

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

Loading…
Cancel
Save