<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.martinuswiki.dk/w/index.php?action=history&amp;feed=atom&amp;title=Module%3AReference</id>
	<title>Module:Reference - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://en.martinuswiki.dk/w/index.php?action=history&amp;feed=atom&amp;title=Module%3AReference"/>
	<link rel="alternate" type="text/html" href="https://en.martinuswiki.dk/w/index.php?title=Module:Reference&amp;action=history"/>
	<updated>2026-08-12T16:06:24Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.9</generator>
	<entry>
		<id>https://en.martinuswiki.dk/w/index.php?title=Module:Reference&amp;diff=70&amp;oldid=prev</id>
		<title>Wikiboteng@Wikiboteng: Add English Martinus reference system (Stage 4)</title>
		<link rel="alternate" type="text/html" href="https://en.martinuswiki.dk/w/index.php?title=Module:Reference&amp;diff=70&amp;oldid=prev"/>
		<updated>2026-08-11T06:12:44Z</updated>

		<summary type="html">&lt;p&gt;Add English Martinus reference system (Stage 4)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- English Martinus Wiki reference renderer.&lt;br /&gt;
--&lt;br /&gt;
-- Stage 1 source artifact.  This module deliberately contains the routing and&lt;br /&gt;
-- validation policy in one small, data-driven module so it can be copied to&lt;br /&gt;
-- Module:Reference after Scribunto is enabled.  It does not call ParserFunctions.&lt;br /&gt;
-- The public entry points are p.ref (the template wrapper) and p.render (a&lt;br /&gt;
-- direct module entry point); all state is local to an invocation.&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
local EN_TTT = &amp;quot;https://www.martinus.dk/en/online-library/ttt/index.php&amp;quot;&lt;br /&gt;
local DA_TTT = &amp;quot;https://www.martinus.dk/da/onlinebibliotek/dtt/index.php&amp;quot;&lt;br /&gt;
local EN_SYMBOLS = &amp;quot;https://www.martinus.dk/en/online-library/symbols/index.php&amp;quot;&lt;br /&gt;
local DA_LECTURES = &amp;quot;https://www.martinus.dk/da/onlinebibliotek/foredrag/index.php&amp;quot;&lt;br /&gt;
local ERROR_CATEGORY = &amp;quot;[[Category:Pages with Martinus reference errors]]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
-- The section ranges are the ranges shown by the official online library.  LB6&lt;br /&gt;
-- and LB7 are retained for compatibility, but their English flag is false until&lt;br /&gt;
-- an English text is confirmed by the Institute.&lt;br /&gt;
local BOOKS = {&lt;br /&gt;
    LB1 = { id = 51, title = &amp;quot;Livets Bog 1&amp;quot;, first = 1, last = 288, english = true },&lt;br /&gt;
    LB2 = { id = 52, title = &amp;quot;Livets Bog 2&amp;quot;, first = 289, last = 638, english = true },&lt;br /&gt;
    LB3 = { id = 53, title = &amp;quot;Livets Bog 3&amp;quot;, first = 639, last = 1052, english = true },&lt;br /&gt;
    LB4 = { id = 54, title = &amp;quot;Livets Bog 4&amp;quot;, first = 1053, last = 1590, english = true },&lt;br /&gt;
    LB5 = { id = 55, title = &amp;quot;Livets Bog 5&amp;quot;, first = 1591, last = 1938, english = true },&lt;br /&gt;
    LB6 = { id = 56, title = &amp;quot;Livets Bog 6&amp;quot;, first = 1939, last = 2395, english = false },&lt;br /&gt;
    LB7 = { id = 57, title = &amp;quot;Livets Bog 7&amp;quot;, first = 2396, last = 2664, english = false },&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local TEWP = {&lt;br /&gt;
    [1] = { id = 61, title = &amp;quot;The Eternal World Picture 1&amp;quot;, english = true },&lt;br /&gt;
    [2] = { id = 62, title = &amp;quot;The Eternal World Picture 2&amp;quot;, english = true },&lt;br /&gt;
    [3] = { id = 63, title = &amp;quot;The Eternal World Picture 3&amp;quot;, english = true },&lt;br /&gt;
    [4] = { id = 64, title = &amp;quot;The Eternal World Picture 4&amp;quot;, english = true },&lt;br /&gt;
    [5] = { id = 65, title = &amp;quot;The Eternal World Picture 5&amp;quot;, english = false },&lt;br /&gt;
    [6] = { id = 66, title = &amp;quot;The Eternal World Picture 6&amp;quot;, english = false },&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local ALLOWED = {&lt;br /&gt;
    [&amp;quot;1&amp;quot;] = true, [&amp;quot;2&amp;quot;] = true, [&amp;quot;3&amp;quot;] = true, [&amp;quot;4&amp;quot;] = true,&lt;br /&gt;
    [&amp;quot;5&amp;quot;] = true, [&amp;quot;6&amp;quot;] = true, [&amp;quot;7&amp;quot;] = true, [&amp;quot;8&amp;quot;] = true,&lt;br /&gt;
    [&amp;quot;9&amp;quot;] = true, [&amp;quot;10&amp;quot;] = true,&lt;br /&gt;
    work = true, source = true, section = true, subsection = true,&lt;br /&gt;
    kind = true,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local function trim(value)&lt;br /&gt;
    if value == nil then&lt;br /&gt;
        return nil&lt;br /&gt;
    end&lt;br /&gt;
    value = tostring(value):gsub(&amp;quot;^%s+&amp;quot;, &amp;quot;&amp;quot;):gsub(&amp;quot;%s+$&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
    if value == &amp;quot;&amp;quot; then&lt;br /&gt;
        return nil&lt;br /&gt;
    end&lt;br /&gt;
    return value&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function text(value)&lt;br /&gt;
    -- All values that reach this helper have already passed a strict grammar,&lt;br /&gt;
    -- except Kosmos text.  mw.text.encode prevents that free text becoming HTML.&lt;br /&gt;
    return mw.text.encode(tostring(value))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function error_message(code, detail)&lt;br /&gt;
    local suffix = detail and (&amp;quot; (&amp;quot; .. text(detail) .. &amp;quot;)&amp;quot;) or &amp;quot;&amp;quot;&lt;br /&gt;
    return &amp;#039;&amp;lt;span class=&amp;quot;error reference-error&amp;quot;&amp;gt;Reference error: &amp;#039; .. code .. suffix .. &amp;quot;&amp;lt;/span&amp;gt;&amp;quot; .. ERROR_CATEGORY&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function link(url, label)&lt;br /&gt;
    return &amp;quot;[&amp;quot; .. url .. &amp;quot; &amp;quot; .. text(label) .. &amp;quot;]&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function is_integer(value)&lt;br /&gt;
    return value ~= nil and value:match(&amp;quot;^[1-9]%d*$&amp;quot;) ~= nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function is_decimal_section(value)&lt;br /&gt;
    return value ~= nil and value:match(&amp;quot;^[1-9]%d*%.[1-9]%d*$&amp;quot;) ~= nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function source_suffix(book)&lt;br /&gt;
    if book.english then&lt;br /&gt;
        return &amp;quot;English online text&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    return &amp;quot;Danish original; no English translation confirmed&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function book_url(book, section, subsection)&lt;br /&gt;
    local base = book.english and EN_TTT or DA_TTT&lt;br /&gt;
    local mode = section and (book.english and &amp;quot;opslag&amp;quot; or &amp;quot;forside&amp;quot;) or &amp;quot;forside&amp;quot;&lt;br /&gt;
    local url = base .. &amp;quot;?bog=&amp;quot; .. book.id .. &amp;quot;&amp;amp;mode=&amp;quot; .. mode&lt;br /&gt;
    if section then&lt;br /&gt;
        url = url .. &amp;quot;&amp;amp;stk=&amp;quot; .. section&lt;br /&gt;
    end&lt;br /&gt;
    if subsection then&lt;br /&gt;
        url = url .. &amp;quot;&amp;amp;pkt=&amp;quot; .. subsection&lt;br /&gt;
    end&lt;br /&gt;
    return url&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function book_reference(book, section, subsection)&lt;br /&gt;
    if not book then&lt;br /&gt;
        return nil&lt;br /&gt;
    end&lt;br /&gt;
    if section and not is_integer(section) then&lt;br /&gt;
        return nil, &amp;quot;INVALID_SECTION&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    if subsection and not is_integer(subsection) then&lt;br /&gt;
        return nil, &amp;quot;INVALID_SUBSECTION&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    if subsection and not section then&lt;br /&gt;
        return nil, &amp;quot;MISSING_SECTION&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    if section then&lt;br /&gt;
        local number = tonumber(section)&lt;br /&gt;
        if number &amp;lt; book.first or number &amp;gt; book.last then&lt;br /&gt;
            return nil, &amp;quot;SECTION_OUT_OF_RANGE&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    local label = book.title&lt;br /&gt;
    if section then&lt;br /&gt;
        label = label .. &amp;quot;, section &amp;quot; .. section&lt;br /&gt;
        if subsection then&lt;br /&gt;
            label = label .. &amp;quot;, subsection &amp;quot; .. subsection&lt;br /&gt;
        end&lt;br /&gt;
    else&lt;br /&gt;
        label = label .. &amp;quot; (book)&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    local url = book_url(book, section, subsection)&lt;br /&gt;
    return link(url, label .. &amp;quot; — &amp;quot; .. source_suffix(book))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function find_book_for_section(section)&lt;br /&gt;
    local number = tonumber(section)&lt;br /&gt;
    for _, key in ipairs({ &amp;quot;LB1&amp;quot;, &amp;quot;LB2&amp;quot;, &amp;quot;LB3&amp;quot;, &amp;quot;LB4&amp;quot;, &amp;quot;LB5&amp;quot;, &amp;quot;LB6&amp;quot;, &amp;quot;LB7&amp;quot; }) do&lt;br /&gt;
        local book = BOOKS[key]&lt;br /&gt;
        if number &amp;gt;= book.first and number &amp;lt;= book.last then&lt;br /&gt;
            return book&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function normalise_work(value)&lt;br /&gt;
    local upper = value:upper():gsub(&amp;quot;%s+&amp;quot;, &amp;quot; &amp;quot;)&lt;br /&gt;
    local lb = upper:match(&amp;quot;^(LB[1-7])$&amp;quot;)&lt;br /&gt;
    if lb then&lt;br /&gt;
        return &amp;quot;LB&amp;quot;, tonumber(lb:sub(3))&lt;br /&gt;
    end&lt;br /&gt;
    local tewp = upper:match(&amp;quot;^TEWP%s+([1-6])$&amp;quot;)&lt;br /&gt;
        or upper:match(&amp;quot;^DEV%s+([1-6])$&amp;quot;)&lt;br /&gt;
        or upper:match(&amp;quot;^THE ETERNAL WORLD PICTURE%s+([1-6])$&amp;quot;)&lt;br /&gt;
    if tewp then&lt;br /&gt;
        return &amp;quot;TEWP&amp;quot;, tonumber(tewp)&lt;br /&gt;
    end&lt;br /&gt;
    local short = upper:match(&amp;quot;^SHORT BOOK%s+([1-9]%d*)$&amp;quot;)&lt;br /&gt;
        or upper:match(&amp;quot;^SMÅBOG%s+([1-9]%d*)$&amp;quot;)&lt;br /&gt;
        or upper:match(&amp;quot;^SMABOG%s+([1-9]%d*)$&amp;quot;)&lt;br /&gt;
        or upper:match(&amp;quot;^PAMPHLET%s+([1-9]%d*)$&amp;quot;)&lt;br /&gt;
    if short then&lt;br /&gt;
        return &amp;quot;SHORT&amp;quot;, tonumber(short)&lt;br /&gt;
    end&lt;br /&gt;
    return upper&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function collect_args(argument_frame)&lt;br /&gt;
    local values = {}&lt;br /&gt;
    -- p.ref passes the Template:Ref frame explicitly. This is important:&lt;br /&gt;
    -- putting #invoke inside literal &amp;lt;ref&amp;gt; markup creates another parser frame&lt;br /&gt;
    -- and loses the template arguments. Reading this exact frame also keeps&lt;br /&gt;
    -- every argument visible to validation, including unknown names.&lt;br /&gt;
    if not argument_frame then&lt;br /&gt;
        return nil, &amp;quot;MISSING_PRIMARY_ARGUMENT&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    for key, raw in pairs(argument_frame.args or {}) do&lt;br /&gt;
        local name = tostring(key)&lt;br /&gt;
        local value = trim(raw)&lt;br /&gt;
        if value ~= nil then&lt;br /&gt;
            if not ALLOWED[name] then&lt;br /&gt;
                return nil, &amp;quot;UNSUPPORTED_ARGUMENT&amp;quot;, name&lt;br /&gt;
            end&lt;br /&gt;
            values[name] = value&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return values&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function positional(values)&lt;br /&gt;
    local result = {}&lt;br /&gt;
    for index = 1, 10 do&lt;br /&gt;
        if values[tostring(index)] ~= nil then&lt;br /&gt;
            result[index] = values[tostring(index)]&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    for index = 2, 10 do&lt;br /&gt;
        if result[index] ~= nil and result[index - 1] == nil then&lt;br /&gt;
            return nil, &amp;quot;MISSING_PRIMARY_ARGUMENT&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    for index = 4, 10 do&lt;br /&gt;
        if result[index] ~= nil then&lt;br /&gt;
            return nil, &amp;quot;TOO_MANY_POSITIONAL_ARGUMENTS&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function render_book(work, section, subsection)&lt;br /&gt;
    local family, volume = normalise_work(work)&lt;br /&gt;
    if family == &amp;quot;LB&amp;quot; then&lt;br /&gt;
        local book = BOOKS[&amp;quot;LB&amp;quot; .. volume]&lt;br /&gt;
        if not book then&lt;br /&gt;
            return nil, &amp;quot;UNKNOWN_VOLUME&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        return book_reference(book, section, subsection)&lt;br /&gt;
    end&lt;br /&gt;
    if family == &amp;quot;TEWP&amp;quot; then&lt;br /&gt;
        local book = TEWP[volume]&lt;br /&gt;
        if not book then&lt;br /&gt;
            return nil, &amp;quot;UNKNOWN_VOLUME&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        if subsection then&lt;br /&gt;
            return nil, &amp;quot;TOO_MANY_SOURCE_ARGUMENTS&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        if not section or not is_decimal_section(section) then&lt;br /&gt;
            return nil, &amp;quot;INVALID_SYMBOL_SECTION&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        local base = book.english and EN_TTT or DA_TTT&lt;br /&gt;
        local url = base .. &amp;quot;?bog=&amp;quot; .. book.id .. &amp;quot;&amp;amp;mode=opslag&amp;amp;pkt=&amp;quot; .. section:match(&amp;quot;%d+$&amp;quot;) .. &amp;quot;&amp;amp;stk=&amp;quot; .. section:match(&amp;quot;^%d+&amp;quot;)&lt;br /&gt;
        return link(url, book.title .. &amp;quot;, section &amp;quot; .. section .. &amp;quot; — &amp;quot; .. source_suffix(book))&lt;br /&gt;
    end&lt;br /&gt;
    if family == &amp;quot;SHORT&amp;quot; then&lt;br /&gt;
        if subsection then&lt;br /&gt;
            return nil, &amp;quot;TOO_MANY_SOURCE_ARGUMENTS&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        if not section or not is_decimal_section(section) then&lt;br /&gt;
            return nil, &amp;quot;INVALID_SHORT_BOOK_SECTION&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        local chapter, passage = section:match(&amp;quot;^(%d+)%.(%d+)$&amp;quot;)&lt;br /&gt;
        local url = DA_TTT .. &amp;quot;?bog=&amp;quot; .. volume .. &amp;quot;&amp;amp;art=&amp;quot; .. chapter .. &amp;quot;&amp;amp;stk=&amp;quot; .. passage&lt;br /&gt;
        return link(url, &amp;quot;Short book &amp;quot; .. volume .. &amp;quot;, section &amp;quot; .. section .. &amp;quot; — Danish original; English translation not confirmed&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    return nil, &amp;quot;UNKNOWN_WORK&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function render_special(kind, value)&lt;br /&gt;
    local lowered = kind:lower()&lt;br /&gt;
    if lowered == &amp;quot;symbol&amp;quot; or lowered == &amp;quot;symbols&amp;quot; then&lt;br /&gt;
        if not is_integer(value) or tonumber(value) &amp;gt; 100 then&lt;br /&gt;
            return nil, &amp;quot;INVALID_SYMBOL_ID&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        return link(EN_SYMBOLS .. &amp;quot;?symbol=&amp;quot; .. value, &amp;quot;Symbol &amp;quot; .. value .. &amp;quot; — English symbol page&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    if lowered == &amp;quot;article&amp;quot; or lowered == &amp;quot;articles&amp;quot; then&lt;br /&gt;
        if not value or value:match(&amp;quot;^%d%d%d%d$&amp;quot;) == nil then&lt;br /&gt;
            return nil, &amp;quot;INVALID_ARTICLE_ID&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        return link(EN_TTT .. &amp;quot;?art=&amp;quot; .. value .. &amp;quot;&amp;amp;mode=artikelopslag&amp;quot;, &amp;quot;Article &amp;quot; .. value .. &amp;quot; — English online text if available&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    if lowered == &amp;quot;lecture&amp;quot; or lowered == &amp;quot;lectures&amp;quot; or lowered == &amp;quot;foredrag&amp;quot; then&lt;br /&gt;
        if not is_integer(value) then&lt;br /&gt;
            return nil, &amp;quot;INVALID_LECTURE_ID&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        return link(DA_LECTURES .. &amp;quot;?nr=&amp;quot; .. value, &amp;quot;Lecture &amp;quot; .. value .. &amp;quot; — Danish original; English translation not confirmed&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    if lowered == &amp;quot;kosmos&amp;quot; then&lt;br /&gt;
        if not value then&lt;br /&gt;
            return nil, &amp;quot;MISSING_KOSMOS_DESCRIPTION&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
        return text(&amp;quot;Kosmos: &amp;quot; .. value .. &amp;quot; — Danish original; no direct online-library link confirmed&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    return nil, &amp;quot;UNKNOWN_SOURCE_KIND&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function render_reference(argument_frame)&lt;br /&gt;
    local values, collect_error, collect_detail = collect_args(argument_frame)&lt;br /&gt;
    if not values then&lt;br /&gt;
        return error_message(collect_error, collect_detail)&lt;br /&gt;
    end&lt;br /&gt;
    local pos, positional_error = positional(values)&lt;br /&gt;
    if not pos then&lt;br /&gt;
        return error_message(positional_error)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    local work = values.work or values.source&lt;br /&gt;
    local section = values.section&lt;br /&gt;
    local subsection = values.subsection&lt;br /&gt;
    local kind = values.kind&lt;br /&gt;
&lt;br /&gt;
    if values.work and values.source then&lt;br /&gt;
        return error_message(&amp;quot;DUPLICATE_WORK_ARGUMENTS&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    if values.section and pos[2] then&lt;br /&gt;
        return error_message(&amp;quot;DUPLICATE_SECTION_ARGUMENT&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    if values.subsection and pos[3] then&lt;br /&gt;
        return error_message(&amp;quot;DUPLICATE_SUBSECTION_ARGUMENT&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if kind then&lt;br /&gt;
        if pos[2] or pos[3] or work or section or subsection then&lt;br /&gt;
            return error_message(&amp;quot;MIXED_REFERENCE_FORMS&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
        local special_result, special_error = render_special(kind, pos[1] or values[&amp;quot;1&amp;quot;])&lt;br /&gt;
        if not special_result then&lt;br /&gt;
            return error_message(special_error)&lt;br /&gt;
        end&lt;br /&gt;
        return special_result&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if work and pos[1] then&lt;br /&gt;
        return error_message(&amp;quot;MIXED_REFERENCE_FORMS&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if work then&lt;br /&gt;
        section = section or pos[2]&lt;br /&gt;
        subsection = subsection or pos[3]&lt;br /&gt;
    else&lt;br /&gt;
        work = pos[1]&lt;br /&gt;
        section = section or pos[2]&lt;br /&gt;
        subsection = subsection or pos[3]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if not work then&lt;br /&gt;
        return error_message(&amp;quot;MISSING_PRIMARY_ARGUMENT&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if is_integer(work) then&lt;br /&gt;
        if section and subsection then&lt;br /&gt;
            return error_message(&amp;quot;DUPLICATE_SUBSECTION_ARGUMENT&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
        if section and not is_integer(section) then&lt;br /&gt;
            return error_message(&amp;quot;INVALID_SUBSECTION&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
        local book = find_book_for_section(work)&lt;br /&gt;
        if not book then&lt;br /&gt;
            return error_message(&amp;quot;SECTION_OUT_OF_RANGE&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
        -- For numeric shorthand the second value is the subsection.  Accept&lt;br /&gt;
        -- either positional 2 or the named subsection form, but never discard&lt;br /&gt;
        -- a third positional value.&lt;br /&gt;
        local numeric_subsection = subsection or section&lt;br /&gt;
        local result, render_error = book_reference(book, work, numeric_subsection)&lt;br /&gt;
        if not result then&lt;br /&gt;
            return error_message(render_error)&lt;br /&gt;
        end&lt;br /&gt;
        return result&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    if work:lower() == &amp;quot;e&amp;quot; or work:lower() == &amp;quot;epilogue&amp;quot; then&lt;br /&gt;
        if section or subsection then&lt;br /&gt;
            return error_message(&amp;quot;UNEXPECTED_EPILOGUE_ARGUMENT&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
        local book = BOOKS.LB7&lt;br /&gt;
        return link(book_url(book, &amp;quot;2665&amp;quot;), &amp;quot;Livets Bog 7, epilogue (section 2665) — Danish original; no English translation confirmed&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    local special_kind = work:lower()&lt;br /&gt;
    if special_kind == &amp;quot;symbol&amp;quot; or special_kind == &amp;quot;symbols&amp;quot;&lt;br /&gt;
        or special_kind == &amp;quot;article&amp;quot; or special_kind == &amp;quot;articles&amp;quot;&lt;br /&gt;
        or special_kind == &amp;quot;lecture&amp;quot; or special_kind == &amp;quot;lectures&amp;quot;&lt;br /&gt;
        or special_kind == &amp;quot;foredrag&amp;quot; or special_kind == &amp;quot;kosmos&amp;quot; then&lt;br /&gt;
        if subsection then&lt;br /&gt;
            return error_message(&amp;quot;TOO_MANY_SOURCE_ARGUMENTS&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
        local special_result, special_error = render_special(work, section)&lt;br /&gt;
        if not special_result then&lt;br /&gt;
            return error_message(special_error)&lt;br /&gt;
        end&lt;br /&gt;
        return special_result&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    local result, render_error = render_book(work, section, subsection)&lt;br /&gt;
    if not result then&lt;br /&gt;
        return error_message(render_error)&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.render(frame)&lt;br /&gt;
    return render_reference(frame)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.ref(frame)&lt;br /&gt;
    local parent = frame and frame:getParent()&lt;br /&gt;
    local content = render_reference(parent)&lt;br /&gt;
    local has_error_category = content:sub(-#ERROR_CATEGORY) == ERROR_CATEGORY&lt;br /&gt;
    if has_error_category then&lt;br /&gt;
        -- Category links inside a Cite extension tag are not reliably attached&lt;br /&gt;
        -- to the page. Keep the error text in the note, but emit the marker&lt;br /&gt;
        -- outside the tag so the maintenance category is authoritative.&lt;br /&gt;
        content = content:sub(1, -#ERROR_CATEGORY - 1)&lt;br /&gt;
    end&lt;br /&gt;
    local reference = frame:extensionTag(&amp;quot;ref&amp;quot;, content)&lt;br /&gt;
    if has_error_category then&lt;br /&gt;
        reference = reference .. ERROR_CATEGORY&lt;br /&gt;
    end&lt;br /&gt;
    return reference&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Wikiboteng@Wikiboteng</name></author>
	</entry>
</feed>