我用\setnotetext[footnote][0001]{This is a footnote.}
它来设置脚注的文本并\note[footnote][0001]
创建对它的多个引用。当脚注第一次出现,以及随后出现的脚注出现在大约 10 页之内时,这种方法是可行的,但是,如果距离太远,考虑到文档的复杂性,引用这么久以前的脚注就会变得很麻烦。我如何让 ConTeXt 为脚注分配一个新编号,并在页面底部显示相同的文本,如果它在 10 页或更多页内没有这样做,并且碰巧再次被引用?例如:
_______________________
| |
| This is some text.^1 |
| |
| | (page 1)
| .... |
| 1 This is a footnote. |
|_______________________|
_______________________
| |
| This is some text.^1 |
| |
| | (page 6)
| |
| |
|_______________________|
_______________________
| |
| This is some text.^2 |
| |
| | (page 14)
| .... |
| 2 This is a footnote. |
|_______________________|
_______________________
| |
| This is some text.^2 |
| |
| | (page 16)
| |
| |
|_______________________|
_______________________
| |
| This is some text.^3 |
| |
| | (page 70)
| .... |
| 3 This is a footnote. |
|_______________________|
如果脚注文本最后一次出现的时间早于 10 页以上,我该如何自动为脚注分配一个新编号并重新显示文本?
答案1
Context 没有提供内置机制,但只要稍微努力一下,就可以创建一个包装器笔记/符号 如果达到阈值,则动态生成新插入的功能。
将此代码保存为t-noteref.mkvi
:
\startmodule [noteref]
\startluacode
local texgetcount = tex.getcount
local thresholds = { } -- (string, (string, int) hash_t) hash_t
local occurrences = { } -- (string, (string, int) hash_t) hash_t
local contents = { } -- (string, (string, string) hash_t) hash_t
local noteref = function (tag, ref)
local ttag = thresholds[tag]
if not ttag then
context ("<noteref: unknown note tag %s>", tag)
return
end
local threshold = ttag[ref]
if not threshold then
context ("<noteref: undeclared reference %s for tag %s>",
ref, tag)
return
end
local currentpage = texgetcount "realpageno"
local last = occurrences[tag][ref]
local ref_id = ref .. ":" .. last
local diff = currentpage - last
if diff >= threshold then
--- create new notetext with same content
ref_id = ref .. ":" .. currentpage
occurrences[tag][ref] = currentpage
context.setnotetext ({tag}, {ref_id}, contents[tag][ref])
end
--- typeset the note marker
context.note ({tag}, {ref_id})
end
local initialize_tag = function (tag)
local ctag, ttag, otag = { }, { }, { }
contents[tag] = ctag
thresholds[tag] = ttag
occurrences[tag] = otag
return ctag, ttag, otag
end
local set_noteref = function (tag, ref, threshold, content)
tag = tag and tostring (tag) or "<none>"
local ctag = contents[tag]
local ttag = thresholds[tag]
local otag = occurrences[tag]
if not ctag then --- initialize new
ctag, ttag, otag = initialize_tag (tag)
end
ref = ref and tostring (ref) or "<none>"
threshold = threshold and tonumber (threshold) or 10
ttag[ref] = threshold
ctag[ref] = content
otag[ref] = -1/0
end
commands.set_noteref = set_noteref
commands.noteref = noteref
\stopluacode
\unprotect
\unexpanded \def \definenoteref {%
\dotripleempty \note_reference_define%
}
\def \note_reference_define [#tag][#reference][#threshold]#content{%
\ifthirdargument
\note_reference_define_indeed{#tag}{#reference}{#threshold}{#content}%
\else
\note_reference_define_indeed{\v!footnote}{#tag}{#reference}{#content}%
\fi%
}
\def \note_reference_define_indeed #tag#reference#threshold#content{%
\ctxcommand {set_noteref ("#tag", "#reference", #threshold,
"\luaescapestring{#content}")}%
}
\unexpanded \def \noteref {%
\dodoubleempty \note_reference_command%
}
\def \note_reference_command [#tag][#reference]{%
\ifsecondargument
\note_reference_indeed{#tag}{#reference}%
\else
\note_reference_indeed{\v!footnote}{#reference}%
\fi%
}
\def \note_reference_indeed #tag#reference{%
\ctxcommand {noteref ("#tag", "#reference")}%
}
\def \footnoteref {\noteref[\v!footnote]}
\def \definefootnoteref {\definenoteref[\v!footnote]}
\protect
\stopmodule
该模块声明了两个主要的用户宏:
\definenoteref[<note>][<reference>][<threshold>]{<text>}
创建一个新的类型条目<note>
(例如footnote
),可以由 引用<reference>
。必须是一个整数,它决定在重新排版<threshold>
脚注内容之前必须经过多少页。<text>
\noteref[<note>][<reference>]
<note>
指的是已定义为类型的注释<reference>
。自从脚注是迄今为止最常见的注释类型,该模块提供了两个方便的别名:
\footnoteref[<reference>]
与 同义\noteref[footnote][<reference>]
。同样,\definefootnoteref[<reference>][<value>]{<content>}
是 的简写\definenoteref[footnote][<reference>][<value>]{<content>}
。
使用方法很简单:首先,使用\definenoteref
而不是定义一个注释。现在您可以通过与之前相同的方式
\setnotetext
访问它。\noteref
\note
\setuppapersize [A7,landscape]
\setupinteraction [state=start]
\usemodule [noteref]
\definefootnoteref [mynote][3]{%% same as \definenoteref[footnote][mynote][3] {...}
This {\bold footnote} is going to be referred to repeatedly, though
the insert should reappear only whenever the threshold is reached.
}
\starttext
first occurrence: \footnoteref[mynote]
\dorecurse {19} {
\page [yes] inserted page no \recurselevel \par
> foo\footnote {some unremarkable footnote before} \par
> bar\footnoteref [mynote] \par
> baz\footnote {some unremarkable footnote after} \par
}
\stoptext
请注意,这些参数尽管有其名称,但不再是可以通过普通方式(如和 )<reference>
引用的实际引用。这是动态插入的结果,它在每次重复时都会创建一个新的实际引用,以供连续的引用。\in
\at
\noteref
对您的代码的一些补充说明:
\footnotetext
是\setnotetext[footnote]
(参见来源),因此您可以使用\footnotetext[0001]{this is a footnote}
。同样适用于\note
假设其第一个参数为
[footnote]
如果未指定(参见来源)。因此,只需\note[footnote][0001]
写\note[0001]