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.

Fenote
  • 47
  • 5

1 Answers1

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 }

Fenote
  • 47
  • 5
  • @Domenjoud Thank you for the code. There seems to be an issue with one website that I've footnoted: https://www.ilo.org/wcmsp5/groups/public/---ed_dialogue/---sector/documents/meetingdocument/wcms_741659.pdf
    The code works fine if I include the URL as an endnote, but NOT as a footnote. Any Ideas?
    – Fenote Nov 21 '21 at 00: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. $ l.24 ...ocuments/meetingdocument/wcms_741659.pdf}} Any Ideas? Thank you! – Fenote Nov 21 '21 at 01: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. – Eric Domenjoud Nov 21 '21 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 https://tex.stackexchange.com/questions/56145/is-there-a-way-to-move-all-footnotes-to-the-end-of-the-document. Adds a nice touch the the "Notes" heading. Enjoy! – Fenote Nov 24 '21 at 03:39
  • Works like a charm with Scrivener + LaTeX as well! Thanks! – RosesBouquet Nov 24 '21 at 03:49
  • I've been using the following code (courtesy the LaTeX forum) to change the endnote marks from numbers (1,2,3 ...) to capitol letters (A,B,C,...):
    \makeatletter
    \renewcommand*\makeenmark{\hbox{\textsuperscript{\@Alph{\theenmark}}}}
    \makeatother
    

    ,
    However, when I add Domenjoud's code from above that tests for endnotes (when the at '@' sign is the first character in the text of an endnote), *ALL* the endnotes marks revert from capital letters (A,B,C,...) back to numbers (1,2,3 ...). Any thoughts? Thank you!

    – RosesBouquet Nov 24 '21 at 04:36
  • @RosesBouquet I made some tests and did not see your problem occur. Could you be mode specific ? I don't see how my code could interfer with \makeenmark. – Eric Domenjoud Nov 24 '21 at 08:22
  • My Bad! I used code to "[Change the look of the endnotes on the 'Notes' page (\theendnotes)][1]":

    \makeatletter \def\enoteformat{% \rightskip\z@ \leftskip\z@ \parindent=1.8em \leavevmode{\setbox\z@=\lastbox}\llap{\theenmark.\enskip}% } \makeatother.

    I need to move the endnote marker into the margin (Bringhurst-style) as shown in the answer to the above post.

    The above code works only for numeric endnotes. How can I move the alpha endnote marker into the margin? [1]: https://tex.stackexchange.com/questions/286339/changing-the-look-of-the-endnotes-on-the-notes-page-theendnotes

    – RosesBouquet Nov 24 '21 at 09:31
  • @RosesBouquet In the definition of \enoteformat just replace \llap{\theenmark.\enskip} with \llap{\@Alph\theenmark.\enskip} – Eric Domenjoud Nov 24 '21 at 13:31
  • @Domenjoud Your code worked like a charm! Thank you!!! Now all I need to figure out is how to make the endnotes within the body of the text active links so that when highlighted with the cursor, a window opens showing the endnote text at the end of the chapter or section. Works fine for footnotes, just not for endnotes! Thank you again for all your help! Can I do anything else to give you credit for your answer? – RosesBouquet Nov 25 '21 at 08:05
  • @RosesBouquet There are a number of solutions for this. Just search 'endnote hyperref' on stackexchange. – Eric Domenjoud Nov 26 '21 at 10:38
  • @Domenjoud - How do I 'accept' your answer so you get credit? I've been using your code for over a month now and I want to be sure you are given credit. – RosesBouquet Dec 28 '21 at 08:03
  • i think that you just have to accept the answer. But anyway, I'm not looking for credit. I'm glad that my answer is useful to you. – Eric Domenjoud Dec 28 '21 at 19:35
  • @Domenjoud - I'm now wrestling with adapting your solution above (which is working very well!) to see if there is a way to adapt it with the \footnotemark & \footnotetext footnote macros. I'd like to be able to simply add the leading @ character to each \footnotetext to convert it to an endnote. Right now adding the leading @ character to each \footnotetext does NOT convert it to an endnote. To get the same endnote effect with \footnotetext, do I simply create a duplicate \renewcommand\footnotetext[1] macro? Thanks! – RosesBouquet Mar 01 '22 at 14:50
  • @RosesBouquet I edited my answer. – Eric Domenjoud Mar 01 '22 at 22:16
  • @Domenjoud - I've been using your Footnote<> Endnote code (that utilizes the @ character to switch between the two) for some time and it works GREAT! Per your suggestion, I also was able to adapt the code for use with footnotemark+footnotetext, but the behavior is not working completely as it should. I'd like to post the issue for review. Question: Should I simply add the footnotemark+footnotetext MWE as a supplement to my initial posting here, or should I create a separate posting with a link back to this posting with your solutions? – Fenote Mar 23 '22 at 03:11
  • @Fenote The best may be to just edit your question. – Eric Domenjoud Mar 23 '22 at 09:10
  • @Fenote The problem when using \foonotemark and \footnotetext is that the indication that the note should be turned into an endnote is provided only in the argument of \footnotetext. At the time you use \footnotemark, there is no way to know that it should actually use \endnotemark instead. I don't see a way around. – Eric Domenjoud Mar 25 '22 at 09:10
  • @Domenjoud - Thank you for your insight. The challenge appears to be daunting, far beyond my LaTeX knowledge. I wonder if it would be worth presenting the matter as a separate post for consideration. The flexibility of using the @ character to quickly switch between a footnote and endnote is a powerful way to address the special 'real estate' issues that can occur. The space traditionally reserved for words must now compete with images (and other graphics), tables, minipages, etc. that can quickly shift appearance with each recompiling. – Fenote Mar 26 '22 at 03:27