-
-
Save tarleb/afee1b1d97e52aca888f410e77b3624a to your computer and use it in GitHub Desktop.
Any updates on this? Including [highlight-author.lua] in the _output.yml throws the following error:
Error running filter lua/highlight-author.lua:
PandocLuaError "Cannot get Attr from TypeNil"
stack traceback:
lua/highlight-author.lua:32: in function 'Pandoc'
Error: pandoc document conversion failed with error 83
Execution halted
While "local highlight_author_filter = {
Para = function(el) ..." approach does not do the highlighting trick for me.
Thanks in advance.
The highlight-author.lua filter only works with old versions of pandoc that use pandoc-citeproc. The other filter should work, but you have to be careful about how your name and initials are output by the csl you are using. Try converting to a .json file first to see how your csl treats initials, commas, periods, etc and make sure that you copy the strings correctly into the filter. I did a quick search in Scopus for Ayhan and created a short bibliography to test (as .json file, can also be .bib) - not sure if this is you, but you can adjust accordingly. I include below a text with two references (save as test.txt), the lua filter modified with your name (save as test.lua), the bibliography (save as biblio.json) and a csl file that I use to create a cv with my name underlined (so it puts all the details in the citation, not in a bibliography at the end - save as CiteOnly.csl). The command:
pandoc --citeproc --bibliography=biblio.json --csl=CiteOnly.csl -L test.lua -o test.pdf test.txt
should give you the correct result with name underlined - or use -o test.html if you don't want pdf. Then try with your csl file, if it doesn't work, convert to .json (pandoc -t json etc.), check how your initials are formated and adjust the lua filter.
Files:
test.txt
@Ayhan2022872
@Varpahovskis202252
test.lua
function Inline (el)
if el.t == "Cite" then
for k,_ in ipairs(el.content) do
if el.content[k].t == "Str" and el.content[k].text == "Ayhan,"
and el.content[k+1].t == "Space"
and el.content[k+2].t == "Str" and el.content[k+2].text:find("^K.J.") then
local _,e = el.content[k+2].text:find("^K.J.")
local rest = el.content[k+2].text:sub(e+1)
el.content[k] = pandoc.Underline { pandoc.Str("Ayhan, K.J.") }
el.content[k+1] = pandoc.Str(rest)
table.remove(el.content, k+2)
end
end
end
return el
end
biblio.json
[
{
"id": "Ayhan2022872",
"type": "article-journal",
"container-title": "Journal of Asian and African Studies",
"DOI": "10.1177/00219096211035800",
"issue": "4",
"note": "tex.document_type: Article\ntex.source: Scopus",
"page": "872-893",
"title": "Exploring global korea scholarship as a public diplomacy tool",
"URL": "https://www.scopus.com/inward/record.uri?eid=2-s2.0-85112764468&doi=10.1177%2f00219096211035800&partnerID=40&md5=b0445b994fdf178b3635cd521b10abe9",
"volume": "57",
"author": [
{
"family": "Ayhan",
"given": "K.J."
},
{
"family": "Gouda",
"given": "M."
},
{
"family": "Lee",
"given": "H."
}
],
"issued": {
"date-parts": [
[
"2022"
]
]
}
},
{
"id": "Varpahovskis202252",
"type": "article-journal",
"container-title": "Place Branding and Public Diplomacy",
"DOI": "10.1057/s41254-020-00177-0",
"issue": "2",
"note": "tex.document_type: Article\ntex.source: Scopus",
"page": "52-64",
"title": "Impact of country image on relationship maintenance: a case study of Korean Government Scholarship Program alumni",
"URL": "https://www.scopus.com/inward/record.uri?eid=2-s2.0-85089368484&doi=10.1057%2fs41254-020-00177-0&partnerID=40&md5=5f1f27dc8b88674ee4d38560f1d2eab9",
"volume": "18",
"author": [
{
"family": "Varpahovskis",
"given": "E."
},
{
"family": "Ayhan",
"given": "K.J."
}
],
"issued": {
"date-parts": [
[
"2022"
]
]
}
}
]
CiteOnly.csl
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" version="1.0" class="in-text" default-locale="en-US" demote-non-dropping-particle="sort-only" page-range-format="expanded">
<info>
<title>CiteOnly</title>
</info>
<macro name="author-short">
<names variable="author">
<name form="short" and="text"/>
</names>
</macro>
<macro name="author-count">
<names variable="author">
<name form="count"/>
</names>
</macro>
<macro name="author">
<names variable="author">
<name name-as-sort-order="all" initialize-with="." and="text" delimiter-precedes-last="always"/>
</names>
</macro>
<macro name="issued">
<date variable="issued">
<date-part name="year"/>
</date>
</macro>
<macro name="publisher">
<group prefix="(" delimiter=": " suffix=")">
<text variable="publisher-place"/>
<text variable="publisher"/>
</group>
</macro>
<macro name="editor">
<names variable="editor">
<name initialize-with="." and="text" delimiter-precedes-last="always"/>
<label form="short" prefix=", "/>
</names>
</macro>
<citation et-al-min="21" et-al-use-first="20">
<sort>
<key macro="author-short" names-min="1" names-use-first="1"/>
<key macro="author-count" names-min="3" names-use-first="3"/>
<key macro="author" names-min="3" names-use-first="1"/>
<key macro="issued"/>
<key variable="title"/>
</sort>
<layout suffix=".">
<group delimiter=" ">
<text macro="author"/>
<text macro="issued" prefix="(" suffix=")."/>
<choose>
<if type="article article-magazine article-newspaper article-journal review" match="any">
<text variable="title" suffix="."/>
<text variable="container-title" form="short" text-case="title" font-weight="bold"/>
<group delimiter=", ">
<text variable="volume" font-style="italic"/>
<text variable="page"/>
</group>
</if>
<else-if type="chapter paper-conference" match="any">
<text variable="title" suffix="."/>
<text variable="container-title" prefix="In " suffix="," text-case="title"/>
<text macro="editor"/>
<text macro="publisher" suffix=","/>
<label variable="page" form="short"/>
<text variable="page"/>
</else-if>
<else-if type="thesis">
<text variable="title" suffix="."/>
<text variable="genre" suffix="."/>
<text variable="publisher"/>
</else-if>
<else>
<text variable="title"/>
<text macro="publisher"/>
</else>
</choose>
</group>
</layout>
</citation>
</style>
Thank you very much for very detailed instructions. I should have probably mentioned that I am a markdown novice. And this is first time touching a lua file. I tried adding test.lua to my folder and to _output.yml here, but it didn't produce any result either (probably I should change something more).
Sounds like the
find
patterns are inconsistent: the one in theif
condition probably returns a truthy value, but the latter one doesn't match.