Phantom section and bookmarks

bookmarkshyperref

    \newcounter{entry}[chapter]
    \newcommand{\declarenewentry}[1]{\medskip\noindent\framebox[\textwidth][l]{\qquad Day \theentry : #1}\medskip}

    \newcommand{\newentry}[1]{\addtocounter{entry}{1}\addtocounter{chapter}{1}\phantomsection \addcontentsline{toc}{chapter}{\protect\numberline{\theentry \qquad #1}}\declarenewentry{#1}}

MWE:

\documentclass{book}

\usepackage{bookmark, hyperref}

\newcounter{entry}[chapter]
\newcommand{\declarenewentry}[1]{\medskip\noindent\framebox[\textwidth][l]{\qquad Day \theentry : #1}\medskip}

\newcommand{\newentry}[1]{\addtocounter{entry}{1}\addtocounter{chapter}{1}\phantomsection \addcontentsline{toc}{chapter}{\protect\numberline{\theentry \qquad #1}}\declarenewentry{#1}}

\begin{document}
    \frontmatter
    \mainmatter
        \newentry{August 10, 2021}

            Sample Text
            \section{Sample}

            \newpage
        \newentry{August 11, 2021}

    \backmatter
\end{document}

Now, the problem is that these commands generate a bookmark, but they have no displayed names. I think this is because of \phantomsection. I could probably achieve a better effect by using the sectsty package, but is there a way to name the bookmark?


Edit: Output

enter image description here

As observed, there exists a bookmark with no name. Same goes below the section, as there is a second entry, though it is unnoticeable.

Best Answer

My impression is that instead of \newentry you want to use \chapter.

\documentclass{book}

\usepackage{titlesec}
\usepackage{hyperref,bookmark}

\titleformat{\chapter}[block]
 {\normalfont}
 {}
 {0pt}
 {\declarenewentry}
\titlespacing{\chapter}
 {0pt}
 {\medskipamount}
 {\medskipamount}

\newcommand{\declarenewentry}[1]{%
  \framebox[\textwidth][l]{\qquad Day \thechapter: #1}%
}


\begin{document}

\mainmatter

\chapter{August 10, 2021}

Sample Text

\section{Sample}

\chapter{August 11, 2021}

\end{document}

enter image description here

Related Question