# Select (child)entrytype for DeclareLabelalphaTemplate in BibLaTeX

I want to cite an ISO Standard with BibLaTeX as proposed here.

However, as for the citation style alphabetic, the label of \cite{iso704} is "ISO00" and what I want is "ISO 704:2000". The style is fine for everything else, so I don't want to switch the whole style.

So I did the following:

\begin{filecontents}{iso.bib}
@Techreport{ISO704,
Title                    = {Terminology work - Principles and methods},
Author                   = {{ISO/TC 37}},
Date                     = {2000-11},
Institution              = {ISO International Organization for Standardization},
Number                   = {704},
Type                     = {ISO},

Comment                  = {Revised by ISO 704:2009, Revises ISO 704:1987},
Keywords                 = {Definitions, General section, Methods, Terminology},
}

\end{filecontents}
\documentclass{article}
\usepackage[style=alphabetic]{biblatex}

\DeclareLabelalphaTemplate[]{
\labelelement{\field[]{type}}
\labelelement{\literal{~}}
\labelelement{\field[]{number}}
\labelelement{\literal{:}}
\labelelement{
\field[strwidth=4,strside=right]{year}
}
}

\begin{document}
Actual Output: \cite{ISO704} %ISO00 - Expected Output: [ISO 704:2000]
\end{document}


My problem is, that I have to select the proper entrytype (techreport with subtype ISO) that goes into [], so that this does not affect all the other labels.

However, I wasn't able to find any solution on how to select the appropriate entrytype. In the BibLaTeX-Manual they refer to something like @techreport, but even that doesn't work for me.

That is a bit wicked, in biblatex using @techreport is just a fancy way of using the type @report together with setting the type field to techreporrt, which in your case is immediately overwritten by your type = {ISO} in the .bib.

Internally, a @techreport is thus a @report.

So all you need is

\DeclareLabelalphaTemplate[report]{
\labelelement{\field{type}}
\labelelement{\literal{~}}
\labelelement{\field{number}}
\labelelement{\literal{:}}
\labelelement{
\field[strwidth=4,strside=right]{year}
}
}


Maybe the biblatex documentation is not a hundred percent clear on that when on p. 12 it says

[@techreport is] [s]imilar to @report except that the type field is optional and defaults to the localized term ‘technical report’. You may still use the type field to override that.

You can, however, find a mapping in biblatex.def

\map{
\step[typesource=techreport, typetarget=report, final]
\step[fieldset=type,         fieldvalue=techreport]
}


that clearly shows that a @techreport is converted into a @report.

Since \DeclareLabelalphaTemplate can only distinguish by entry types, if you want something more elaborate, you need to go down a different path.

You can, for example, set the shorthand field automatically with the following code

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite]{
\pertype{techreport}
\step[fieldsource=type, match=\regexp{ISO}, final]
\step[fieldset=shorthand, fieldvalue={ISO\,}]
\step[fieldsource=number, final]
\step[fieldset=shorthand, origfieldval, append]
}
\map[overwrite]{
\pertype{techreport}
\step[fieldsource=type, match=\regexp{ISO}, final]
\step[fieldsource=year, match=\regexp{\A(.*)\Z}]
\step[fieldsource=date, match=\regexp{([0-9]{4}?)}]
\step[fieldset=shorthand, fieldvalue={:$1}, append] } } }  Due to the nature of this code though, shorthand fields of @techreports that have type = {ISO} will be overwritten with the desired format. In order to avoid this shortcoming we can use the slightly longer-winding \DeclareSourcemap{ \maps[datatype=bibtex]{ \map[overwrite]{ \pertype{techreport} \step[fieldsource=type, match=\regexp{ISO}, final] \step[fieldset=safeshorthand, fieldvalue={ISO\,}] \step[fieldsource=number, final] \step[fieldset=safeshorthand, origfieldval, append] } \map[overwrite]{ \pertype{techreport} \step[fieldsource=type, match=\regexp{ISO}, final] \step[fieldsource=year, match=\regexp{\A(.*)\Z}] \step[fieldsource=date, match=\regexp{([0-9]{4}?)}] \step[fieldset=safeshorthand, fieldvalue={:$1}, append]
}
\map{
\step[fieldsource=safeshorthand, final]
\step[fieldset=shorthand, origfieldval]
}
}
}


Here, we construct the desired label in a safeshorthand field and only copy that to the shorthand field, if the latter is empty.

• Thank you! "report" works as shown, but is there also an option to select report with fieldtype "ISO"? – BumbleBee Oct 9 '15 at 6:29
• @BumbleBee As far as I can see, one can only adjust the format by entry type, not by the contents of arbitrary fields. I do have another idea how we could get around this though, bear with me for a moment. – moewe Oct 9 '15 at 6:39
• @BumbleBee I came up with an alternative that doesn't use \DeclareLabelalphaTemplate, but \DeclareSourcemap on the shorthand field instead. I have now also removed one shortcoming of my first attempt with that idea. – moewe Oct 9 '15 at 7:27

Just to extend @moewe's answer: I subsequently had to add a German DIN norm as well. Therefore I extended the code like this:

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite]{
\pertype{techreport}
\step[fieldsource=type, match=\regexp{(ISO|DIN)}, final]
\step[fieldset=safeshorthand, origfieldval]
\step[fieldset=safeshorthand, fieldvalue={\,}, append]
}
\map[overwrite]{
\pertype{techreport}
\step[fieldsource=type, match=\regexp{(ISO|DIN)}, final]
\step[fieldsource=number, final]
\step[fieldset=safeshorthand, origfieldval, append]
}
\map[overwrite]{
\pertype{techreport}
\step[fieldsource=type, match=\regexp{(ISO|DIN)}, final]
\step[fieldsource=year, match=\regexp{\A(.*)\Z}]
\step[fieldsource=date, match=\regexp{([0-9]{4}?)}]
\step[fieldset=safeshorthand, fieldvalue={:$1}, append] } \map{ \step[fieldsource=safeshorthand, final] \step[fieldset=shorthand, origfieldval] } } }  A more general option would probably be to use the type Standard and use ISO 740 or DIN 2230 in the number field of the @report: \DeclareSourcemap{ \maps[datatype=bibtex]{ \map[overwrite]{ \pertype{techreport} \step[fieldsource=type, match=\regexp{Standard}, final] \step[fieldsource=number, final] \step[fieldset=safeshorthand, origfieldval, append] } \map[overwrite]{ \pertype{techreport} \step[fieldsource=type, match=\regexp{Standard}, final] \step[fieldsource=year, match=\regexp{\A(.*)\Z}] \step[fieldsource=date, match=\regexp{([0-9]{4}?)}] \step[fieldset=safeshorthand, fieldvalue={:$1}, append]
}
\map{
\step[fieldsource=safeshorthand, final]
\step[fieldset=shorthand, origfieldval]
}
}
}


This might not be perfect, since probably at some point one should define a new entrytype like @standard for handling standards in general. But it works out with citation managers like Jabref without the need to declare new entry types.

• You can make your first piece of code more concise by moving the \step[fieldsource=number, final] \step[fieldset=shorthand, origfieldval, append] bit to its own mapping just like the date stuff. But please be aware that this solution will overwrite existing shorthands for @techreports with the right type, this can be avoided as explained in my answer above just at the end. – moewe Oct 9 '15 at 9:02
• I adjusted the code according to your comments. This works now for both approaches. – BumbleBee Oct 9 '15 at 9:53
• If you want to, you can make your code even more compact by combining the first to \map directives in the first piece of code into one: \map[overwrite]{ \pertype{techreport} \step[fieldsource=type, match=\regexp{(ISO|DIN)}, final] \step[fieldset=shorthand, fieldvalue={$1\,}] } – moewe Oct 9 '15 at 9:59 • I reduced this code as you proposed, but it didn't work with the $1. Suppose I don't fully understand that right now. Nonetheless, it works as above. However, for other users the more generic solution with the Standard-type might be more appropriate either way. – BumbleBee Oct 9 '15 at 10:33