Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Please sign up or log in to edit the wiki.

Citation template for books.

TemplateData

Generic citation template for books and published volumes.

Template parameters

This template prefers inline formatting of parameters.

ParameterDescriptionTypeStatus
Author(s)author

Author(s) of the book. Multiple authors can be separated with semicolons or 'and'.

Stringsuggested
Chapter titlechapter

Title of the chapter

Stringsuggested
Book titletitle

Title of the book

Stringsuggested
Publisherpublisher

Publisher of the book

Stringsuggested
Publication datedate

Publication year or full date

Datesuggested
Pagespages

Page range of the article

Stringsuggested
Pagepage

Single page reference (used if pages is not set)

Stringoptional

local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
local mArguments -- initialized lazily
local p = {}

--- Formats citation
--- @param args table - arguments
--- @return string
function p._cite(args)
    checkType('_cite', 1, args, 'table')

    local parts = {}

    -- 1. Author
    if args.author and args.author ~= "" then
        table.insert(parts, args.author .. ",")
    end

    -- 2. Chapter
    if args.chapter and args.chapter ~= "" then
        table.insert(parts, '“' .. args.chapter .. ',” in')
    end

    -- 3. Title
    if args.title and args.title ~= "" then
        table.insert(parts, "''" .. args.title .. "''")
    end

    -- 4. Publisher and/or Date
    if (args.publisher and args.publisher ~= "") or (args.date and args.date ~= "") then
        local pubParts = {}
        if args.publisher and args.publisher ~= "" then table.insert(pubParts, args.publisher) end
        if args.date and args.date ~= "" then table.insert(pubParts, args.date) end
        
        if #parts > 0 then
            parts[#parts] = parts[#parts] .. " (" .. table.concat(pubParts, ", ") .. ")"
        else
            table.insert(parts, "(" .. table.concat(pubParts, ", ") .. ")")
        end
    end

    -- 5. Page / Pages
    if args.pages and args.pages ~= "" then
        if #parts > 0 then
            parts[#parts] = parts[#parts] .. ", pp. " .. args.pages
        else
            table.insert(parts, "pp. " .. args.pages)
        end
    elseif args.page and args.page ~= "" then
        if #parts > 0 then
            parts[#parts] = parts[#parts] .. ", p. " .. args.page
        else
            table.insert(parts, "p. " .. args.page)
        end
    end

    local result = table.concat(parts, " ")
    return (string.gsub(result, "%s+$", ""))
end

function p.cite(frame)
    mArguments = require('Module:Arguments')
    return p._cite(mArguments.getArgs(frame))
end

return p