# Automating extracting values from existing commands

(Part 1)

I'm trying to extract values or parameters from a predefined command to use in another command. Is this possible?

I'll add an example to clarify:

\fancypagestyle{c.appendix.sep}{
\rfoot{\pbox{5cm}{\hyperlink{document.toc}{$\leftarrow$ Naar inhoudsopgave} \\ \hyperlink{appendix.a}{$\leftarrow$ Naar \textbf{\textcolor{blue}{R}} commando's} \\ \hyperlink{appendix.b}{$\leftarrow$ Naar begrippenlijst }}}%
\lfoot{\currentsection}
}


Imagine I could extract say, rfoot value for reuse in another command?

(Part 2)

Is there any way to automate this over a range of commands, to only pick the very last declared object? (When choosing where to extract the value from)

-
Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Henri Menke Apr 28 '14 at 8:30
fancyhdr stores the rfoot values in \f@ncyerf and \f@ncyorf. – Henri Menke Apr 28 '14 at 8:33
I didn't include an MWE because this question was not related to any specific packages or functionality thereof. How do I call these values back and how far do they go back? – 1010011010 Apr 28 '14 at 8:35
@Euryris there is no general mechanism, it relies on each command to have stored (or not) its arguments in internal macros. If you go \newcommand\foo[1]{....#1___} then when executing ... tex has no record that it is in the expansion of \foo TeX is a macro expansion language, it just works by textual substitution of the tokens, there is no call stack. – David Carlisle Apr 28 '14 at 8:39

For part 1 of your question, I looked up, which macros are used to store values in fancyhdr.sty. It reveals, that the content of \rfoot is stored in \f@ncyerf and \f@ncyorf.

\documentclass{article}
\usepackage{fancyhdr}
\rfoot{Hello footer}
\pagestyle{fancy}
\begin{document}
\makeatletter
The \texttt{\string\rfoot} contains: \f@ncyorf
\makeatother
\end{document}


-

Save the needed value in an own macro:

\documentclass{article}
\usepackage[a6paper]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\let\Rfoot\rfoot
\renewcommand\rfoot[1]{\def\LastRfoot{#1}\Rfoot{#1}}
\rfoot{Hello footer}

\begin{document}
The \texttt{\textbackslash rfoot} contains: \LastRfoot
\newpage
\rfoot{My new footer}
The \texttt{\textbackslash rfoot} contains: \LastRfoot
\end{document}

-
I guess this fails, if \rfoot was defined as \outer\def\rfoot`. – Henri Menke Apr 29 '14 at 12:47