0

Building on the helpful suggestions offered by @moewe both here and here, I wanted seek assistance for a more complex footnote citation command that would allow the user to include page numbers as well. Long story short, I'm helping a colleague with an old project that uses natbib.

Minimal working example as follows,

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{A01,
    author = {Author Name},
    publisher = {Publisher Co.},
    title = {Title of the Book},
    year = {2022}}
\end{filecontents}
\listfiles

\documentclass{article} \usepackage{natbib}

\begin{document}

\NewDocumentCommand{\footcite}{om}{\footnote{\IfNoValueTF{#1}{\cite{#2}}{\cite[#1]{#2}}}}

Test function of footnote citation without page number.\footcite{A01}

Test function of footnote citation with page number.\footcite[2]{A01}

\bibliographystyle{plainnat} \bibliography{\jobname}

\end{document}

Unfortunately the command \NewDocumentCommand{\footcite}{om}{\footnote{\IfNoValueTF{#1}{\cite{#2}}{\cite[#1]{#2}}}} results in undefined control sequence errors.

Any guidance or suggestions would be greatly appreciated!

1 Answers1

0

After some tinkering I finally figured it out! Please see the now functional MWE with desired output. Also note that I added some stylistic options. I hope this helps future users in similar need!

\RequirePackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{A01,
    author = {Author Name},
    publisher = {Publisher Co.},
    title = {Title of the Book},
    year = {2022}}
\end{filecontents}
\listfiles

\documentclass{article} \usepackage{natbib} \setcitestyle{authoryear,open={(},close={)}} %Citation-related command, replaces default brackets to parentheses \setcitestyle{aysep={}} %Citation-related command, removes default comma between author & year

\usepackage{xparse} \NewDocumentCommand\footcite{o m} {% \footnote{ % \IfNoValueTF {#1}% {\citet{#2}}% {\citet[#1]{#2}}% } }

\begin{document}

Test function of footnote citation without page number.\footcite{A01}

Test function of footnote citation with page number.\footcite[2]{A01}

\bibliographystyle{plainnat} \bibliography{\jobname}

\end{document}