# Hyperref endnotes used to create the author queries

I am using hyperref endnotes to create a two way inter linking marginal note and author queries. I am using a lot of environments like vbox and hbox, tables, figure, equations, Box, multicol.

But paragraph environment only working the endnotes. Other environments like vbox and hbox, tables, figure, equations, Box, multicol, natbib are not working. When I compile the file, my sty generates a lot of errors. I am finding it very difficult to fix these problems.

My required coding is \endnote[vertical alignment adjustable vspace command][horizontally alignment adjustable hspace command]{query text here}. The two optional commands [][] are used only if I need to adjust the vertical and horizontal alignment. Otherwise, I just use \endnote{query text here}.

Vertical and horizontal query alignments are not affected the paragraph text.

I need my code to support three cases:

1. \endnote{author query text} - normal placement

2. \endnote[Vertical points]{author query text} - If I need to align the endnote mark vertically

3. \endnote[Vertical points][Horizontal points]{author query text} - If I need to align the endnote mark vertically and horizontally

My required first page printed theendnote author query form designed the table format below mentioned here:

Endnote mark is showing the marginal notes

Here is an MWE:

\documentclass[twocolumn]{article}

\usepackage{authblk}
\usepackage{endnotes}
\usepackage{hyperref}
\usepackage{graphics}
\usepackage{multicol}
\usepackage{graphicx}
\makeatletter
\AtBeginDocument{\theendnotes}
\makeatother

\begin{document}

\title{Sample document for endnotes}
\author[1,]{Junli Liu}
\author[2]{James Rowe}
\author[2]{Keith Lindsey}
\affil[1]{Integrative Cell Biology Laboratory, School of Biological and Biomedical Sciences, The Bio physical Sciences Institute, Durham University, Durham, UK}
\maketitle

\noindent Patterning\endnote{note1} in Arabidopsis root development
is coordinated via a localized auxin concentration maximum in the
root tip (Sabatini et al., 1999), requiring the regulated expression
of speciÞc genes. This auxin gradient has been hypothesized to be sink-driven (Friml et al., 2002) and com- putational modeling suggests that auxin efßux carrier activity may be sufÞcient to generate the gradient in the absence of auxin biosynthesis in the root

\begin{figure}[!t]
\caption{The sample caption\label{fig:1}}\endnote{figure endnote}
\end{figure}
\end{document}


and here is the hyperref endnote.sty file:

   \usepackage{color}
\@definecounter{endnote}
\def\theendnote{\@arabic\c@endnote}

\def\@makeenmark{\textcolor{red}{\fbox{Q\@theenmark}}}
\def\makeenmark{\@makeenmark}

\def\theenmark{\@theenmark}

\newdimen\endnotesep

