【问题标题】:Highlight one specific author when generating references in Pandoc在 Pandoc 中生成参考文献时突出显示一位特定作者
【发布时间】:2021-02-07 17:38:58
【问题描述】:

我正在使用 Pandoc 为我的网站生成出版物列表。我仅使用它来生成带有出版物的 html,以便我可以将原始 html 粘贴到 jekyll 中。这部分工作正常。

当我要生成 html 以使我的名字在所有条目中显示为粗体时,就会出现复杂情况。我正在尝试为此使用this solution,当我将它应用于我正在生成的纯乳胶文档时,它会起作用。但是,当我尝试应用相同的 Pandoc 时,生成的 html 没有任何粗体。

这是我的 Pandoc 文件:

---
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}}
...

这是我的 Makefile 的相关部分:

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

再说一遍:这段代码可以很好地生成引用。它只是没有像它应该的那样用粗体显示任何东西。

有什么想法吗?

编辑

围兜条目如下所示

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

版本是 - Biblatex 3.12 - 比伯 2.12

【问题讨论】:

  • 您使用哪个版本的 biber 和 biblatex?
  • 以及对应的围兜条目是什么样子的?
  • @samcarter 编辑了问题:3.12 和 2.12。
  • 这看起来不错。是否可以拦截在编译文档期间创建的 .tex 文件?
  • header-includes 中的 LaTeX 在您使用 pandoc 生成 HTML 时不会帮助您,因为这根本不涉及 LaTeX。您应该将等效的 CSS(或 JavaScript)放在那里..

标签: latex pandoc biblatex pandoc-citeproc


【解决方案1】:

您可以使用 lua 过滤器来修改 AST。以下内容可让我在参考文献 (see here) 中突出显示姓氏和首字母 (Smith, J.)。您可以将 pandoc.Strong 替换为 pandoc.Underline 或 pandoc.Emph。将 Smith 和 J. 替换为您的姓名/姓名缩写,将其另存为 myname.lua 并使用以下内容:

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

即把过滤器放在最后。

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

注意事项:

  1. 如果您使用作者日期格式 csl,上述方法有效。如果您想使用数字格式 csl(例如 ieee.csl 或 nature.csl),您需要在过滤器中将 Span 替换为 Para,即:
  Span = function(el)
    if el.t == "Span" then
  1. 如果你还想使用multiple-bibliographies lua filter,它应该放在作者高亮过滤器之前。 'refs' 应该是 'refs_biblio1' 或 'refs_biblio2' 等,这取决于你如何定义它们:
function Div (div)
  if 'refs' or 'refs_biblio1’ or 'refs_biblio2’ == div.identifier then

对于 pdf 输出,如果使用数字格式 csl,还需要在 pandoc 命令中添加-V csl-refs

  1. 如果由 csl 按此顺序格式化,过滤器会突出显示 Smith, J.。一些 csl 将使用此格式作为第一作者,然后切换到 J. Smith 作为其余作者,因此您必须相应地调整过滤器,添加一个额外的 if el.content[k].t == "Str”…etc。首先转换为 .json 将有助于检查 AST 中的正确格式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-20
    • 2017-07-12
    • 2020-08-26
    • 2015-05-15
    • 1970-01-01
    相关资源
    最近更新 更多