Customizing endnotes: hanging indent + justified text + no space between notes

endnotesragged2espacing

This is what I want to achieve for endnotes in a book typeset using LuaLaTeX 2020.

  1. Endnote marker at the left margin
  2. Hanging indent (endnote text should indented throughout, not just first line of each note)
  3. No line space between successive notes
  4. Endnote text fully justified

I started with the answer here

\documentclass{book}
\usepackage{endnotes}
\usepackage{lipsum}
\renewcommand\enoteformat{%
  \raggedright
  \leftskip=1.8em
  \makebox[0pt][r]{\theenmark. \rule{0pt}{\dimexpr\ht\strutbox+\baselineskip}}%
}
\begin{document}
\endnote{\lipsum[1]}\endnote{\lipsum[2]}
\theendnotes
\end{document}

and changed the code to remove the space between two notes by deleting +\baselineskip. This worked and the extra space was gone. So then I tried to justify the endnote text using justify (I am using ragged2e anyway in my book). This is my code now

\documentclass{book}
\usepackage{endnotes}
\usepackage{lipsum}
\usepackage{ragged2e}
\renewcommand\enoteformat{%
  \justify
  \leftskip=1.8em
  \makebox[0pt][r]{\theenmark. \rule{0pt}{\dimexpr\ht\strutbox}}%
}
\begin{document}
\endnote{\lipsum[1]}\endnote{\lipsum[2]}
\theendnotes
\end{document}

But this reintroduced the space between the endnotes. I tried playing around but cannot figure out how to eliminate the space.

Best Answer

Finally got it working. The trick is to remove \raggedright, not add \justify but instead add \noindent before \makebox. This is my code now.

\documentclass{book}
\usepackage{endnotes}
\usepackage{lipsum}
\usepackage{ragged2e}
\renewcommand\enoteformat{%
  \justify
  \leftskip=1.8em
  \makebox[0pt][r]{\theenmark. \rule{0pt}{\dimexpr\ht\strutbox}}%
}
\begin{document}
\endnote{\lipsum[1]}\endnote{\lipsum[2]}
\theendnotes
\end{document}