Update 2: (with more help from ConTeXt mailing list)
Based on this response from thread.
In order to take advantage of built-in methods for both author splitting and author conversion, the best approach is to redefine the author conversion function. So if the normalshort
conversion is to be used, define it to include a conditional entry of a bold term:
\startsetups btx:list:author:normalshort
\fastsetup{btx:list:author:concat}
\begingroup
%%% New snippet
\ctxluacode{document.BoldNames("\currentbtxdataset","\currentbtxtag",\number\currentbtxauthorindex)}
%%%
\ifx\currentbtxinitials\empty \else
\currentbtxinitials
\btxparameter{separator:initials}
\fi
\ifx\currentbtxvons\empty \else
\currentbtxvons
\ifx\currentbtxsurnames\empty \else
\btxparameter{separator:vons}
\fi
\fi
\ifx\currentbtxsurnames\empty \else
\currentbtxsurnames
\ifx\currentbtxjuniors\empty \else
\btxparameter{separator:juniors}
\currentbtxjuniors
\fi
\fi
\endgroup
\fastsetup{btx:list:author:others}
\stopsetups
Other author coversion definitions can be found publ-imp-author.mkiv source code.
The following example defines the document.BoldNames
function to allow selection of multiple names (although it might need some tweaking for more complex names):
\startbuffer[ref]
@article{solo,
author = {MyLast, MyFirst},
title = {Solo work},
journal = {Journal},
year = {2000},
month = {1},
volume = {1}
}
@article{co,
author = {OtherLast, OtherFirst and MyLast, MyFirst and CoLast, CoFirst},
title = {Joint work},
journal = {Journal},
month = {1},
year = {2000},
volume = {1}
}
\stopbuffer
\usebtxdataset[ref][ref.buffer]
\setupbtx[dataset=ref]
\definebtxrendering[ref][dataset=ref]
\setupbtx[default:cite]
[alternative=authoryear,
etallimit=1,
authorconversion=normalshort]
\startluacode
local BoldNames = {
{firstnames = "MyFirst",
surnames = "MyLast"},
{initials = "C",
surnames = "CoLast"},
}
function document.CompareNames(reference, targets)
-- Loop over targets
for _, target in pairs(targets) do
-- Loop over fields
for key, value in pairs(target) do
if reference[key] == nil then
break
end
local full_entry = ''
for _, part in ipairs(reference[key]) do
full_entry = full_entry .. ' ' .. part
end
full_entry = string.sub(full_entry, 2)
if full_entry == value then
return(true)
end
end
end
return(false)
end
function document.BoldNames(set, tag, aut)
local c = publications.getcasted(set, tag, "author")
if document.CompareNames(c[aut], BoldNames) then
context("\\bf")
end
end
\stopluacode
\startsetups btx:list:author:normalshort
\fastsetup{btx:list:author:concat}
\begingroup
\ctxluacode{document.BoldNames("\currentbtxdataset","\currentbtxtag",\number\currentbtxauthorindex)}
\ifx\currentbtxinitials\empty \else
\currentbtxinitials
\btxparameter{separator:initials}
\fi
\ifx\currentbtxvons\empty \else
\currentbtxvons
\ifx\currentbtxsurnames\empty \else
\btxparameter{separator:vons}
\fi
\fi
\ifx\currentbtxsurnames\empty \else
\currentbtxsurnames
\ifx\currentbtxjuniors\empty \else
\btxparameter{separator:juniors}
\currentbtxjuniors
\fi
\fi
\endgroup
\fastsetup{btx:list:author:others}
\stopsetups
\starttext
Citations: \cite[solo] \cite[co]
\startsubject[title=Bibliography]
\placelistofpublications[ref][method=dataset]
\stopsection
\stoptext
The result:
Update: (with help from ConTeXt mailing list)
Based on this response from thread.
Using publications.getcasted()
function, it's possible to get formatted names without having to do custom splitting. However, it's still necessary to define a format for name output. The following code uses a simple example format of Lastname Initial., (which might fail for more complex names):
\startbuffer[ref]
@article{solo,
author = {MyLast, MyFirst},
title = {Solo work},
journal = {Journal},
year = {2000},
month = {1},
volume = {1}
}
@article{co,
author = {MyLast, MyFirst and CoLast, CoFirst},
title = {Joint work},
journal = {Journal},
month = {1},
year = {2000},
volume = {1}
}
\stopbuffer
\usebtxdataset[ref][ref.buffer]
\setupbtx[dataset=ref]
\definebtxrendering[ref][dataset=ref]
\setupbtx[default:cite]
[alternative=authoryear,
etallimit=1]
\startluacode
-- Define target name
local target = { ['firstnames'] = 'MyFirst',
[ 'surnames' ] = 'MyLast'}
function document.boldauthor(set,tag)
c = publications.getcasted(set, tag, 'author')
for i = 1,#c do
local add_name = function() context.sprint(c[i].surnames[1] .. ' ' .. c[i].initials[1]) end
if (c[i].surnames[1] == target.surnames) and (c[i].firstnames[1] == target.firstnames) then
context.bold( add_name )
context.sprint('., ')
else
add_name()
context.sprint('., ')
end
end
end
\stopluacode
\starttexdefinition btx:customauthor
\ctxluacode{document.boldauthor("\currentbtxdataset","\currentbtxtag")}
\stoptexdefinition
\startsetups btx:default:list:article
\texdefinition{btx:customauthor}
\texdefinition{btx:default:title}
\texdefinition{btx:default:journal}
\texdefinition{btx:default:year}
\removeunwantedspaces
\removepunctuation
\btxperiod
\stopsetups
\starttext
Citations: \cite[solo] \cite[co]
\startsubject[title=Bibliography]
\placelistofpublications[ref][method=dataset]
\stopsection
\stoptext
The result:
Old answer:
I have found a way to subvert the problem by defining a new entry key myauthor
as a copy of author
(to avoid influencing citations) and then using \btxdirect
rather than btxflush
. However, this copy is generated before any formatting, meaning that the approach would require manual name splitting and formatting (to generate initials and the like), which isn't very general.
\startbuffer[ref]
@article{solo,
author = {MyLast, MyFirst},
title = {Solo work},
journal = {Journal},
year = {2000},
month = {1},
volume = {1}
}
@article{co,
author = {MyLast, MyFirst and CoLast, CoFirst},
title = {Joint work},
journal = {Journal},
month = {1},
year = {2000},
volume = {1}
}
\stopbuffer
\usebtxdataset[ref][ref.buffer]
\setupbtx[dataset=ref]
\definebtxrendering[ref][dataset=ref]
\setupbtx[default:cite]
[alternative=authoryear,
etallimit=1]
\startluacode
local dataset = publications.datasets.ref
for tag, entry in pairs(dataset.luadata) do
-- Do complex formatting in lua... the following is a placeholder
dataset.luadata[tag].myauthor = '{\\bf ' .. entry.author ..' }'
end
\stopluacode
\starttexdefinition btx:test
\btxdirect{myauthor}
\stoptexdefinition
\startsetups btx:default:list:article
\texdefinition{btx:test}
\texdefinition{btx:default:title}
\texdefinition{btx:default:journal}
\texdefinition{btx:default:year}
\removeunwantedspaces
\removepunctuation
\btxperiod
\stopsetups
\starttext
Citations: \cite[solo], \cite[co]
\startsubject[title=Bibliography]
\placelistofpublications[ref][method=dataset]
\stopsection
\stoptext