1

I'm trying to refer to an existing footnote inside an algorithm, and I tried following this link but it doesn't work. I added the algorithm within a minipage so that the footnote appears soon after it.

This is the MWE:

\documentclass{article}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor} % use color

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{arydshln} % for cdashline

\usepackage[noend]{algpseudocode}
\usepackage{algorithm}
\usepackage{algorithmicx}

\algtext*{EndWhile}% Remove "end while" text
\algtext*{EndFor}% Remove "end for" text
\algtext*{EndIf}% Remove "end if" text

\newcommand{\inlinecomment}[1]{{\color{gray} \it-- #1}}

\usepackage[colorlinks,bookmarksopen,bookmarksnumbered,citecolor=red,urlcolor=red]{hyperref}


% increase line spacing for algorithmicx
\usepackage{etoolbox}
\makeatletter
\expandafter\patchcmd\csname\string\algorithmic\endcsname{\itemsep\z@}
{\itemsep=0.2ex plus2pt}{}{}
\makeatother

% reduce font size for algorithms
\makeatletter
\renewcommand{\ALG@beginalgorithmic}
{\tt\small}
\makeatother

% redefine pseudo-code commands
\algnewcommand\algorithmicto{\textbf{to}}
%\algrenewtext{For}[3]{\algorithmicfor\ #1 $=$ #2 \algorithmicto\ #3}
\algrenewtext{While}{\textbf{while}\ }
%\algrenewtext{EndWhile}{\textbf{end}}
\algrenewtext{Procedure}[2]{\textbf{function}\ \textproc{#1}\ifthenelse{\equal{#2}{}}{}{(#2)}}
%\algrenewtext{EndProcedure}{\textbf{end}}



\newcommand*\Let[2]{\State #1 $\gets$ #2}
\algrenewcommand\algorithmicrequire{\textbf{Input:}}
\algrenewcommand\algorithmicensure{\textbf{Output:}}



\newcommand{\bs}[1] {\boldsymbol{#1}}

\begin{document}

\noindent\begin{minipage}{\textwidth}
\renewcommand\footnoterule{}
\begin{algorithm}[H]
  \caption{test footnote \label{alg:assemble_t3i}}
  \begin{algorithmic}[0]
    \Require{Input goes here}
    \Statex
    \Function{BAR}{$\ldots$}
      \State \inlinecomment{loop}
      \For {$i \gets 1, \ldots , n$}
         \Let{$ foo $\footnote{This is the footnote $\bs \xi$}}{$\text{bar} \left({\bs \xi_i }\right) $} \Comment{Here I have the first footnote} 
         \Let{$foo^a$}{$ \text{test} (\ldots)$} \Comment{I want to refer to the same footnote here}

      \EndFor
    \EndFunction
  \end{algorithmic}
\end{algorithm}
\end{minipage}

\end{document}

which gives me enter image description here

You see that I'm cheating now since I added ^a. Is there a way to solve this?

1

Based on https://tex.stackexchange.com/a/35044/36296

\documentclass{article}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor} % use color

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{arydshln} % for cdashline

\usepackage[noend]{algpseudocode}
\usepackage{algorithm}
\usepackage{algorithmicx}

\algtext*{EndWhile}% Remove "end while" text
\algtext*{EndFor}% Remove "end for" text
\algtext*{EndIf}% Remove "end if" text

\newcommand{\inlinecomment}[1]{{\color{gray} \it-- #1}}

\usepackage[colorlinks,bookmarksopen,bookmarksnumbered,citecolor=red,urlcolor=red]{hyperref}


% increase line spacing for algorithmicx
\usepackage{etoolbox}
\makeatletter
\expandafter\patchcmd\csname\string\algorithmic\endcsname{\itemsep\z@}
{\itemsep=0.2ex plus2pt}{}{}
\makeatother

% reduce font size for algorithms
\makeatletter
\renewcommand{\ALG@beginalgorithmic}
{\tt\small}
\makeatother

% redefine pseudo-code commands
\algnewcommand\algorithmicto{\textbf{to}}
%\algrenewtext{For}[3]{\algorithmicfor\ #1 $=$ #2 \algorithmicto\ #3}
\algrenewtext{While}{\textbf{while}\ }
%\algrenewtext{EndWhile}{\textbf{end}}
\algrenewtext{Procedure}[2]{\textbf{function}\ \textproc{#1}\ifthenelse{\equal{#2}{}}{}{(#2)}}
%\algrenewtext{EndProcedure}{\textbf{end}}



\newcommand*\Let[2]{\State #1 $\gets$ #2}
\algrenewcommand\algorithmicrequire{\textbf{Input:}}
\algrenewcommand\algorithmicensure{\textbf{Output:}}



\newcommand{\bs}[1] {\boldsymbol{#1}}


\makeatletter
\newcommand\footnoteref[1]{\protected@xdef\@thefnmark{\ref{#1}}\@footnotemark}
\makeatother

\begin{document}

\noindent\begin{minipage}{\textwidth}
\renewcommand\footnoterule{}
\begin{algorithm}[H]
  \caption{test footnote \label{alg:assemble_t3i}}
  \begin{algorithmic}[0]
    \Require{Input goes here}
    \Statex
    \Function{BAR}{$\ldots$}
      \State \inlinecomment{loop}
      \For {$i \gets 1, \ldots , n$}
         \Let{$ foo $\footnote{\label{test}This is the footnote $\bs \xi$}}{$\text{bar} \left({\bs \xi_i }\right) $} \Comment{Here I have the first footnote} 
         \Let{$foo$\footnoteref{test}}{$ \text{test} (\ldots)$} \Comment{I want to refer to the same footnote here}

      \EndFor
    \EndFunction
  \end{algorithmic}
\end{algorithm}
\end{minipage}

\end{document}

enter image description here

  • I marked your solution as the answer, but could you please provide some info on what was the problem? Why footnoteref has to be redefined? – aaragon Nov 22 '16 at 10:47
  • @aaragon Honestly, I don't really know. Please read the linked answer for more explanation. – samcarter_is_at_topanswers.xyz Nov 22 '16 at 12:15
1

The defaut placement of the footnote mark is via \textsuperscript. So we can define \footnoteref to do something similar:

enter image description here

\documentclass{article}

\usepackage[noend]{algpseudocode}
\usepackage{algorithm}

\usepackage[colorlinks]{hyperref}

\newcommand\footnoteref[1]{\textsuperscript{\ref{#1}}}

\begin{document}

\noindent\begin{minipage}{\textwidth}
\renewcommand\footnoterule{}
\begin{algorithm}[H]
  \caption{test footnote}
  \begin{algorithmic}[0]
    \State $foo$\footnote{\label{test}This is the footnote} \Comment{Here I have the first footnote} 
    \State $foo$\footnoteref{test} \Comment{I want to refer to the same footnote here}
  \end{algorithmic}
\end{algorithm}
\end{minipage}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.