Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I need to take the first string (considering First~Second a single string) from the title field from anonym entries and:

  1. Format this first string differently from the rest of the title, e.g.:

    LES MILLES et un nuit trans. by M. Galland. Paris: Compaigne des Libraires, 1745.

    THE BOOK of the thousand nights and a night trans. and annot. by Richard F. Burton. London: Burton Club, 1885.

  2. Use that string as a citation label, e.g.

    LES MILLES..., 1745; THE BOOK..., 1885

So, the style file needs to check for author and editor names and, in their absence, reformat the first word of the title to uppercase, as well as use it as a label for quotations.

My attempt

This is what I've tried so far.

I tried to achieve this result through the use of xstring with something like:

\newbibmacro{author+title}{%
    \ifnameundef{author}%
        {\ifnameundef{editor}%
        {%
          \StrCut[1]{\thefield{title}}{ }\StringA\StringB%
          \SpecialTitleFormat{\StringA}\space\StringB%
          \setunit\newblock
        }%
        {\usebibmacro{editor}
            \setunit{\labelnamepunct}\newblock
            \usebibmacro{title}}}%
        {\usebibmacro{author}%
          \setunit{\labelnamepunct}\newblock%
          \usebibmacro{title}}

And I tried to remap this string to the shorttitle field via biber's \DeclareSourcemap functionality

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \step[fieldsource=title,
            fieldset=shorttitle,
            match=\regexp{(\w+).*},
            fieldvalue={$1}]
    }
  }
}
\renewbibmacro*{labeltitle}{%
  \iffieldundef{label}
    {\iffieldundef{shorttitle}
       {\printfield{title}%
        \clearfield{title}}
       {\printfield[shorttitle]{shorttitle}}}
    {\printfield{label}}}

The problem with this approach is that the citation label and the emphasis in the bibliography are taken from the field through different means, what makes it inconsistent, e.g. the ~ works for the bibliography part, but not for the label.

Here's a MWE:

\documentclass{article}
\usepackage{filecontents}
% Bibliographic Database
\begin{filecontents*}{\jobname.bib}
@book{simple,
  title = {Simple anonym entry},
  publisher = {Publisher},
  year = {2013},
}
@book{1001nights,
  title = {The~Book of the thousand nights and a night},
  subtitle = {A plain and literal translation of the Arabian nights' entertainments},
  translator = {Richard F. Burton},
  annotator = {Richard F. Burton},
  location = {London},
  publisher = {Burton Club},
  year = {1885},
  }
@book{1001nuit,
  title = {Les~milles et un nuit},
  subtitle = {Contes Arabes},
  translator = {M. Galland},
  address = {Paris},
  publisher = {Compaigne des Libraires},
  year = {1745},
}
@book{editoranonym,
  title = {An anonym entry with an editor},
  editor = {Editor, Ed},
  publisher = {Publisher},
  year = {2000},
}
\end{filecontents*}
% Biblatex Style file
\begin{filecontents*}{\jobname.bbx}
\ProvidesFile{\jobname.bbx}

\RequireBibliographyStyle{standard}

% I'm redefining the book driver to use an author+title bibmacro
\DeclareBibliographyDriver{book}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author+title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \printfield{edition}%
  \newunit
  \iffieldundef{maintitle}
    {\printfield{volume}%
     \printfield{part}}
    {}%
  \newunit
  \printfield{volumes}%
  \newunit\newblock
  \usebibmacro{series+number}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{publisher+location+date}%
  \newunit\newblock
  \usebibmacro{chapter+pages}%
  \newunit
  \printfield{pagetotal}%
  \newunit\newblock
  \iftoggle{bbx:isbn}
    {\printfield{isbn}}
    {}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \usebibmacro{related}%
  \usebibmacro{finentry}}

\RequirePackage{xstring}
\DeclareRobustCommand{\SpecialTitleFormat}[1]{%
  \MakeUppercase{#1}}

% author+title bibmacro
% this should check for author and editor, and, in their absence, use
% the title field
\newbibmacro{author+title}{%
    \ifnameundef{author}%
        {\ifnameundef{editor}%
      {%
        \StrCut[1]{\thefield{title}}{ }\StringA\StringB%
        \SpecialTitleFormat{\StringA}\space\StringB%
        \setunit\newblock
      }%
      {\usebibmacro{editor}
            \setunit{\labelnamepunct}\newblock
            \usebibmacro{title}}}%
        {\usebibmacro{author}%
          \setunit{\labelnamepunct}\newblock%
          \usebibmacro{title}}
  }
\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \step[fieldsource=title,
                fieldset=shorttitle,
            match=\regexp{(\w+).*},
            fieldvalue={$1}]% 
          }
        }
      }

