0

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.

  1. 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
  2. strips the @ 'at' sign from the beginning of the endnote, then
  3. calls the \endnote macro using whatever text follows the @ 'at' sign, then
  4. 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}

Using @ to convert Footnote to Endnote 1st Footnote via "footnote -> fnote"

Notice how Endnotes Endnote B and Endnote C fail to replace Endnote 2 and Endnote 3 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 Endnote 2 and Endnote 3 with Endnote B and Endnote C respectively while retaining the ability to use the @ character to shift a footnote to an endnote would be appreciated.

Thank you.

1 Answer 1

1

The problem is that \IfBeginWith expands its argument and you get the error when \url is expanded. You would get the same error simply with \edef\foo{\url{whatever}}.

The solution is to avoid xstring.

\documentclass{article}

\usepackage{endnotes}
\usepackage{hyperref}

\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
}

\begin{document}

Lorem\footnote{@\url{https://www.ilo.org/wcmsp5/groups/public/---ed_dialogue/---sector/documents/meetingdocument/wcms_741659.pdf}} ipsum dolor sit amet.\footnote{\url{https://www.ilo.org/wcmsp5/groups/public/---ed_dialogue/---sector/documents/meetingdocument/wcms_741659.pdf}}

\theendnotes
\end{document}

To answer your last question and obtain the same effect with \footnotetext you may simply mimic the redefinition of \footnote. Although \footnote itself uses \footnotetext, it should work.

\let\fnotetext\footnotetext

\renewcommand\footnotetext[1]{\xfntext#1\empty\xfntext}

\long\def\xfntext#1#2\xfntext{%
  \def\tempa{#1}%
  \def\tempb{@}%
  \ifx\tempa\tempb
    \endnote{#2}%
  \else
    \fnotetext{#1#2}%
  \fi
}
19
  • @Domenjoud Thank you for the code. There seems to be an issue with one website that I've footnoted: ilo.org/wcmsp5/groups/public/---ed_dialogue/---sector/documents/… The code works fine if I include the URL as an endnote, but NOT as a footnote. Any Ideas?
    – Fenote
    Commented Nov 21, 2021 at 0:58
  • @Domenjoud The error that appears when I include the above URL as a footnote (wo the leading @) in your sample code above is: ./Testing Code 2.tex:24: Missing $ inserted. <inserted text> $ l.24 ...ocuments/meetingdocument/wcms_741659.pdf}} Any Ideas? Thank you!
    – Fenote
    Commented Nov 21, 2021 at 1:11
  • The problem was that \xfnt took \url as its first argument and the url without the braces as its second argument. The braces were stripped because the argument is a single group. The trick is to add \empty after the argument so that it does consist anymore in a single group and the braces are not stripped. I updated the code. Commented Nov 21, 2021 at 10:27
  • @Domenjoud Thank you!! Works GREAT!! If I may, I'd like to take this opportunity to link another SE posting to “To add a horizontal rule below the 'Notes' heading” at <tex.stackexchange.com/questions/56145/…>. Adds a nice touch the the "Notes" heading. Enjoy!
    – Fenote
    Commented Nov 24, 2021 at 3:39
  • Works like a charm with Scrivener + LaTeX as well! Thanks! Commented Nov 24, 2021 at 3:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .