Problem
I'm creating a custom biblatex style, and wanted to have a support for bibstrings similar to what the month
field has on the common implementations. That is, if I put something in brackets, {something}
, then the content, something
, is rendered in the field. But if I have something without brackets it is interpreted as a bibstring and converted to its definition.
I can partially achive that by checking if the content of the field is a bibstring, through \ifbibstring
(and friends). However, that only works if the content is always within brackets. If it isn't biber gives and error and does not passes the field for further processing.
For example, the code below generates the warning message
WARN - BibTeX subsystem: /tmp/M3YJZ8wGD7/mwe.bib_28410.utf8, line 21, warning: undefined macro "mytitle"
and that makes biber to not create that field into the .bbl
file. I found a similar error on biblatex/biber: using strings macros from one file in multiple refsections, but that doesn't address my problem.
MWE
This is my minimal implementation to demonstrate my problem.
% !BIB program = biber
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@test{test1,
title = {A},
year = {1995},
}
@test{test2,
title = {B},
year = {1994},
}
@test{test3,
title = {mytitle},
year = {1998},
}
@test{test4,
title = mytitle,
year = {1998},
}
\end{filecontents}
\begin{filecontents}{test.dbx}
\DeclareDatamodelFields[type=field, datatype=literal]{title}
\DeclareDatamodelFields[type=field, datatype=datepart]{year}
\DeclareDatamodelEntryfields[test]{%
year,%
title%
}
\end{filecontents}
\begin{filecontents}{english-test.lbx}
\InheritBibliographyExtras{english}
% Bibliography strings
\NewBibliographyString{mytitle}
\DeclareBibliographyStrings{%
inherit = {american},
mytitle = {{my title}{my title}},
}
\end{filecontents}
\begin{filecontents}{test.bbx}
\RequireBibliographyStyle{standard}
% map language
\DeclareLanguageMapping{english}{english-test}
% Dummy driver for testing
\DeclareBibliographyDriver{test}{%
\usebibmacro{begentry}%
\printfield{title}%
\newunit%
\printfield{year}%
\newunit%
\usebibmacro{finentry}%
}
\DeclareFieldFormat[test]{title}{%
\ifbibstring{#1}{\bibstring{#1}}{#1}%
}
\end{filecontents}
\usepackage[backend=biber, bibstyle=test]{biblatex}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}
Current output:
Expected output:
Question
Note that I'm expecting the same behavior with the bibstrings like month
. If I have the field without the brackets, the case of test4
entry in .bib
, that should be converted using the definition of the bibstring. But if I have the same definition with brackets, like in test3
, the content should be printed instead.
How can I achieve that with a custom style?
@string
' (the former is defined in a.bst
, the latter in the.bib
). So your plan goes wrong at the parsing stage ifmytitle
is not a@string
.biblatex
check if the bibstring exists? (I.e. use yourtest3
approach?) That is what manybiblatex
fields do that accept keywords and literal text. - Maybe I should better ask: What is it about the brace-less approach you need? Are you very likely to end up in a situation where you have the same field contents once with braces and once without..lbx
into a.bst
automatically?.lbx
s into a.bst
. That wouldn't help much here.biblatex
only uses one central.bst
that should not be modified (in theory it could be, but we really shouldn't), so that approach is out. Instead of using your.lbx
file you could of course define a new.bib
with@string
entries and load that as well, then you could use the brace-less approach.@string
definitions extensively and they work just the same with Biblatex as they did with BibTeX.