# Endnotes with enotez: hyphenation and line breaking problems

Clemens's enotez package has made typesetting endnotes a lot more fun than it used to be with the traditional means, and has encouraged me to do the publication I'm typesetting with (the more aesthetically pleasing) end- rather than (the simpler but clumsier looking) footnotes.

However.

There's now trouble that wasn't there before. It seems that, whenever an endnote mark is attached to a word, that word becomes un-hyphenatable to TeX. Contrast the following three scenarios, in the image, one scenario per paragraph:

1. no mark

2. regular footnote mark using standard TeX routines

3. mark produced via enotez

It's obvious that TeX has problems hyphenating the word, as evidenced by the log file:

Overfull \hbox (11.5128pt too wide) in paragraph at lines 8--10
[]\OT1/cmr/m/n/12 Hat ei-ner und ge-macht zu wer-den um von Buch wol-len an um
Dampfschifffahrt$[]$


@Clemens: has this been brought to your attention? @Everyone else: what would be ways of working around that problem until there's an official fix?

Here's an MWE:

\documentclass[12pt, DIV=9]{scrreprt}
\usepackage[ngerman]{babel}
\usepackage{enotez,blindtext}

\begin{document}
Hat einer und gemacht zu werden um von Buch wollen an um  Dampfschifffahrt
\blindtext

Hat einer und gemacht zu werden um von Buch wollen an um  Dampfschifffahrt\footnote{Footnote}
\blindtext

Hat einer und gemacht zu werden um von Buch wollen an um  Dampfschifffahrt\endnote{Test}
\blindtext

\printendnotes
\end{document}

• Of course, you can manually override with Dampfschiff\-fahrt\endnote{Test} via specified hyphenation. – Steven B. Segletes Apr 13 '16 at 12:54
• Yes, of course -- that certainly is an option for those who don't need a solution that's sustainable; for those who don't mind worrying about their line breaks whenever they make a minor change to the text or its format; for those who have the nerve or wo/manpower to check the output after every change; and for those who don't mind intermingling content and form more than absolutely necessary :) – Nils L Apr 13 '16 at 13:28
• If you want to bring this to my attention the best way is to contact me through the contact information in the manual. Otherwise you must hope that I'll see the question here (and I've missed more than one in the past). – clemens Apr 13 '16 at 13:30
• well, I had taken into account the frequency of your showing up here in the community, and your favourite tags -- but I'll keep that in mind for next time... – Nils L Apr 13 '16 at 13:35
• I'll fix it: bitbucket.org/cgnieder/enotez/issues/7 – clemens Apr 13 '16 at 13:47

There is no “word boundary”; adding \nolinebreak before the endnote mark seems sufficient for the most common cases.

\documentclass[12pt, DIV=9]{scrreprt}
\usepackage[ngerman]{babel}
\usepackage{enotez}
\usepackage{blindtext}

\ExplSyntaxOn
\cs_set_protected:Npn \endnote
{
\peek_meaning_ignore_spaces:NTF [
{ \enotez_endnote_aux:w }
{ \enotez_endnote:nn { \q_no_value } }
}
\ExplSyntaxOff

\begin{document}

Hat einer und gemacht zu werden um von Buch wollen an um  Dampfschifffahrt
\blindtext

Hat einer und gemacht zu werden um von Buch wollen an um  Dampfschifffahrt\footnote{Footnote}
\blindtext

Hat einer und gemacht zu werden um von Buch wollen an um  Dampfschifffahrt\endnote{Test}
\blindtext

\printendnotes
\end{document}


A better fix should be along the lines of how \@footnotemark is defined in standard LaTeX:

% latex.ltx, line 6238:
\def\@footnotemark{%
\leavevmode
\ifhmode\edef\@x@sf{\the\spacefactor}\nobreak\fi
\@makefnmark
\ifhmode\spacefactor\@x@sf\fi
\relax}


So something like the following is probably better.

\cs_set_protected:Npn \enotez_endnote_mark:n #1
{
\leavevmode
\mode_if_horizontal:T { \tl_set:Nx \l__enotez_sf_tl { \the\spacefactor } \nobreak }
\int_gincr:N \g__enotez_endnote_id_int
\quark_if_no_value:nTF {#1}
{
\int_gincr:N \g__enotez_endnote_mark_int
\cs_gset:cpx { @currentlabel }
{ \enotez_counter_format:V \g__enotez_endnote_mark_int }
\cs_gset_eq:NN \theendnote \@currentlabel
\enotez_write_mark:nn
{ \int_use:N \g__enotez_endnote_id_int }
{ \enotez_counter_format:V \g__enotez_endnote_mark_int }
}
{
\cs_gset:cpx { @currentlabel } {#1}
\cs_gset_eq:NN \theendnote \@currentlabel
\enotez_write_mark:nn { \int_use:N \g__enotez_endnote_id_int } {#1}
}
}

\cs_set_protected:Npn \enotez_write_mark:nn #1#2
{
\bool_if:NTF \l__enotez_hyperfootnotes_bool
{
\enotezwritemark { \hyperlink { enz.#1 } { \enmarkstyle #2 } }
\bool_if:NT \l__enotez_hyperbackref_bool
{
\box_move_up:nn { 1em }
{ \hbox:n { \hypertarget { enz.#1.backref } { } } }
}
}
{ \enotezwritemark { \enmarkstyle #2 } }
\mode_if_horizontal:T { \spacefactor \l__enotez_sf_tl \scan_stop: }
}