1

I am using LaTeX on Windows and I need to customize the formatting of citation labels in my thesis. I produced a new citation style fitting my needs for the natbib package, but I have trouble with label formatting for the \cite{} (\citep{} etc.) commands. The citation style I use requires the author name to be uppercase when in parentheses, like (KNUTH, 1984, p. 42), but differently when not in parentheses, stated by Knuth (1984, p. 42). As a workaround I type the author name by hand and then I use \citeyear(Knuth1984). Unfortunately, that way only years are clickable, not the author name.

The document structure is rather complicated, I use a .sty file for the thesis typesetting, so I'll provide at least relevant packages I've put into the preamble.

\documentclass[12pt,a4paper,oneside,final]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[czech]{babel}
\usepackage[round]{natbib}
\usepackage[Bc,Barevne]{sci.muni.thesis.uprava}
\begin{document}
Citation in parentheses is great \citep{Knuth1984}.
But we also love citation in text, said \citet{Knuth1984}!
\bibliography{biblio}
\end{document}

Desired result should look like this:

Citation in parentheses is great (KNUTH, 1984).

But we also love citation in text, said Knuth (1984)!

Also, the bibliography entry written after \bibliography{biblio} should have author last name in upper case with first names shortened to one letter. I managed to do that, but I think you should know for clarification. The bibliography entry:

KNUTH, D. 1984. The TeX book ...

The .bib file is formatted like so:

@book{Knuth1984,
    author = "Donald Knuth",
    title = "The \TeX book",
    ...
}

I can provide by .bst file, but I don't think that's necessary. Any ideas?

Thanks.

  • 2
    Welcome to TeX.SX! Probably the ,bst is not necessary, but a minimal example of a document is. – egreg May 7 '15 at 18:02
  • Edited. Also, everything works just fine, I'm just curious if it's possible to achieve desired results. – Rajcze May 7 '15 at 19:01
  • 1
    I guess that when you have two authors, you want “AUTHORONE and AUTHORTWO” in a parenthetical citation, with lowercase “and”. For this some changes to the .bst file are necessary. Maybe you already have something on this line. Can you add what you get in the .bbl file for a two author paper (and maybe also for three or more)? If you instead want “AUTHORONE AND AUTHORTWO” for two authors and “AUTHOR ET AL.” for more than two, I think I have a solution. – egreg May 7 '15 at 23:21
  • That could probably best be done changing the definition of bbl.and and other related functions inside the .bst file, but keeping the AUTHORONE and AUTHORTWO or AUTHORONE et al. behaviour is intended in my case. What I aim for is the possibility to produce citations with uppercase author name for one command and capitalized for another one. – Rajcze May 7 '15 at 23:40
1

Both macros \citep and \citet internally use \NAT@citetp, but when the first is used, \ifNAT@swa is set to true, whereas the second sets it to false. Then it's just a matter of changing the definition of \NAT@nmfmt so that it uses \MakeUppercase in the case of \citep.

\begin{filecontents*}{\jobname.bib}
@book{Knuth1984,
  author = {Donald E. Knuth},
  title = {The {\TeX}book},
  publisher = {Addison-Wesley},
  year = 1984,    
}
@book{multi,
  author = {A. Uthor and W. Riter},
  title = {A book},
  publisher = {Some},
  year = 1984,    
}
@book{multi2,
  author = {A. Uthor and W. Riter and S. C. I. Entist},
  title = {Another book},
  publisher = {Some},
  year = 1984,    
}
\end{filecontents*}

\documentclass{article}
\usepackage[round]{natbib}

\makeatletter
\renewcommand{\NAT@nmfmt}[1]{%
  \ifNAT@swa\expandafter\MakeUppercase\else\expandafter\@firstofone\fi{{\NAT@up #1}}%
}
\makeatother

\begin{document}

Citation in parentheses is great \citep{Knuth1984}.
But we also love citation in text, said \citet{Knuth1984}!

Let's see multiauthor: \citep{multi} or \citet{multi}.

Let's see multiauthor: \citep{multi2} or \citet{multi2}

\bibliographystyle{plainnat}
\bibliography{\jobname}

\end{document}

enter image description here

This also capitalizes “AND” and “ET AL.”. If this is not desired, the .bst file must be changed so that it outputs something like

\begin{thebibliography}{3}
\providecommand{\natexlab}[1]{#1}
\providecommand{\url}[1]{\texttt{#1}}
\expandafter\ifx\csname urlstyle\endcsname\relax
  \providecommand{\doi}[1]{doi: #1}\else
  \providecommand{\doi}{doi: \begingroup \urlstyle{rm}\Url}\fi

\bibitem[Knuth(1984)]{Knuth1984}
Donald~E. Knuth.
\newblock \emph{The {\TeX}book}.
\newblock Addison-Wesley, 1984.

\bibitem[Uthor \NATand{} Riter(1984)]{multi}
A.~Uthor and W.~Riter.
\newblock \emph{A book}.
\newblock Some, 1984.

\bibitem[Uthor \NATetal{}(1984)Uthor, Riter, and Entist]{multi2}
A.~Uthor, W.~Riter, and S.~C.~I. Entist.
\newblock \emph{Another book}.
\newblock Some, 1984.

\end{thebibliography}

with \NATand{} and \NATetal{} instead of the hardwired and and et al.. The LaTeX code above should be supplemented by

\DeclareRobustCommand{\NATand}{and}
\DeclareRobustCommand{\NATetal}{et~al.}
  • Redefining the \NAT@nmfmt worked great! I'll probably try tinkering with "and" and "et al." as you mentioned, but it is not critical and the citations are basically 99 % the way I wanted them. So thank you very much, you were very helpful. – Rajcze May 8 '15 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.