From f11bda499f45b0a4831006e8d979b6c7801c2bea Mon Sep 17 00:00:00 2001 From: Marc Hiatt Date: Sun, 8 Oct 2023 00:43:30 +0200 Subject: [PATCH] Make $tmpdir a generic conf.d/worddiv/.cache --- README.md | 3 ++ latex-hyphenation-template.tex | 30 ++++++++++++++++ worddiv.fish | 62 ++++++++++++++++++++++------------ 3 files changed, 73 insertions(+), 22 deletions(-) create mode 100644 README.md create mode 100644 latex-hyphenation-template.tex diff --git a/README.md b/README.md new file mode 100644 index 0000000..e5d0bed --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ + +## installation + diff --git a/latex-hyphenation-template.tex b/latex-hyphenation-template.tex new file mode 100644 index 0000000..281d6e1 --- /dev/null +++ b/latex-hyphenation-template.tex @@ -0,0 +1,30 @@ +% TeX template for use with worddiv.fish +% for a different approach, see https://tex.stackexchange.com/a/693030, also quoted at the bottom of this file + +% we can set the language as a global option by passing it as an option to \documentclass +\documentclass[language]{article} + +% according to the babel user guide (babel.pdf), if we've set the language globally (above), setting it here again is actually redundant, but if it ain't broke... +\usepackage[language]{babel} + +% include exceptions for US English from /usr/share/texlive/texmf-dist/tex/generic/hyphenex/ushyphex.tex +% my fish script uncomments this line just in those cases where it has also set the language to `american` +% \input ushyphex + + +\begin{document} + +\showhyphens{expression} + +\end{document} + + +% here's a lualatex alternative, suggested by koppor ( https://tex.stackexchange.com/a/693030 ) + +% % !TeX program = lualatex +% \documentclass{article} +% \usepackage{showhyphens} +% \begin{document} +% \input{ushyphex} +% antinuclear +% \end{document} \ No newline at end of file diff --git a/worddiv.fish b/worddiv.fish index ea7795c..87476cb 100644 --- a/worddiv.fish +++ b/worddiv.fish @@ -13,9 +13,9 @@ function worddiv --description "Interact with TeX and babel (LaTeX) to show word # 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 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!" 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 @@ -36,30 +36,42 @@ function worddiv --description "Interact with TeX and babel (LaTeX) to show word 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!" + end + if test $expression != "q" - # latex+babel: generate input and output - cp $template_path/$template_filename ./$tmpdir/ + ## latex+babel + # generate input and output + cp $project_path/$template_filename $tmpdir/ - sed "s/language/$language/g" ./$tmpdir/$template_filename | + # for now, $language just = american + 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 + # 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 is different - sed "s/language/$secondary_language/g" ./$tmpdir/$template_filename | - sed "s/expression/$expression/g" > ./$tmpdir/$secondary_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 | + 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 | + latex -draftmode $tmpdir/$secondary_filename | grep "\\[\\] .OT1" | sed 's_\\[\\] .OT1/cmr/m/n/10 __' ) - # tex+showhyphens: generate output + + ## 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 //' ) @@ -67,31 +79,37 @@ function worddiv --description "Interact with TeX and babel (LaTeX) to show word # $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 "|" - + ## 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): " + 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 +end echo -e "\nQuitting...\n" # clean up - rm -r $tmpdir - + if -e $tmpdir + rm -r $tmpdir + end end