Note: This posting has been augmented to reflect a corollary issue. Please refer to the UPDATE below:
I'm seeing the following error "Undefined control sequence" when using MWE below ...
./Fnote.tex:15: Undefined control sequence. \hyper@normalise ...M{ }\catcode `%\active \let % @percentchar \let %@per... l.15 ...t amet.\footnote{\url{https://google.com}}
I'm using Scrivener with LaTeX. Scrivener does not support endnotes natively, so I've tried to use the following \fnote macro to accommodate endnotes.
- The macro first tests for the presence of an endnote (e.g. if the text string begins with the character @ 'at' sign), then if present
- strips the @ 'at' sign from the beginning of the endnote, then
- calls the \endnote macro using whatever text follows the @ 'at' sign, then
- if no @ 'at' sign is found, the text string is treated as a footnote.
If the macro worked, it would have allowed for the use of footnotes as endnotes, as endnotes are not natively supported within Scrivener.
Any and all thoughts or comments greatly appreciated.
\documentclass{article}
\usepackage{endnotes} %
\usepackage{ifthen}
\usepackage{xstring}
\usepackage{hyperref}
\let\fnote\footnote
\renewcommand{\footnote}[1]{
\IfBeginWith{#1}{@}
{\endnote{\StrDel[1]{#1}{@}}} %%
{\fnote{#1}}
}
\begin{document}
Lorem ipsum dolor sit amet.\footnote{\url{https://google.com}}
% Nesting of \footnote{ ... \url{...} ... } throws an error.
\theendnotes %
\end{document}
UPDATE: As per Domenjoud's suggestion I am adding the results of a followup item posted earlier. Domenjoud's solution to the original post (utilizing an initial @ character to switch from Footnotes to Endnotes) has worked extremely well. Yet, the attempt to extend Domenjoud's solution for use with footnotemark+footnotetext has revealed issues.
In the following MWE, I've highlighted how the footnote-to-endnote shift behaves when the initial @ character is used to shift a footnote to endnote using footnotemark+footnotetext.
\documentclass{article}
\usepackage{endnotes}
\usepackage{hyperref}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage[T1]{fontenc}
% \footnote -> \fnote
\let\fnote\footnote
\renewcommand\footnote[1]{\xfnt#1\empty\xfnt}
\long\def\xfnt#1#2\xfnt{%
\def\tempa{#1}%
\def\tempb{@}%
\ifx\tempa\tempb
\endnote{#2}%
\else
\fnote{#1#2}%
\fi
}
% \footnotetext -> \fnotetext
\let\fnotetext\footnotetext
\renewcommand\footnotetext[1]{\xfntext#1\empty\xfntext}
\long\def\xfntext#1#2\xfntext{%
\def\tempc{#1}%
\def\tempd{@}%
\ifx\tempc\tempd
\endnote{#2}%
\else
\fnotetext{#1#2}%
\fi
}
% Color endnotes red
\makeatletter
\renewcommand*\makeenmark{\hbox{\textcolor{red}{\textsuperscript{\@Alph{\theenmark}}}}}
\makeatother
% Change endnotes to Alph
\makeatletter
\def\enoteformat{%
\rightskip\z@ \leftskip\z@ \parindent=1.8em
\leavevmode{\setbox\z@=\lastbox}\llap{%
\@Alph\theenmark.\enskip}%
}
\makeatother
\begin{document}
\lipsum[1][1-3] (\textcolor{cyan}{1st \textbf{Foot}note} via "\textcolor{purple}{\textbf{footnote -> fnote}}").\,\footnote{This is \textcolor{cyan}{1st \textbf{Foot}note} via "\textcolor{purple}{\textbf{footnote -> fnote}}". Google. \url{http://www.google.com}} Works Great! \par
\par
\lipsum[1][3-4] (\textcolor{cyan}{1st \textbf{End}note} via "\textcolor{purple}{\textbf{footnote -> fnote}}").\,\footnote{@\,This is the \textcolor{cyan}{1st \textbf{End}note} via "\textcolor{purple}{\textbf{footnote -> fnote}}". Google (Germany). \url{http://www.google.de}} Also works great !\par
\par
\lipsum[2][1-3] (\textcolor{cyan}{2nd \textbf{End}note} via "\textcolor{violet}{\textbf{footnotetext -> fnotetext}}").\footnotemark\;\lipsum[2][4-7] Doesn't work so great ... :( \par
\footnotetext{@\,\textcolor{cyan}{2nd \textbf{End}note} via "\textcolor{violet}{\textbf{footnotetext -> fnotetext}}". CNN (US). \url{https://www.cnn.com}} \par
\lipsum[3][1-3] (\textcolor{cyan}{3rd \textbf{End}note} via "\textcolor{violet}{\textbf{footnotetext -> fnotetext}}").\footnotemark \lipsum[3][4-7] Also doesn't work so great ... :( \par
\footnotetext{@\,\textcolor{cyan}{3rd \textbf{End}note} via "\textcolor{violet}{\textbf{footnotetext -> fnotetext}}". CNN Europe. \url{https://www.cnn.com/europe}} \par
\theendnotes % Print the endnotes
\end{document}
Notice how Endnotes and fail to replace and respectively, and are significantly offset below where they should appear.
When footnotemark+footnotetext are used in conjunction with the @ sign in a LaTeX minipage
to convert a footnote to an endnote, the offset is even more pronounced.
Any thoughts as to how I might properly replace and with and respectively while retaining the ability to use the @ character to shift a footnote to an endnote would be appreciated.
Thank you.