\def\endnote{\@ifnextchar[\@xendnote{\stepcounter{endnote}%
\protected@xdef\@theenmark{\theendnote}%
\@endnotemark\@endnotetext}}

\def\@xendnote[#1]{%
\begingroup
\c@endnote=#1\relax
\unrestored@protected@xdef\@theenmark{\theendnote}%
\endgroup
\@endnotemark\@endnotetext}

%  Here begins a section of endnote code that's really different from
% the footnote code of LaTeX.

\let\@doanenote=0
\let\@endanenote=0

\newwrite\@enotes
\newif\if@enotesopen \global\@enotesopenfalse

\def\@openenotes{\immediate\openout\@enotes=\jobname.ent\relax
\global\@enotesopentrue}

%  The stuff with \next and \meaning is a trick from the TeXbook, 382,
% there intended for setting verbatim text, but here used to avoid
% macro expansion when the footnote text is written.  \next will have
% the entire text of the footnote as one long line, which might well
% overflow limits on output line length; the business with \newlinechar
% makes every space become a newline in the \@enotes file, so that all
% of the lines wind up being quite short.

\long\def\@endnotetext#1{%
\if@enotesopen \else \@openenotes \fi
\immediate\write\@enotes{\@doanenote{\@theenmark}}%
\begingroup
\def\next{#1}%
\newlinechar='40
\immediate\write\@enotes{\meaning\next}%
\endgroup
\immediate\write\@enotes{\@endanenote}}

% \addtoendnotes works the way the other endnote macros probably should
% have, requiring the use of \protect for fragile commands.

\if@enotesopen \else \@openenotes \fi
\begingroup
\newlinechar='40
\let\protect\string
\immediate\write\@enotes{#1}%
\endgroup}

%  End of unique endnote code

\def\endnotemark{%
\@ifnextchar[\@xendnotemark
{\stepcounter{endnote}%
\protected@xdef\@theenmark{\theendnote}%
\@endnotemark}}

\def\@xendnotemark[#1]{%
\begingroup
\c@endnote #1\relax
\unrestored@protected@xdef\@theenmark{\theendnote}%
\endgroup
\@endnotemark}

\def\@endnotemark{%
\leavevmode
\ifhmode\edef\@x@sf{\the\spacefactor}\nobreak\fi
\makeenmark
\ifhmode\spacefactor\@x@sf\fi
\relax}

\def\endnotetext{%
\@ifnextchar [\@xendnotenext
{\protected@xdef\@theenmark{\theendnote}%
\@endnotetext}}

\def\@xendnotenext[#1]{\begingroup \c@endnote=#1\relax
\xdef\@theenmark{\theendnote}\endgroup \@endnotetext}

\def\@xendnotenext[#1]{%
\begingroup
\c@endnote=#1\relax
\unrestored@protected@xdef\@theenmark{\theendnote}%
\endgroup
\@endnotetext}

%  \theendnotes actually prints out the endnotes.

%  The user may want separate endnotes for each chapter, or a big
% block of them at the end of the whole document.  As it stands,
% either will work; you just say \theendnotes wherever you want the
% endnotes so far to be inserted.  However, you must add
% \setcounter{endnote}{0} after that if you want subsequent endnotes
% to start numbering at 1 again.

%  \enoteformat is provided so user can specify some special formatting
% for the endnotes.  It needs to set up the paragraph parameters, start
% the paragraph, and print the label.  The \mbox stuff in \enoteheading
% is to make and undo a dummy paragraph, to get around the games \section*
% plays with paragraph indenting and instead give us uniform
% indenting for all notes.

\def\notesname{Notes}%
\@mkboth{\MakeUppercase{\notesname}}{\MakeUppercase{\notesname}}}%
\mbox{}\par\vskip-\baselineskip}

\def\enoteformat{\rightskip\z@ \leftskip\z@ \parindent=1.8em
\leavevmode\llap{\makeenmark}}

\def\enotesize{\footnotesize}

\def\theendnotes{\immediate\closeout\@enotes \global\@enotesopenfalse
\begingroup
\makeatletter
%
% The machinery with \@ResetGT and > here ensures that
% \@doanenote works properly even if > is an active character
% at the point where \theendnotes is invoked. > needs to have
% catcode 12 when the arguments of \@doanenote are scanned, so
% that the > in the string "macro:->" is matched.  The actual
% footnote text is not an argument to \@doanenote, but just
% follows it in the .ent file; so \@ResetGT can reset the
% category code for > that should be used when processing
% that text.  That resetting takes place within a
% \begingroup-\endgroup block set up by \@doanenote and
% \@endanenote, so the catcode for > is back to 12 for the
% next note.
%
\edef\@tempa{\string >}%
\ifnum\catcode\@tempa=12%
\let\@ResetGT\relax
\else
\edef\@ResetGT{\noexpand\catcode\@tempa=\the\catcode\@tempa}%
\@makeother\>%
\fi
\def\@doanenote##1##2>{\def\@theenmark{##1}\par\begingroup
\@ResetGT
\edef\@currentlabel{\csname p@endnote\endcsname\@theenmark}%
\enoteformat}
\def\@endanenote{\par\endgroup}%
\enotesize
\input{\jobname.ent}%
\endgroup}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% hyperendnotes.sty started
\makeatletter
\newcounter{Hendnote}
% Redefining portions of endnotes-package:
\let\savedhref\href
\let\savedurl\url
\def\endnotemark{%
\@ifnextchar[\@xendnotemark{%
\stepcounter{endnote}%
\protected@xdef\@theenmark{\theendnote}%
\protected@xdef\@theenvalue{\number\c@endnote}%
\@endnotemark
}%
}%
\def\@xendnotemark[#1]{%
\begingroup\c@endnote#1\relax
\unrestored@protected@xdef\@theenmark{\theendnote}%
\unrestored@protected@xdef\@theenvalue{\number\c@endnote}%
\endgroup
\@endnotemark
}%
\def\endnotetext{%
\@ifnextchar[\@xendnotenext{%
\protected@xdef\@theenmark{\theendnote}%
\protected@xdef\@theenvalue{\number\c@endnote}%
\@endnotetext
}%
}%
\def\@xendnotenext[#1]{%
\begingroup
\c@endnote=#1\relax
\unrestored@protected@xdef\@theenmark{\theendnote}%
\unrestored@protected@xdef\@theenvalue{\number\c@endnote}%
\endgroup
\@endnotetext
}%
\def\endnote{%
\@ifnextchar[\@xendnote{%
\stepcounter{endnote}%
\protected@xdef\@theenmark{\theendnote}%
\protected@xdef\@theenvalue{\number\c@endnote}%
\@endnotemark\@endnotetext
}%
}%
\def\@xendnote[#1]{%
\begingroup
\c@endnote=#1\relax
\unrestored@protected@xdef\@theenmark{\theendnote}%
\unrestored@protected@xdef\@theenvalue{\number\c@endnote}%
\show\@theenvalue
\endgroup
\@endnotemark\@endnotetext
}%
\def\@endnotemark{%
\leavevmode
\ifhmode
\edef\@x@sf{\the\spacefactor}\nobreak
\fi
\expandafter\@firstofone
\else
\expandafter\@gobble
\fi
{%
\hyper@@anchor{Hendnotepage.\@theenvalue}{\empty}%
}%
}%
\makeenmark
\ifhmode
\spacefactor\@x@sf
\fi
\relax
}%
\long\def\@endnotetext#1{%
\if@enotesopen
\else
\@openenotes
\fi
\immediate\write\@enotes{%
\@doanenote{\@theenmark}{\@theenvalue}%
}%
\begingroup
\def\next{#1}%
\newlinechar='40
\immediate\write\@enotes{\meaning\next}%
\endgroup
\immediate\write\@enotes{%
\@endanenote
}%
}%
\def\theendnotes{%
\immediate\closeout\@enotes
\global\@enotesopenfalse
\begingroup
\makeatletter
\edef\@tempa{\string>}%
\ifnum\catcode\@tempa=12
\let\@ResetGT\relax
\else
\edef\@ResetGT{\noexpand\catcode\@tempa=\the\catcode\@tempa}%
\@makeother\>%
\fi
\def\@doanenote##1##2##3>{%
\def\@theenmark{##1}%
\def\@theenvalue{##2}%
\par
\smallskip %<-small vertical gap between endnotes
\begingroup
\def\href{\expandafter\savedhref}%
\def\url{\expandafter\savedurl}%
\@ResetGT
\edef\@currentlabel{\csname p@endnote\endcsname\@theenmark}%
\enoteformat
}%
\def\@endanenote{%
\par\endgroup
}%
% Redefine, how numbers are formatted in the endnotes-section:
\renewcommand*\@makeenmark{%
\hbox{\normalfont\@theenmark~}%
}%
% font-size of endnotes
\enotesize
\input{\jobname.ent}%
\endgroup
}%
\def\enoteformat{%
\rightskip\z@
\leftskip1.8em
\parindent\z@
\leavevmode\llap{%
\setcounter{Hendnote}{\@theenvalue}%
\refstepcounter{Hendnote}%
\expandafter\@secondoftwo
\else
\expandafter\@firstoftwo
\fi
{\@firstofone}%
{\makeenmark}%
}%
}%
% stop redefining portions of endnotes-package:
\makeatother
% Toggle switch in order to turn on/off back-links in the
% endnote-section:


I would like to control the \queriesoff command in endnote.sty but it is totally off in my .tex document.

My marginal note output below mentioned here:

If i am using the endnotes inside the float below mentioned error will be thrown:

   ! Argument of \Hy@tempa has an extra }.
<inserted text>
\par
l.34 ...tion\label{fig:1}\endnote{figure endnote}}

?
! Emergency stop.


How can I do this?

• Note that I have edited your question. You should check it carefully to ensure that I have not misinterpreted you. I have not done anything about the parts which I understand least well. These include 'Vertical and horizontal query alignments are not affected the paragraph text. ' and the sentence beginning 'My required first page...'. I have guessed a bit for 'I would like to control...' but I don't really know what is meant here. Note that you must use backticks for inline code - not quotation marks. I have also formatted your MWE as code. – cfr Jan 14 '15 at 3:18
• @cfr I edit and save my endnote.sty file and question. Please advice to achieve the required output – Vetri Jan 14 '15 at 6:09
• See tex.stackexchange.com/questions/8685/footnotes-and-floats. I still don't understand your question fully, but insofar as you are trying to use notes in floats, that is likely to be the problem. – cfr Jan 14 '15 at 13:26
• @cfr: Sorry for the late reply. The above mentioned question is not fulfill my requirement. My requirement is endnotes working all floats environments like "figure, tables, multicol, minipage, vbox". Current endnote.sty file is supported paragraph environments only. If i coded the float environment the error will be throw. If you know any logic kindly share with me... – Vetri Jan 21 '15 at 18:41
• As I say, I don't really understand your question completely. However, insofar as you are trying to use notes in floats, that is the problem as this won't work. There are workarounds for some cases (e.g. put the note in the float environment or make a marker and then add the note outside the float environment), but those will not support the 'one-size-fits-all' syntax you suggest in the question. (Again, I'm afraid that I don't fully understand the question. So I might have misunderstood what you are trying to do.) – cfr Jan 21 '15 at 22:36