Highlight one specific author when generating references in Pandoc
Asked Answered
N

1

1

I am using Pandoc to generate a list of publications for my website. I'm using it solely to generate the html with the publications so that I can then paste the raw html in jekyll. This part works fine.

The complications arise when I tty to generate the html so that my name appears boldfaced in all entries. I'm trying to use this solution for that, which works when I apply it to a pure Latex document I am generating. However when I try to apply the same Pandoc, the html is generated without any boldface.

Here's my Pandoc file:

---
bibliography: /home/tomas/Dropbox/cv/makerefen4/selectedpubs.bib
nocite: '@'
linestretch: 1.5
fontsize: 12pt
header-includes: |
    \usepackage[
    backend=biber,
    dashed=false,
    style=authoryear-icomp,
    natbib=true,
    url=false,
    doi=true,
    eprint=false,
    sorting=ydnt, %Year (Descending) Name Title
    maxbibnames=99
    ]{biblatex}
    \renewcommand{\mkbibnamegiven}[1]{%
      \ifitemannotation{highlight}
        {\textbf{#1}}
        {#1}}
    \renewcommand*{\mkbibnamefamily}[1]{%
      \ifitemannotation{highlight}
        {\textbf{#1}}
        {#1}}
...

And here's the relevant part of my Makefile:

PANDOC_OPTIONS=--columns=80    
PANDOC_HTML_OPTIONS=--filter=pandoc-citeproc --csl=els-modified.csl --biblatex

Again: this code generates the references fine. It just doesn't boldface anything as it is supposed to.

Any ideas?

EDIT

Bib entries look like this

@MISC{test,
  AUTHOR    = {Last1, First1 and Last2, First2 and Last3, First3},
  AUTHOR+an = {2=highlight},
}

And versions are - Biblatex 3.12 - Biber 2.12

Nodose answered 3/7, 2019 at 15:34 Comment(6)
which version of biber and biblatex do you use?Tolbert
and how does the corresponding bib entry look like?Tolbert
@samcarter Editted the question: 3.12 and 2.12.Nodose
This looks good. Is it possible to intercept the .tex file which is created during compilation of your document?Tolbert
@samcarter I'm not very familiar with Pandoc so I don't know. I've looked it up and couldn't find anything that would allow me to do that... if you know of something please let me knowNodose
The LaTeX in header-includes is not going to help you when you're generating HTML with pandoc, since that doesn't involve LaTeX at all. You should put the equivalent CSS (or JavaScript) in there..Radiography
V
2

You can use a lua filter to modify the AST. The following works for me to get the surname and initials (Smith, J.) highlighted in the references (see here). You can replace pandoc.Strong with pandoc.Underline or pandoc.Emph. Replace Smith and J. with your name/initials, save it as myname.lua and use something like:

pandoc --citeproc --bibliography=mybib.bib --csl.mycsl.csl --lua-filter=myname.lua -o refs.html refs.md 

i.e. put the filter last.

local highlight_author_filter = {
  Para = function(el)
    if el.t == "Para" then
    for k,_ in ipairs(el.content) do
      if el.content[k].t == "Str" and el.content[k].text == "Smith,"
      and el.content[k+1].t == "Space"
      and el.content[k+2].t == "Str" and el.content[k+2].text:find("^J.") then
          local _,e = el.content[k+2].text:find("^J.")
          local rest = el.content[k+2].text:sub(e+1) 
          el.content[k] = pandoc.Strong { pandoc.Str("Smith, J.") }
          el.content[k+1] = pandoc.Str(rest)
          table.remove(el.content, k+2) 
      end
    end
  end
  return el
  end
}

function Div (div)
  if 'refs' == div.identifier then
    return pandoc.walk_block(div, highlight_author_filter)
  end
  return nil
end

Notes:

  1. The above works if you use an author-date format csl. If you want to use a numeric format csl (e.g. ieee.csl or nature.csl) you will need to substitute Span for Para in the filter, i.e.:
  Span = function(el)
    if el.t == "Span" then
  1. If you also want to use the multiple-bibliographies lua filter, it should go before the author highlight filter. And 'refs' should be 'refs_biblio1' or 'refs_biblio2' etc, depending on how you have defined them:
function Div (div)
  if 'refs' or 'refs_biblio1’ or 'refs_biblio2’ == div.identifier then

For pdf output, you will also need to add -V csl-refs in the pandoc command if you use a numeric format csl.

  1. The filter highlights Smith, J. if formated in this order by the csl. Some csl will use this format for the first author and then switch to J. Smith for the rest, so you will have to adjust the filter accordingly adding an extra if el.content[k].t == "Str”…etc. Converting to .json first will help to check the correct formatting in the AST.
Vondavonni answered 6/2, 2021 at 9:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.