1

I would like BibLaTeX to automatically change the citation style. If the whatever called cite command (in my case, I only use \citet[]{} [w/ or w/o optional argument]) is located inside a footnote, the result should look like this

\citet[20]{Doe:2018}: Doe (2018) 20.

To achieve this, I have already set up a boolean variable

\newif\ifinfootnote  
\let\svfootnote\footnote  
\renewcommand{\footnote}[2][\thefootnote]{%  
    \stepcounter{footnote}%  
    \gdef\infootnote{T}%  
    \svfootnote[#1]{\infootnotetrue#2}%  
}

that checks if you are inside a footnote environment. -- Thanks to @moewe for pointing that out (previous question).

The in text citation is already satisfying my needs

\citet[20]{Doe:2018}: Doe (2018, 20).

Please seethe attached cbx file.

As far as I can see, the solution would look nearly like this

\renewcommand{\citet}[2][]{%
    \if T\infootnote%
        % code for footnote citation
    \else%
        % code for in text citation
    \fi%
}

My cbx file (epicstructure.cbx):

\ProvidesFile{epicstructure.cbx}
[\abx@cbxid]

\ExecuteBibliographyOptions{labeldateparts,uniquename,uniquelist,autocite=inline}

\renewcommand*{\iffinalcitedelim}{\iflastcitekey}

\newbool{cbx:parens}

\newbibmacro*{cite}{%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
       {\usebibmacro{cite:label}%
        \setunit{\printdelim{nonameyeardelim}}}
       {\printnames[bibhyperref]{labelname}%
        \setunit{\printdelim{nameyeardelim}}}%
     \usebibmacro{cite:labeldate+extradate}}
    {\usebibmacro{cite:shorthand}}}

\newbibmacro*{citeyear}{%
  \iffieldundef{shorthand}
    {\iffieldundef{labelyear}
       {\usebibmacro{cite:label}}
       {\usebibmacro{cite:labeldate+extradate}}}
    {\usebibmacro{cite:shorthand}}}

\newbibmacro*{textcite}{%
  \ifnameundef{labelname}
    {\iffieldundef{shorthand}
       {\usebibmacro{cite:label}%
        \setunit{%
          \global\booltrue{cbx:parens}%
          \printdelim{nonameyeardelim}\bibopenparen}%
        \ifnumequal{\value{citecount}}{1}
          {\usebibmacro{prenote}}
          {}%
        \usebibmacro{cite:labeldate+extradate}}
       {\usebibmacro{cite:shorthand}}}
    {\printnames[bibhyperref]{labelname}%
     \setunit{%
       \global\booltrue{cbx:parens}%
       \printdelim{nameyeardelim}\bibopenparen}%
     \ifnumequal{\value{citecount}}{1}
       {\usebibmacro{prenote}}
       {}%
     \usebibmacro{citeyear}}%
}

\newbibmacro*{cite:shorthand}{%
  \printtext[bibhyperref]{\printfield{shorthand}}}

\newbibmacro*{cite:label}{%
  \iffieldundef{label}
    {\printtext[bibhyperref]{\printfield[citetitle]{labeltitle}}}
    {\printtext[bibhyperref]{\printfield{label}}}}

\newbibmacro*{cite:labeldate+extradate}{%
  \iffieldundef{labelyear}
    {}
    {\printtext[bibhyperref]{\usebibmacro{editionsupscr}\printlabeldateextra}}}

\newbibmacro{cite:labelyear+extrayear}{%
  \blx@warning{bibmacro 'cite:labelyear+extrayear' is deprecated.\MessageBreak
    Please use 'cite:labeldate+extradate'.\MessageBreak
    Using 'cite:labeldate+extradate' instead}%
  \usebibmacro{cite:labeldate+extradate}}

\newbibmacro*{textcite:postnote}{%
  \iffieldundef{postnote}
    {\ifbool{cbx:parens}
       {\bibcloseparen}
       {}}
    {\ifbool{cbx:parens}
       {\setunit{\postnotedelim}}
       {\setunit{\extpostnotedelim\bibopenparen}}%
     \printfield{postnote}\bibcloseparen}}

\DeclareCiteCommand{\cite}
  {\usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\cite}
  {\usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{citeyear}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\parencite}[\mkbibparens]
  {\usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\parencite}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{citeyear}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\footcite}%[\mkbibfootnote]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\footcitetext}[\mkbibfootnotetext]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\smartcite}[\iffootnote\mkbibparens\mkbibfootnote]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\textcite}
  {\boolfalse{cbx:parens}}
  {\usebibmacro{citeindex}%
   \iffirstcitekey
     {\setcounter{textcitetotal}{1}}
     {\stepcounter{textcitetotal}%
      \textcitedelim}%
   \usebibmacro{textcite}}
  {\ifbool{cbx:parens}
     {\bibcloseparen\global\boolfalse{cbx:parens}}
     {}}
  {\usebibmacro{textcite:postnote}}

\DeclareCiteCommand{\citeauthor}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexnames{labelname}}
     {}%
   \printnames[bibhyperref]{labelname}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\citeauthor}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexnames{labelname}}
     {}%
   \printnames[bibhyperref][1-1]{labelname}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citeyear}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\printfield[bibhyperref]{year}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\citeyear}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\printfield[bibhyperref]{\usebibmacro{editionsupscr}year}\printfield{extradate}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareMultiCiteCommand{\textcites}{\textcite}{}

\endinput
  • 1
    biblatex already has a footnote tracker. So \ifinfootnote should not be necessary. On the other hand the patching needed for biblatex's footnote tracker may not work for all document classes (it works for the standard and KOMA classes and memoir) out of the box, so a minimal working example would be needed to asses its usefulness. The biblatex part of my answer https://tex.stackexchange.com/a/438013/35864 already shows how this could work. – moewe Aug 21 '18 at 07:20
  • Thanks! Your answer is just what I was looking for. Sorry for asking again. I haven't remembered that, since I thought it caused some other problems. You may delete this question (if possible) or vote down. – rsa-krypto Aug 21 '18 at 12:48
  • If you are happy with the answer there we can vote to close this question as a duplicate. But if you think it makes sense to have a answer here, that would be OK with me as well. Just tell me what works best for you. – moewe Aug 21 '18 at 13:01
  • I would prefer to close this question as a duplicate. The answer is already given somewhere else. – rsa-krypto Aug 21 '18 at 13:11

0 Answers0