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.
97 lines
3.4 KiB
97 lines
3.4 KiB
|
|
|
|
## interactive show-hyphens, LaTeX version
|
|
|
|
function hyphenation_prompt --description "Construct promt for `latex-hyphens`"
|
|
set_color green; echo -n 'divide '; set_color normal; echo "> "
|
|
end
|
|
|
|
|
|
function worddiv --description "Interact with TeX and babel (LaTeX) to show word division (a.k.a. hyphenation)."
|
|
# TODO: add languages other than English
|
|
#
|
|
|
|
# set up temporary directory for our own .tex files and LaTeX's logfiles
|
|
# -f : scope our variable to the function
|
|
set -f tmpdir show-hyphens_(date -Ins)
|
|
mkdir "./$tmpdir" || echo "Unable to create temporary directory!"
|
|
set -f template_path /home/marc/.config/fish/hyphenation
|
|
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
|
|
|
|
|
|
# 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
|
|
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'
|
|
|
|
# set language
|
|
set -f language american
|
|
set -f secondary_language british
|
|
|
|
# interact
|
|
set -f expression ""
|
|
while test $expression != "q"
|
|
read -f --prompt hyphenation_prompt expression
|
|
if test $expression != "q"
|
|
|
|
# latex+babel: generate input and output
|
|
cp $template_path/$template_filename ./$tmpdir/
|
|
|
|
sed "s/language/$language/g" ./$tmpdir/$template_filename |
|
|
sed "s/expression/$expression/g" |
|
|
# uncomment the \input ushyphex line to include the exceptions list for AE
|
|
sed "s/% \\\input/\\\input/g" > ./$tmpdir/$expression_filename
|
|
|
|
|
|
# let's check and see if british is different
|
|
sed "s/language/$secondary_language/g" ./$tmpdir/$template_filename |
|
|
sed "s/expression/$expression/g" > ./$tmpdir/$secondary_filename
|
|
|
|
set -f babel_output (
|
|
latex -draftmode ./$tmpdir/$expression_filename |
|
|
grep "\\[\\] .OT1" | sed 's_\\[\\] .OT1/cmr/m/n/10 __' )
|
|
|
|
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")
|
|
|
|
# echo -n "latex: " ; echo -n $babel_output ; echo "|"
|
|
# echo -n " tex: " ; echo -n $tex_output ; echo "|"
|
|
|
|
if test "$babel_output" = "$tex_output"
|
|
if test "$babel_output" != "$babel_output_british"
|
|
set_color yellow ; echo -en "\nbabel (AE): "
|
|
else
|
|
set_color yellow ; echo -en "\nbabel (AE & BE): "
|
|
end
|
|
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
|
|
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
|
|
rm -r $tmpdir
|
|
|
|
end
|
|
|
|
|