On 7/23/2018 6:42 PM, Stanislav Sokolenko wrote:
Dear list,
I'm struggling to output bibliography entries into lua for string
modification (like making a particular author name bold). In effect, I
just need something like the following:
\starttexdefinition btx:customauthor
\startluacode
local text = context.btxflush('author')
-- tex.sprint(text) -- fails because text remains nil
\stopluacode
\stoptexdefinition
It's clear that btxflux is the wrong function for this as it writes the
contents to file rather than returning a variable in lua... Is there a
way to directly access what btxflush is writing through the publications
table or other means? I've gone over the source code but I can't
decipher what btxflush is actually doing.
This is not for the fainthearted so here we go
\startluacode
function document.MyBoldPub(set,tag)
-- local a = publications.getfield(set,tag,"author")
-- inspect(a)
-- local c = publications.getcasted(set,tag,"author")
-- inspect(c)
if c[1].surnames[1] == "Myname" then
context.bold(function()
context.btxflush('author')
end )
else
context.btxflush('author')
end
end
\stopluacode
\starttexdefinition btx:customauthor
\ctxluacode{document.MyBoldPub("\currentbtxdataset","\currentbtxtag")}
\stoptexdefinition
try to avoid tex.print cum suis, use the proper context.* interface instead
Thanks,
Stan
Longer MNWE:
\stopluacode
\startbuffer[ref]
@article{solo,
author = {Lastname, Firstname},
title = {Solo work},
journal = {Journal},
year = {2000},
month = {1},
volume = {1}
}
\stopbuffer
\usebtxdataset[ref][ref.buffer]
\setupbtx[dataset=ref]
\definebtxrendering[ref][dataset=ref]
\setupbtx[default:cite]
[alternative=authoryear,
etallimit=1]
\starttexdefinition btx:customauthor
\startluacode
local text = context.btxflush('author')
-- tex.sprint(text) -- text remains nill
\stopluacode
\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]
\startsubject[title=Bibliography]
\placelistofpublications[ref][method=dataset]
\stopsection
\stoptext
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry
to the Wiki!
maillist : ntg-context@ntg.nl /
http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
--
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the
Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________