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 would like to know, what's the first character of the value of the editor field. If the character is a curly bracket "{" the value should be printed for example bold, if the first character is something else the fields value should be printed \textnormal.

I've tried to do that with the package xstring and the following code in a biblatex declaration:

\IfBeginWith{editor}{\{}{\textbf{\printfield{editor}}}{\printfield{editor}}

But this will not modify anything. How to do that right?

share|improve this question
    
biblatex can do many different tests. Maybe any of those can be used to answer this question? –  N.N. Jun 13 '11 at 10:25
    
I've had taken a look to these tests, but didn't found the right one. Do you have an idea? –  MaKa TaBo Jun 13 '11 at 11:17

1 Answer 1

up vote 4 down vote accepted

Looks like you should read up on data types in biblatex; editor is of the type name list, not field. Some details on how you can access data in a name list are described in the documentation on \DeclareNameFormat. You're on the right track in using xstring, but more care is required in passing arguments.

The code below will print out any corporate editor (i.e. any editor name enclosed in braces - see section 2.3.3 of the biblatex manual, version 1.4b) in boldface. I've applied edits to the generic biblatex format and macro definitions, but depending on the style you are using this solution will probably need to be adapted.

\documentclass{article}
\usepackage[style=authoryear]{biblatex}
\usepackage{xstring}
\usepackage{filecontents}

\DeclareNameFormat{byeditor}{%  Based on first-last format from biblatex.def
  \iffirstinits
    {\usebibmacro{ename:first-last}{#1}{#4}{#5}{#7}}
    {\usebibmacro{ename:first-last}{#1}{#3}{#5}{#7}}%
  \usebibmacro{name:andothers}}

\newbibmacro*{ename:first-last}[4]{%  Basd on name:first-last macro from biblatex.def
    \usebibmacro{name:delim}{#2#3#1}%
    \usebibmacro{name:hook}{#2#3#1}%
    \ifblank{#2}{}{\mkbibnamefirst{#2}\isdot\bibnamedelimd}%
    \ifblank{#3}{}{%
        \mkbibnameprefix{#3}\isdot
        \ifpunctmark{'}
            {}
            {\ifuseprefix{\bibnamedelimc}{\bibnamedelimd}}}%
    \noexpandarg\StrRemoveBraces{#1}[\mycsnb]%
    \noexpandarg\StrFindGroup{#1}{1}[\mycsfg]%
    \ifblank{#2#3#4}
        {\ifdefstring{\mycsnb}{#1}
            {\mkbibnamelast{#1}}
            {\ifdefstring{\mycsfg}{#1}{\mkbibbold{#1}}{\mkbibnamelast{#1}}}}
        {\mkbibnamelast{#1}}\isdot
    \ifblank{#4}{}{\bibnamedelimd\mkbibnameaffix{#4}\isdot}}

\begin{filecontents}{\jobname.bib}
@Book{companion,
    author = {Goossens, Michel and Mittelbach, Frank and Samarin, Alexander},
    title = {The LaTeX Companion},
    edition = {1},
    editor = {{Corporate Editor} and {A}ristotle and \texttt{HAL}},
    publisher = {Addison-Wesley},
    location = {Reading, Mass.},
    date = {1994}}
@Article{gillies,
    author = {Gillies, Alexander and {Corporate Author}},
    title = {Herder and the Preparation. Goethe's Idea of World Literature},
    journaltitle = {Publications of the English Goethe Society},
    volume = {9},
    date = {1933},
    editor = {Lastname, Firstname and {Corporate Editor} and {Corporation}},
    pages = {46--67}}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

enter image description here

Some notes on the code:

  • The corporate name gets passed to the last name argument (#1 throughout). All other name arguments (e.g. first names, name prefixes, etc.) are empty/blank.
  • Enclosure in braces prevents xstring from doing any straightforward string comparisons. I've instead detected corporate names using some other commands from xstring.
  • \ifdefstring tests if a control sequence is equal to a string. This test is from the etoolbox package, which is loaded by biblatex.
share|improve this answer
    
Wow! Thats much more complicated than I thought before! Thanks for your effort :-) –  MaKa TaBo Jun 15 '11 at 6:26
    
@Matthias If you compare my code with the definitions in biblatex.def, you'll see that I've only added a few lines. But yes, pattern matching isn't easy. –  Audrey Jun 15 '11 at 13:05

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.