# Command (using \ifthenelse) within 2nd optional (post) argument of footcite

I have defined a new command \mypageref to reference page numbers of text parts in my appendix. The begin of such a text part is labeled, e.g., by \label{text_begin}, and the end of the text part is labeled, e.g., by \label{text_end}. The statement is intended to either print, e.g., "S. 42" if the text part is entirely on page 42, or to print, e.g., "S. 42 - 44" if the text part is going over multiple pages. I use the \ifthenelse statement of the ifthen package. The command is defined as follows:

    \newcommand{\mypageref}[2]{
\ifthenelse{\equal{\pageref{#1}}{\pageref{#2}}}
{S. \pageref{#1}}
{S. \pageref{#1}\ --\ \pageref{#2}}
}


It works fine in the main text and in footnotes. However, I have the situation, that my appendix contains text which also belongs to a "source" with an own entry in my bib file, lets say

    @misc{biblabel,
author = {AAA},
title = {BBB},
year = 2014
}


Now, I want to use

    \footcite[pre][\mypageref{text_begin}{text_end}]{biblabel}


which fails with the error: "Missing \endcsname inserted".

Interestingly,

    \footcite[\mypageref{text_begin}{text_end}][post]{biblabel}


works. In other words, using the \mypageref in the 1st optional argument (pre) works, but not in the 2nd optional argument (post). I use biblatex and biber. Note that \footcite as well as \mypageref work fine separately.

    \usepackage{etoolbox}