4

A relatively common requirement in academic grants is to provide a bibliography where your name or your students' names are formatted differently than other author names (such as put in bold text or underlined). Is there a way to do this automatically in ConTeXt?

Not sure if it's helpful or not, but I've previously used the following answer in biblatex.

I've read through the bibliographies manual and I feel like the following should work with some small changes by passing the author field into lua (and doing some text processing there):

\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] 

\define[1]\formatname{
  % Placeholder formatting
  \ctxlua{tex.sprint('{\\bf ' .. '#1' .. '}')}
}

\starttexdefinition btx:test
   \formatname{\btxflush{author}}
\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

But the \btxflush command doesn't get resolved and lua doesn't see the author field after the initials have been generated. I've tried different variations of expansion, but I'm still hazy about how that works.

The result:

enter image description here

1 Answer 1

4
+50

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:

enter image description here

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:

enter image description here

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .