diff options
Diffstat (limited to 'paper/lua-filters/author-info-blocks')
-rw-r--r-- | paper/lua-filters/author-info-blocks/Makefile | 8 | ||||
-rw-r--r-- | paper/lua-filters/author-info-blocks/README.md | 59 | ||||
-rw-r--r-- | paper/lua-filters/author-info-blocks/author-info-blocks.lua | 176 | ||||
-rw-r--r-- | paper/lua-filters/author-info-blocks/document-screenshot.jpg | bin | 14584 -> 0 bytes | |||
-rw-r--r-- | paper/lua-filters/author-info-blocks/expected.native | 5 | ||||
-rw-r--r-- | paper/lua-filters/author-info-blocks/sample.md | 28 |
6 files changed, 0 insertions, 276 deletions
diff --git a/paper/lua-filters/author-info-blocks/Makefile b/paper/lua-filters/author-info-blocks/Makefile deleted file mode 100644 index 341c44d..0000000 --- a/paper/lua-filters/author-info-blocks/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -test: sample.md author-info-blocks.lua - @pandoc --lua-filter=author-info-blocks.lua --standalone --to=native $< \ - | diff -u expected.native - - -expected.native: sample.md author-info-blocks.lua - pandoc --lua-filter=author-info-blocks.lua --standalone --output $@ $< - -.PHONY: test diff --git a/paper/lua-filters/author-info-blocks/README.md b/paper/lua-filters/author-info-blocks/README.md deleted file mode 100644 index 3386bac..0000000 --- a/paper/lua-filters/author-info-blocks/README.md +++ /dev/null @@ -1,59 +0,0 @@ -# author-info-blocks - -This filter adds author-related header blocks usually included in -scholarly articles, such as a list of author affiliations, -correspondence information, and on notes equal contributors. - - -## Dependencies - -This filter assumes metadata in the canonical format generated by -the [scholarly-metadata filter](../scholarly-metadata). - -## Usage - -The filter should be run after *scholarly-metadata.lua*: - - pandoc --lua-filter=scholarly-metadata/scholarly-metadata.lua \ - --lua-filter=author-info-blocks/author-inffo-blocks.lua \ - --output=outfile.pdf --pdf-engine=xelatex \ - article.md - -The ways in which affiliation data should be given is described -in the docs for **scholarly-metadata.lua*. Additionally, authors -who contributed equally to an article can be marked by adding -`equal_contributor: yes` to the respective YAML objects. -Similarly, corresponding authors should be marked with -`correspondence: yes` and have an `email` listed. - -### Example - -Take the following example YAML block: - -``` yaml ---- -title: Affiliation Blocks Example -author: - - Jane Doe: - institute: - - federation - equal_contributor: "yes" - correspondence: "yes" - email: jane.doe@example.com - - John Q. Doe: - institute: [federation, acme] - equal_contributor: "yes" - - Juan Pérez: - institute: acme -institute: - - federation: Federation of Planets - - acme: - name: Acme Corporation ---- -``` - -This will mark Jane Doe and John Q. Doe as equal contributors and -Jane Doe as the sole corresponding author. Below is a screenshot -of a document header created from this metadata. - -![example document screenshot](document-screenshot.jpg) diff --git a/paper/lua-filters/author-info-blocks/author-info-blocks.lua b/paper/lua-filters/author-info-blocks/author-info-blocks.lua deleted file mode 100644 index 27e32bc..0000000 --- a/paper/lua-filters/author-info-blocks/author-info-blocks.lua +++ /dev/null @@ -1,176 +0,0 @@ ---[[ -affiliation-blocks – generate title components - -Copyright © 2017–2019 Albert Krewinkel - -Permission to use, copy, modify, and/or distribute this software for any purpose -with or without fee is hereby granted, provided that the above copyright notice -and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF -THIS SOFTWARE. -]] -local List = require 'pandoc.List' -local utils = require 'pandoc.utils' -local stringify = utils.stringify - -local default_marks -local default_marks = { - corresponding_author = FORMAT == 'latex' - and {pandoc.RawInline('latex', '*')} - or {pandoc.Str '✉'}, - equal_contributor = FORMAT == 'latex' - and {pandoc.RawInline('latex', '$\\dagger{}$')} - or {pandoc.Str '*'}, -} - -local function intercalate(lists, elem) - local result = List:new{} - for i = 1, (#lists - 1) do - result:extend(lists[i]) - result:extend(elem) - end - if #lists > 0 then - result:extend(lists[#lists]) - end - return result -end - ---- Check whether the given author is a corresponding author -local function is_corresponding_author(author) - return author.correspondence and author.email -end - ---- Create inlines for a single author (includes all author notes) -local function author_inline_generator (get_mark) - return function (author) - local author_marks = List:new{} - if author.equal_contributor then - author_marks[#author_marks + 1] = get_mark 'equal_contributor' - end - local idx_str - for _, idx in ipairs(author.institute) do - if type(idx) ~= 'table' then - idx_str = tostring(idx) - else - idx_str = stringify(idx) - end - author_marks[#author_marks + 1] = {pandoc.Str(idx_str)} - end - if is_corresponding_author(author) then - author_marks[#author_marks + 1] = get_mark 'corresponding_author' - end - local res = List.clone(author.name) - res[#res + 1] = pandoc.Superscript(intercalate(author_marks, {pandoc.Str ','})) - return res - end -end - -local function is_equal_contributor (author) - return author.equal_contributor -end - ---- Create equal contributors note. -local function create_equal_contributors_block(authors, mark) - local has_equal_contribs = List:new(authors):find_if(is_equal_contributor) - if not has_equal_contribs then - return nil - end - local contributors = { - pandoc.Superscript(mark'equal_contributor'), - pandoc.Space(), - pandoc.Str 'These authors contributed equally to this work.' - } - return List:new{pandoc.Para(contributors)} -end - ---- Generate a block list all affiliations, marked with arabic numbers. -local function create_affiliations_blocks(affiliations) - local affil_lines = List:new(affiliations):map( - function (affil, i) - local num_inlines = List:new{ - pandoc.Superscript{pandoc.Str(tostring(i))}, - pandoc.Space() - } - return num_inlines .. affil.name - end - ) - return {pandoc.Para(intercalate(affil_lines, {pandoc.LineBreak()}))} -end - ---- Generate a block element containing the correspondence information -local function create_correspondence_blocks(authors, mark) - local corresponding_authors = List:new{} - for _, author in ipairs(authors) do - if is_corresponding_author(author) then - local mailto = 'mailto:' .. pandoc.utils.stringify(author.email) - local author_with_mail = List:new( - author.name .. List:new{pandoc.Space(), pandoc.Str '<'} .. - author.email .. List:new{pandoc.Str '>'} - ) - local link = pandoc.Link(author_with_mail, mailto) - table.insert(corresponding_authors, {link}) - end - end - if #corresponding_authors == 0 then - return nil - end - local correspondence = List:new{ - pandoc.Superscript(mark'corresponding_author'), - pandoc.Space(), - pandoc.Str'Correspondence:', - pandoc.Space() - } - local sep = List:new{pandoc.Str',', pandoc.Space()} - return { - pandoc.Para(correspondence .. intercalate(corresponding_authors, sep)) - } -end - ---- Generate a list of inlines containing all authors. -local function create_authors_inlines(authors, mark) - local inlines_generator = author_inline_generator(mark) - local inlines = List:new(authors):map(inlines_generator) - local and_str = List:new{pandoc.Space(), pandoc.Str'and', pandoc.Space()} - - local last_author = inlines[#inlines] - inlines[#inlines] = nil - local result = intercalate(inlines, {pandoc.Str ',', pandoc.Space()}) - if #authors > 1 then - result:extend(List:new{pandoc.Str ","} .. and_str) - end - result:extend(last_author) - return result -end - -return { - { - Pandoc = function (doc) - local meta = doc.meta - local body = List:new{} - - local mark = function (mark_name) return default_marks[mark_name] end - - body:extend(create_equal_contributors_block(doc.meta.author, mark) or {}) - body:extend(create_affiliations_blocks(doc.meta.institute) or {}) - body:extend(create_correspondence_blocks(doc.meta.author, mark) or {}) - body:extend(doc.blocks) - - -- Overwrite authors with formatted values. We use a single, formatted - -- string for most formats. LaTeX output, however, looks nicer if we - -- provide a authors as a list. - meta.author = FORMAT:match 'latex' - and pandoc.MetaList(doc.meta.author):map(author_inline_generator(mark)) - or pandoc.MetaInlines(create_authors_inlines(doc.meta.author, mark)) - -- Institute info is now baked into the affiliations block. - meta.institute = nil - - return pandoc.Pandoc(body, meta) - end - } -} diff --git a/paper/lua-filters/author-info-blocks/document-screenshot.jpg b/paper/lua-filters/author-info-blocks/document-screenshot.jpg Binary files differdeleted file mode 100644 index 9e30e9f..0000000 --- a/paper/lua-filters/author-info-blocks/document-screenshot.jpg +++ /dev/null diff --git a/paper/lua-filters/author-info-blocks/expected.native b/paper/lua-filters/author-info-blocks/expected.native deleted file mode 100644 index 6608de7..0000000 --- a/paper/lua-filters/author-info-blocks/expected.native +++ /dev/null @@ -1,5 +0,0 @@ -Pandoc (Meta {unMeta = fromList [("author",MetaInlines [Str "Jane",Space,Str "Doe",Superscript [Str "*",Str ",",Str "1",Str ",",Str "\9993"],Str ",",Space,Str "John",Space,Str "Q.",Space,Str "Doe",Superscript [Str "*",Str ",",Str "1",Str ",",Str "2"],Str ",",Space,Str "and",Space,Str "Juan",Space,Str "P\233rez",Superscript [Str "2"]]),("title",MetaInlines [Str "Affiliation",Space,Str "Blocks",Space,Str "Example"])]}) -[Para [Superscript [Str "*"],Space,Str "These authors contributed equally to this work."] -,Para [Superscript [Str "1"],Space,Str "Federation",Space,Str "of",Space,Str "Planets",LineBreak,Superscript [Str "2"],Space,Str "Acme",Space,Str "Corporation"] -,Para [Superscript [Str "\9993"],Space,Str "Correspondence:",Space,Link ("",[],[]) [Str "Jane",Space,Str "Doe",Space,Str "<",Str "jane.doe@example.com",Str ">"] ("mailto:jane.doe@example.com","")] -,Para [Str "Lorem",Space,Str "ipsum",Space,Str "dolor",Space,Str "sit",Space,Str "amet."]] diff --git a/paper/lua-filters/author-info-blocks/sample.md b/paper/lua-filters/author-info-blocks/sample.md deleted file mode 100644 index 541aa26..0000000 --- a/paper/lua-filters/author-info-blocks/sample.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -author: -- correspondence: yes - email: 'jane.doe\@example.com' - equal_contributor: yes - id: Jane Doe - institute: - - 1 - name: Jane Doe -- equal_contributor: yes - id: 'John Q. Doe' - institute: - - 1 - - 2 - name: 'John Q. Doe' -- id: Juan Pérez - institute: - - 2 - name: Juan Pérez -institute: -- id: federation - name: Federation of Planets -- id: acme - name: Acme Corporation -title: Affiliation Blocks Example ---- - -Lorem ipsum dolor sit amet. |