Make just part of titles uppercase with biblatex

I'm trying to make a biblatex replacement to the abntex2cite bibtex package (a package for brazilian norms), and one of the requirements is that, in the absence of an author, the title should be used as a key with the first word in uppercase (or the first few words if the first word is an article or if it's too short).

I've played around a bit and managed to get the whole title in uppercase in those cases, but I don't know how to do that for just the first word (or the first few words when necessary).

Here's a minimal working example:

\begin{filecontents}{\jobname.bib}
@article{theeffect,
title = {The Effect of Country Music on Suicide},
%author = {Steven Stack and Jim Gundlach},
journaltitle = {Social Forces},
volume = {71},
number = {1},
pages = {211-218},
year = {1992},
month = {9}}
\end{filecontents}

\documentclass{article}

\usepackage[backend=biber, bibstyle=standard, citestyle=authoryear]{biblatex}

\DeclareFieldFormat[article]{title}{#1\isdot}
\DeclareFieldFormat{uppercase}{\MakeUppercase{#1}}

\renewbibmacro*{cite:label}{%
\iffieldundef{label}
{\printtext[bibhyperref]{\printfield[uppercase]{labeltitle}}}
{\printtext[bibhyperref]{\printfield{label}}}}

\renewbibmacro*{title}{%
\ifboolexpr{
test {\iffieldundef{title}}
and
test {\iffieldundef{subtitle}}
}
{}
{\printtext[title]{%
\ifnameundef{author}{
\printfield[uppercase]{title}}
{\printfield[titlecase]{title}}
\setunit{\subtitlepunct}%
\printfield[titlecase]{subtitle}}%
\newunit}%

\begin{document}
The greater the airtime devoted to country music, the greater the white suicide rate.'' \cite{theeffect}
\printbibliography
\end{document}


This prints the title in both the citation and the bibliography entry as "THE EFFECT OF COUNTRY MUSIC ON SUICIDE", while what I need is just "THE EFFECT" for the citation and "THE EFFECT of country music on suicide" for the bibliography.

I think there might be some special biblatex fields (label?, shorttitle?, shorthand?) I could use for that… that would already be great if I can get these results. But it would be even better if there were a way to do that without using any special fields, so people who already use abntex2cite don't have to change all their entries when moving to biblatex.

PS: I have no idea what I'm doing, so if there's a better way of doing any of the stuff in that code, please let me know.

• I think you will have to resort to a manual way to tell bibilatex which part of the title ought to be capitalised. The first few words, if the first word alone is too short is no hard rule that we could implement. You can use shorttitle = {THE EFFECT} and title = {THE EFFECT of country music on suicide rates}. – moewe Apr 26 '16 at 5:28
• @moewe Thanks for the answer. How about just the first word, is there no way to do that either? It would already save a lot of work, then people would have to fix just the exceptions. – dbmrq Apr 26 '16 at 5:58

Your core problem is to uppercase only a part of a list of words. That's not so difficult (perhaps one needs to make the command robust for the bibliography).

\documentclass{article}

\makeatletter
\newcommand\FirstWordUpper[1]{\@firstwordupper#1 \@nil}
\newcommand\@firstwordupper{}
\def\@firstwordupper#1 #2\@nil{\MakeUppercase{#1} #2\unskip}
\makeatother

\begin{document}
\FirstWordUpper{test word test}!

\FirstWordUpper{test\space word test}!

\FirstWordUpper{{test word} test}!

\FirstWordUpper{test. test test}!

\FirstWordUpper{}!

\FirstWordUpper{test}!

\FirstWordUpper{$\alpha$-test xxx}  blblb
\end{document}


The second part is the "first few words" requirement. You could implemement it by measuring the width of #1 and loop if it is too small. Or as in the examples you could simply protect the space you want to ignore.

• Awesome, thank you so much! That \FirstWordUpper command was perfect. I'm still trying to figure out that last part, but it looks promising, thanks for pointing me in the right way. :) – dbmrq Apr 27 '16 at 0:40