[texhax] Disable hyphenation after - everywhere
Aleksandar Zec
zealeksanman at gmail.com
Sun Sep 3 15:30:30 CEST 2017
On 2 September 2017 at 22:01, Aleksandar Zec <zealeksanman at gmail.com> wrote:
> Just out of curiosity, can you think of any disadvantage of this luatex method?
To be more precise. \babelhyphen{nohyphen} does the job, but
hyphenation points at ordinary "-"s are still there. So, as far as I
conclude from my humble experiments, only a combination of a lua
filter (to disable all hyphenations at -) and a special command (to
enable hyphenation of compound words everywhere except at -) does the
whole job.
Please consider this core. Two questions:
1. will lua filter do any harm?
2. can you think of any improvements or this concept?
\documentclass{article}
\usepackage{luatexbase,luacode}
\usepackage[english]{babel}
\usepackage{hyphenat}
\usepackage{multicol}
\begin{luacode}
no_hyphenation_points = function (head)
for n in node.traverse(head) do
if (n.id == node.id('glyph') and n.char == 0x2d and n.next.id ==
node.id('disc')) then
node.remove(head,n.next)
end
end
return head
end
\end{luacode}
\begin{document}
\parindent=0pt
\begin{multicols}{2}
\textbf{Without lua filter}\par\bigskip
simple - (wrong, hyphenates at -):\par
\fbox{\parbox{1.2cm}{%
begin antidisestablish-mentarianism end
}}\qquad\qquad\null\par\bigskip
\verb|\hyp{}| (wrong, hyphenates at -):\par
\fbox{\parbox{1.2cm}{%
begin antidisestablish\hyp{}mentarianism end
}}\qquad\qquad\null\par\bigskip
\verb|\babelhyphen{nobreak}| (correct):\par
\fbox{\parbox{1.2cm}{%
begin antidisestablish\babelhyphen{nobreak}mentarianism end
}}\qquad\qquad\null\par\bigskip
\directlua{luatexbase.add_to_callback("pre_linebreak_filter",no_hyphenation_points,"no
hyph points")}
\textbf{With lua filter}\par\bigskip
simple - (correct):\par
\fbox{\parbox{1.2cm}{%
begin antidisestablish-mentarianism end
}}\qquad\qquad\null\par\bigskip
\verb|\hyp{}| (correct):\par
\fbox{\parbox{1.2cm}{%
begin antidisestablish\hyp{}mentarianism end
}}\qquad\qquad\null\par\bigskip
\verb|\babelhyphen{nobreak}| (correct):\par
\fbox{\parbox{1.2cm}{%
begin antidisestablish\babelhyphen{nobreak}mentarianism end
}}\qquad\qquad\null\par\bigskip
\end{multicols}
\vfill
\end{document}
More information about the texhax
mailing list