I am currently working on writing some biblatex styles for
chemistry. These are at a very preliminary stage, but I have
run into a couple of issues. I'd appreciate any advice.
1) I'm trying to reproduce the usual way of presenting an
article printed in more than one language, and the xref
mechanism look interesting. A typical example would read:
K.\ Dehnicke and J.\ Str\"ahle, \emph{Angew.\ Chem.},
\textbf{1981}, \emph{93}, 451--464; \emph{Angew.\ Chem., Int.\
Ed.\ Engl.}, \textbf{1981}, \emph{20}, 413--426.
Notice that the authors are omitted from the repeated
reference. I've tried to set this up using two BibTeX database
entries and an xref, but it only works if both are included in
the bibliography. I was rather hoping that the sequence
latex - bibtex8 - latex - bibtex8 - latex
would include the necessary data, but this does not seem to be
the case. Is there any way to include both sets of references
in the .bbl, so that this works?
2) In standard BibTeX styles, you can do search-replace on the
database entries as part of creating the .bbl file. In my case,
I'm interested in checking journal titles for commas. Some
journals allow (or require) these, others forbid them. For
example:
J.\ Chem.\ Soc., Perkin Trans.\ 1 (RSC)
J.\ Chem.\ Soc. Perkin Trans.\ 1 (Wiley)
(The same applies to en- and em-dashes.) However, all of the
biblatex macros are \protected. Thus I can't \edef the field
contents and mess with it inside \DeclareFieldFormat. Am I
missing a search--replace system somewhere?
Thanks,
Joseph Wright
> I am currently working on writing some biblatex styles for
> chemistry. These are at a very preliminary stage, but I have
> run into a couple of issues. I'd appreciate any advice.
Another question, this time about the formatting of bibliography labels.
From the documentation, I see that I can do:
\renewcommand*{\bibleftbracket}{(}
\renewcommand*{\bibrightbracket}{)\midsentence}
to get parenthesis around the label used in citations and in the
bibliography, for example:
Other has said (1) ...
(1) A. N. Other, J. Irrep. Res., ...
However, I don't see how I get one style for the citation, and a second
one for the bibliography. I want to achieve, for example:
Other has said (1) ...
1. A. N. Other, J. Irrep. Res., ...
What have I missed?
Joseph Wright
Answering my own question, using:
\DeclareFieldFormat{labelnumberwidth}{\mkbibparens{#1}}
I can use \bibleftbracket/\bibrightbracket for the citation, and the
...paren macros in the bibliography.
Joseph Wright
> 1) I'm trying to reproduce the usual way of presenting an
> article printed in more than one language, and the xref
> mechanism look interesting. A typical example would read:
>
> K.\ Dehnicke and J.\ Str\"ahle, \emph{Angew.\ Chem.},
> \textbf{1981}, \emph{93}, 451--464; \emph{Angew.\ Chem., Int.\
> Ed.\ Engl.}, \textbf{1981}, \emph{20}, 413--426.
>
> Notice that the authors are omitted from the repeated
> reference. I've tried to set this up using two BibTeX database
> entries and an xref, but it only works if both are included in
> the bibliography. I was rather hoping that the sequence
>
> latex - bibtex8 - latex - bibtex8 - latex
>
> would include the necessary data, but this does not seem to be
> the case.
It is, but xref is responsive to 'mincrossrefs'. Try setting
mincrossrefs=1.
Note that BibTeX has no concept of a reference set. If you use two
independent entries you'll have to work around a few pitfalls. In
particular, biblatex.bst will assign (numeric or other) labels to
both entries and include both in the bibliography. You need a keyword
or category filter to suppress the translation in the bibliography
and you need to find a way to deal with the spurious label. If it's a
numeric style, you can easily get away with 'defernums'.
> 2) In standard BibTeX styles, you can do search-replace on the
> database entries as part of creating the .bbl file. In my case,
> I'm interested in checking journal titles for commas. Some
> journals allow (or require) these, others forbid them. For
> example:
>
> J.\ Chem.\ Soc., Perkin Trans.\ 1 (RSC)
> J.\ Chem.\ Soc. Perkin Trans.\ 1 (Wiley)
>
> (The same applies to en- and em-dashes.) However, all of the
> biblatex macros are \protected. Thus I can't \edef the field
> contents and mess with it inside \DeclareFieldFormat. Am I
> missing a search--replace system somewhere?
I'm not sure I understand your problem. Inside \DeclareFieldFormat, #1
are the literal field contents. It's no problem to do something like
\DeclareFieldFormat{title}{\checktitleformat{#1}}
and then create a \checktitleformat macro which does the editing. This
is how \mkpageprefix is integrated with the field format.
There currently is no way to edit the internal field data directly (on
data import) but you can copy the field contents to a macro and work
with that. E.g.:
\savefield*{title}{\bbx@thetitle}
or
\protected@edef\bbx@thetitle{\thefield{title}}
Then use
\printtext[title]{\bbx@thetitle}
instead of \printfield{title}.
--
Sender address blackholed; do not reply to From: address.
You can still reach me by email at: plehman gmx net.
> It is, but xref is responsive to 'mincrossrefs'. Try setting
> mincrossrefs=1.
>
> Note that BibTeX has no concept of a reference set. If you use two
> independent entries you'll have to work around a few pitfalls. In
> particular, biblatex.bst will assign (numeric or other) labels to
> both entries and include both in the bibliography. You need a
> keyword or category filter to suppress the translation in the
> bibliography and you need to find a way to deal with the spurious
> label. If it's a numeric style, you can easily get away with
> 'defernums'.
To clarify that some more: there is no way to export raw data from the
bib file (it's one of those restrictions imposed by BibTeX). If you
pull in the data of an entry, it always ends up in the bibliography
and it always gets a label. In other words, this:
@Article{key1,
xref = {key2}
...
}
is conceptually similar to
@Article{key1,
execute = {\nocite{key2}}
...
}
plus a 'mincrossrefs' check.
I thought biblatex used some kind of internal label, that had nothing
to do with what ended up being printed? (i.e. the cite key itself).
> If it's a
> numeric style, you can easily get away with 'defernums'.
I'll look at this. I realise it's a rather esoteric thing to want to
do!
> > 2) In standard BibTeX styles, you can do search-replace on the
> > database entries as part of creating the .bbl file. In my case,
> > I'm interested in checking journal titles for commas. Some
> > journals allow (or require) these, others forbid them. For
> > example:
>
> > J.\ Chem.\ Soc., Perkin Trans.\ 1 (RSC)
> > J.\ Chem.\ Soc. Perkin Trans.\ 1 (Wiley)
>
> > (The same applies to en- and em-dashes.) However, all of the
> > biblatex macros are \protected. Thus I can't \edef the field
> > contents and mess with it inside \DeclareFieldFormat. Am I
> > missing a search--replace system somewhere?
>
> I'm not sure I understand your problem. Inside \DeclareFieldFormat, #1
> are the literal field contents. It's no problem to do something like
>
> \DeclareFieldFormat{title}{\checktitleformat{#1}}
>
> and then create a \checktitleformat macro which does the editing. This
> is how \mkpageprefix is integrated with the field format.
This is broadly what I tried, for example:
\newcommand*{\bbx@killcomma}[1]{%
\begingroup
\toks@{}%
\bbx@kill@comma#1\@empty
\expandafter\endgroup
\the\toks@}
\def\bbx@kill@comma#1#2\@empty{%
\if,#1\relax\else
\toks@\expandafter{\the\toks@#1}%
\fi
\ifx\@empty#2\@empty\else
\bbx@kill@comma#2\@empty\@empty
\fi}
\DeclareFieldFormat[article]{journaltitle}{%
\emph{\bbx@killcomma{#1}}}
If I try this, I end up with a load of garbage info:
"ournaltitleournalsubtitle". So I tried:
\DeclareFieldFormat[article]{journaltitle}{%
\edef\@tempa{#1}\show\@tempa%
#1}
and get:
> \@tempa=macro:
-> \printfield [noformat]{journaltitle}\setunit
{\addcomma}\printfield [noformat]{journalsubtitle}
which I can't \edef into the actual text. I'm obviously being dim
here. I suspect this is caused by \usebibmacro{journal}, as this
looks like the contents of the macro. But I had (naively) assumed
that \DeclareFieldFormat worked toward the "end" of the printing
process.
Thanks,
Joseph Wright
>> Note that BibTeX has no concept of a reference set. If you use two
>> independent entries you'll have to work around a few pitfalls. In
>> particular, biblatex.bst will assign (numeric or other) labels to
>> both entries and include both in the bibliography.
>
> I thought biblatex used some kind of internal label, that had
> nothing to do with what ended up being printed? (i.e. the cite key
> itself).
Yes, it does. I'm talking about citation 'labels' (e.g., numeric
labels like '1' or things like the 'a' in 'Doe 1995a') which are
normally assigned as the data in the bib file is sorted (by
biblatex.bst). For example, if you have:
@article{doe1,
xref = {doe2}
author = {John Doe}
year = {1995}
}
@article{doe2,
author = {John Doe}
year = {1995}
}
@article{doe3,
author = {John Doe}
year = {1995}
}
and use a filter to exclude 'doe2' from the bibliography, the
references will look like this:
[1] John Doe...
[3] John Doe...
If you're using numeric labels, you can use 'defernums' to work around
that.
> I'll look at this. I realise it's a rather esoteric thing to want
> to do!
I don't think it's that esoteric but you're hitting on of BibTeX's
restrictions. What you're trying to implement is a special case of a
reference set. I'm told that this is very common in physics where
several entries may be listed under a single label in the
bibliography. With current BibTeX, it's not possible to implement
that in a truly clean and elegant way.
> \DeclareFieldFormat[article]{journaltitle}{%
> \edef\@tempa{#1}\show\@tempa%
> #1}
>
> and get:
>
>> \@tempa=macro:
> -> \printfield [noformat]{journaltitle}\setunit
> {\addcomma}\printfield [noformat]{journalsubtitle}
>
> which I can't \edef into the actual text. I'm obviously being dim
> here. I suspect this is caused by \usebibmacro{journal}, as this
> looks like the contents of the macro. But I had (naively) assumed
> that \DeclareFieldFormat worked toward the "end" of the printing
> process.
Ah, I see. Indeed, that's because titles are essentially handled like
this:
\printtext[title]{%
\printfield[noformat]{title}%
\setunit{\subtitlepunct}%
\printfield[noformat]{subtitle}}
(and so on for journaltitle etc.). So, what your format definition
sees is the argument passed to \printtext. You need to hook into the
whole thing on a different level. Try using a specialized format for
the editing, separating this step from the formatting:
\DeclareFieldFormat{killcomma}{\bbx@killcomma{#1}}
\DeclareFieldFormat{title}{\emph{#1}}
and then redefine the affected bibmacros like this:
\printtext[title]{%
\printfield[killcomma]{title}%
\setunit{\subtitlepunct}%
\printfield[killcomma]{subtitle}}
This should work and it has the additional benefit that you can
control both steps (editing and formatting) separately.
PS: Your \bbx@killcomma macro will also kill all spaces. You need to
parse the tokens with \futurelet. It's also a good idea to use tail
recursion in \bbx@kill@comma.
Chemistry does something similar with reference sets, hence my
involvement with Michael Shell's mciteplus package. I meant that most
people (who use author-date or similar) never go anywhere near this
sort of thing.
> \DeclareFieldFormat{killcomma}{\bbx@killcomma{#1}}
> \DeclareFieldFormat{title}{\emph{#1}}
>
> and then redefine the affected bibmacros like this:
>
> \printtext[title]{%
> \printfield[killcomma]{title}%
> \setunit{\subtitlepunct}%
> \printfield[killcomma]{subtitle}}
Great, works fine.
> PS: Your \bbx@killcomma macro will also kill all spaces. You need to
> parse the tokens with \futurelet. It's also a good idea to use tail
> recursion in \bbx@kill@comma.
Both true. I will need to work on my recursion routines!
Joseph Wright
>> PS: Your \bbx@killcomma macro will also kill all spaces. You need
>> to parse the tokens with \futurelet. It's also a good idea to use
>> tail recursion in \bbx@kill@comma.
>
> Both true. I will need to work on my recursion routines!
Here's a quick adaption of some code I wrote for a related task some
time ago. Has not been tested in-depth but could be helpful.
\documentclass{minimal}
\usepackage{etoolbox}% => \appto
\makeatletter
\def\bbx@killcomma#1{%
\begingroup
\let\@tempa\@empty
\bbx@kc@parse#1\bbx@kc@end}
\def\bbx@kc@parse{%
\futurelet\@let@token\bbx@kc@check}
\def\bbx@kc@check{%
\ifx\@let@token\bbx@kc@end
\expandafter\bbx@kc@end
\fi
\ifx\@let@token\@sptoken
\expandafter\bbx@kc@space
\fi
\ifx\@let@token,%
\expandafter\bbx@kc@comma
\fi
\ifx\@let@token\bgroup
\expandafter\bbx@kc@group
\fi
\bbx@kc@other
\relax}
\def\bbx@kc@space{\def\bbx@kc@space##1\relax}
\@nameuse{bbx@kc@space} {%
\appto\@tempa{ }%
\bbx@kc@parse}
\def\bbx@kc@comma#1\relax,{%
\bbx@kc@parse}
\def\bbx@kc@group#1\relax#2{%
\appto\@tempa{{#2}}%
\bbx@kc@parse}
\def\bbx@kc@other\relax#1{%
\appto\@tempa{#1}%
\bbx@kc@parse}
\def\bbx@kc@end#1\bbx@kc@end{%
\expandafter\endgroup\@tempa}
% for testing only
\def\killcomma{\bbx@killcomma}
\makeatother
\begin{document}
\killcomma{J. Chem. Soc. Perkin Trans. 1}\par
\killcomma{J. Chem. Soc., Perkin Trans. 1}\par
\killcomma{J.~Chem.~Soc. Perkin Trans.~1}\par
\killcomma{J.~Chem.~Soc., Perkin Trans.~1}\par
\killcomma{text text text}\par
\killcomma{text text, text}\par
\killcomma{text \emph{text} text}\par
\killcomma{text \emph{text}, text}\par
% protect commas by wrapping them in braces:
\killcomma{protected{,} protected}\par
\killcomma{{protected,} protected}\par
\end{document}
Philipp,
Thanks very much indeed for that. You will save me quite a lot of
time.
Joseph Wright