\renewbibmacro*{labeltitle}{%
  \iffieldundef{label}
    {\iffieldundef{shorttitle}
       {\printfield{title}%
        \clearfield{title}}
       {\printfield[shorttitle]{shorttitle}}}
    {\printfield{label}}}

\endinput
\end{filecontents*}

\usepackage[utf8]{inputenc}
\usepackage[bibstyle=\jobname,citestyle=verbose]{biblatex}
\addbibresource{\jobname.bib}
\usepackage{xstring}

\begin{document}

\thispagestyle{empty}

\citetitle{simple} \citetitle{1001nights} \citetitle{1001nuit} \citetitle{editoranonym}

\printbibliography

\end{document}

image

share|improve this question
    
Two Questions: 1) Does the user specify (with a character) the separator between the 1st and 2nd string parts, or does the program to be written need to do that? and 2) Is it reasonable to ask the user to place some sort of null identifier in the author and/or editor fields? To this 2nd question, you had indicated not, but if the user has to do something proactive for Q1, why not for Q2? Just asking, to help with strategies. –  Steven B. Segletes Mar 12 '13 at 0:25
    
@StevenB.Segletes, I wouldn't want to interfere with the user's database. I only added the ~ separator to keep it simple (I was thinking in something similar to what Audrey did). –  henrique Mar 12 '13 at 11:44
add comment

1 Answer

This problem might be better handled using a new formatting directive. Strings after which words in the title should be upper-cased can be identified using some language-specific lists and the hyphenation field.

Here's a rough demonstration of this idea using the authoryear style, which already uses labeltitle as a last-resort fallback for labelname. Note that localized upper-casing could be implemented using bibliography extras in the localization modules, but this approach would require wrapping both citations and bibliography in the otherlanguage environment given by the hyphenation field.

\documentclass{article}
\usepackage{csquotes}
\usepackage[american]{babel}
\usepackage[style=authoryear]{biblatex}

\forcsvlist{\listcsadd{bibprep:english}}{of,Of,the,The}
\csletcs{bibprep:american}{bibprep:english}
\csletcs{bibprep:british}{bibprep:english}
\forcsvlist{\listcsadd{bibprep:french}}{de,De,des,Des,le,Le,les,Les}

\DeclareFieldFormat{firstupper}{\MakeFirstUppercase{#1}}
\makeatletter
\newrobustcmd*{\MakeFirstUppercase}[1]{%
  \toggletrue{bbx@firstupper}%
  \expandafter\MakeFirstUppercase@i#1 &}
\def\MakeFirstUppercase@i#1 #2&{%
  \iftoggle{bbx@firstupper}
    {\MakeUppercase{#1}%
     \togglefalse{bbx@firstupper}%
     \def\do##1{\ifstrequal{#1}{##1}{\toggletrue{bbx@firstupper}\listbreak}{}}%
     \iffieldundef{hyphenation}
       {\dolistcsloop{bibprep:\bbl@main@language}}
       {\dolistcsloop{bibprep:\thefield{hyphenation}}}}
    {#1}
  \ifblank{#2}{}{\MakeFirstUppercase@i#2&}}
\newtoggle{bbx@firstupper}
\makeatother

% use new format to print labeltitle
\renewbibmacro*{labeltitle}{%
  \iffieldundef{label}
    {\iffieldundef{shorttitle}
       {\printfield[firstupper]{title}%
        \clearfield{title}}
       {\printfield[firstupper]{shorttitle}}}
    {\printfield{label}}}    
\renewbibmacro*{cite:label}{%
  \iffieldundef{label}
    {\printtext[bibhyperref]{\printfield[firstupper]{labeltitle}}}
    {\printtext[bibhyperref]{\printfield{label}}}}

% just for demonstration
\DeclareSourcemap{\maps[datatype=bibtex]{\map{\step[fieldset=label,null]}}}

\addbibresource{biblatex-examples.bib}
\begin{document}
\cite{companion,cms,moraux,kullback,britannica} \\
\citefield{companion,cms,moraux,britannica}[firstupper]{indexsorttitle} \\
\citefield{companion,cms,moraux,kullback,britannica}[firstupper]{title}
\printbibliography
\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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