1

I am using LaTeX with Natbib, and would like to change the fonts for my in-line, author-date citations (but not in the bibliography itself). I have found ways to change the font of the author's name (as here), and also to change the font of numerical citations (same page), but I can't find a way to change the font (or more importantly, just the size) of the year numbers in an author-date citation.

I suppose this might be easier in BibLaTeX, but I'd like to avoid the move if I can.

  • Welcome to TeX.sx! The size? Can you explain what you mean? – egreg Feb 08 '13 at 21:58
  • @egreg: I just mean the font size of the numbers in an author-date citation. For example, I'd like to change the font size of "1905" in a citation like "(Einstein 1905)", or like "Einstein (1905)". – user61367 Feb 09 '13 at 09:12
  • 3
    I don't understand why you should want this. – egreg Feb 09 '13 at 10:46
  • Maybe you are after \oldstylenums: http://tex.stackexchange.com/questions/13455/mixing-oldstylenums-with-strings If you want to use them only locally, this can be of help: http://tex.stackexchange.com/questions/81746/combine-oldstylenums-and-textsc – yo' Feb 15 '13 at 16:28
  • To clarify: I only wish to change the font-size of the numbers in an author-date citation, like "author [date]", or "[author, date]". As above, I've found ways to change the font and/or size for the author's name, but not the date. – user61367 Feb 16 '13 at 10:41

1 Answers1

3

I originally thought you could change the formatting by patching the \NAT@split macro where the \NAT@date macro is set. The problem with this is that the \NAT@date macro is used in conditionals so it doesn't have the right form if you patch it. This means you need to patch where the \NAT@date macro is used.

the \NAT@date macro is used in a number of places in the \NAT@citex macro. I found it easier to copy the definition of the macro from natbib.sty and do the replacements by hand, but you can probably use regexpatch to do it. Basically, wherever \NAT@date is expanded and typeset, I replaced it with dateFormat{\NAT@date}. You do not want to add the formatting into the conditionals

\documentclass{article}

\usepackage[authoryear]{natbib}

\bibliographystyle{plainnat}

\newcommand{\dateFormat}[1]{{\LARGE#1}}
\makeatletter
\def\NAT@citex%
  [#1][#2]#3{%
  \NAT@reset@parser
  \NAT@sort@cites{#3}%
  \NAT@reset@citea
  \@cite{\let\NAT@nm\@empty\let\NAT@year\@empty
    \@for\@citeb:=\NAT@cite@list\do
    {\@safe@activestrue
     \edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
     \@safe@activesfalse
     \@ifundefined{b@\@citeb\@extra@b@citeb}{\@citea%
       {\reset@font\bfseries ?}\NAT@citeundefined
                 \PackageWarning{natbib}%
       {Citation `\@citeb' on page \thepage \space undefined}\def\NAT@date{}}%
     {\let\NAT@last@nm=\NAT@nm\let\NAT@last@yr=\NAT@year
      \NAT@parse{\@citeb}%
      \ifNAT@longnames\@ifundefined{bv@\@citeb\@extra@b@citeb}{%
        \let\NAT@name=\NAT@all@names
        \global\@namedef{bv@\@citeb\@extra@b@citeb}{}}{}%
      \fi
     \ifNAT@full\let\NAT@nm\NAT@all@names\else
       \let\NAT@nm\NAT@name\fi
     \ifNAT@swa\ifcase\NAT@ctype
       \if\relax\NAT@date\relax
         \@citea\NAT@hyper@{\NAT@nmfmt{\NAT@nm}\dateFormat{\NAT@date}}%
       \else
         \ifx\NAT@last@nm\NAT@nm\NAT@yrsep
            \ifx\NAT@last@yr\NAT@year
              \def\NAT@temp{{?}}%
              \ifx\NAT@temp\NAT@exlab\PackageWarningNoLine{natbib}%
               {Multiple citation on page \thepage: same authors and
               year\MessageBreak without distinguishing extra
               letter,\MessageBreak appears as question mark}\fi
              \NAT@hyper@{\NAT@exlab}%
            \else\unskip\NAT@spacechar
              \NAT@hyper@{\dateFormat{\NAT@date}}%
            \fi
         \else
           \@citea\NAT@hyper@{%
             \NAT@nmfmt{\NAT@nm}%
             \hyper@natlinkbreak{%
               \NAT@aysep\NAT@spacechar}{\@citeb\@extra@b@citeb
             }%
             \dateFormat{\NAT@date}
           }%
         \fi
       \fi
     \or\@citea\NAT@hyper@{\NAT@nmfmt{\NAT@nm}}%
     \or\@citea\NAT@hyper@{\dateFormat{\NAT@date}}%
     \or\@citea\NAT@hyper@{\NAT@alias}%
     \fi \NAT@def@citea
     \else
       \ifcase\NAT@ctype
        \if\relax\NAT@date\relax
          \@citea\NAT@hyper@{\NAT@nmfmt{\NAT@nm}}%
        \else
         \ifx\NAT@last@nm\NAT@nm\NAT@yrsep
            \ifx\NAT@last@yr\NAT@year
              \def\NAT@temp{{?}}%
              \ifx\NAT@temp\NAT@exlab\PackageWarningNoLine{natbib}%
               {Multiple citation on page \thepage: same authors and
               year\MessageBreak without distinguishing extra
               letter,\MessageBreak appears as question mark}\fi
              \NAT@hyper@{\NAT@exlab}%
            \else
              \unskip\NAT@spacechar
              \NAT@hyper@{\dateFormat{\NAT@date}}%
            \fi
         \else
           \@citea\NAT@hyper@{%
             \NAT@nmfmt{\NAT@nm}%
             \hyper@natlinkbreak{\NAT@spacechar\NAT@@open\if*#1*\else#1\NAT@spacechar\fi}%
               {\@citeb\@extra@b@citeb}%
             \dateFormat{\NAT@date}
           }%
         \fi
        \fi
       \or\@citea\NAT@hyper@{\NAT@nmfmt{\NAT@nm}}%
       \or\@citea\NAT@hyper@{\dateFormat{\NAT@date}}%
       \or\@citea\NAT@hyper@{\NAT@alias}%
       \fi
       \if\relax\NAT@date\relax
         \NAT@def@citea
       \else
         \NAT@def@citea@close
       \fi
     \fi
     }}\ifNAT@swa\else\if*#2*\else\NAT@cmt#2\fi
     \if\relax\NAT@date\relax\else\NAT@@close\fi\fi}{#1}{#2}}


\makeatother

\begin{document}
\cite{article-minimal}\\
\citep{article-minimal}

\bibliography{xampl}
\end{document}
Troy
  • 13,741
StrongBad
  • 20,495
  • Well carried out hacking... which underlines the fact that the move to biblatex might eventually be the way to go. – Daniel Dec 10 '13 at 15:38
  • @Daniel my guess is someone with some regex foo and a knowledge of regexpatch could probably do the patching automatically pretty easily and someone with better TeX skills than I could probably patch \NAT@date in a way that doesn't screw up the tests. – StrongBad Dec 10 '13 at 17:05