背景
希望重现类似的自定义寄存器:
使用以下方式添加索引条目:
\setregisterentry[index][entries={Kenji Fujimoto}][
title={Maguro},
author={Kenji Fujimoto},
authorurl={http://bit.ly/1fNWF0Y},
]{Maguro}
这产生了一个相当接近的表示:
问题
主要问题是,由于它是一个登记册,按字母顺序排列的不同条目之间有一行额外的线。
代码
重现问题的代码:
\setupinteraction[state=start,]
\define[2]\href{\begingroup\goto{\color[blue]{#1}}[url(#2)]\endgroup}
\define[1]\TextCommand{%
* \Word{\currentregisterpageuserdata{title}}, }
\define[1]\PageCommand{%
#1. {\href{\currentregisterpageuserdata{author}}{\currentregisterpageuserdata{authorurl}}}.}
\starttext
\startsection[title={Ikura}]
\setregisterentry[index][entries={Jiro Ono}][
title={Ikura},
author={Jiro Ono},
authorurl={http://www.sushi-jiro.jp},
]{Ikura}
\stopsection
\startsection[title={Maguro}]
\setregisterentry[index][entries={Kenji Fujimoto}][
title={Maguro},
author={Kenji Fujimoto},
authorurl={http://bit.ly/1fNWF0Y},
]{Maguro}
\stopsection
\page
\placeregister[index][
n=1,
indicator=no,
textcommand=\TextCommand,
pagecommand=\PageCommand,
pagestyle=normal,
distance=\zeropoint,
]
\stoptext
问题
我想知道(按重要性排序):
- 如何删除按字母顺序排列的寄存器项之间的垂直空格?
- 有什么方法更像 ConTeXt 来进行注册定制?
- 您如何在中引用登记册的页码
\TextCommand
? - 如何才能删除(或抑制)两个句号的超链接?
主意
我尝试使用\item
s 将逐项列表应用于索引,但无法从逐项列表中删除垂直空间。
相关链接
答案1
有许多问题无法使用常规索引解决。以下解决方案执行多项任务:
- 覆盖
\startregisterentries
以添加条件设置\endgraf
。这\endgraf
导致章节标题与摄影师姓名分开。 - 使用 Lua 将作者姓名与索引条目标题进行比较。由于额外的 ,比较字符串是否相等失败,因此需要进行子字符串匹配
{
。 - 应用可传递到 Lua 代码中的自定义
\pagereference
。这对于将页码移至最终输出中的所需位置是必要的。
解决所有问题的一个可能的解决方案是:
\setupinteraction[
state=start,
color=red,
contrastcolor=red,
]
\setuphead[section][aftersection=\page,]
% Sections have a register defined for citing the photographer. In ConText,
% the registers are set up with a hanging indent for items defined with
% a + (e.g., Section+Author}. To prevent the Section title from being
% split, the \endgraf must be eliminated.
\define\RegularIndexStyle{\endgraf}
\define\PhotographIndexStyle{\empty}
\unprotect
\unexpanded\def\startregisterentries#1{
% Put the first-level items on the same line as the second-level items.
\IndexStyle
\begingroup
\scratchcounter\ifnum#1>\c_strc_registers_maxlevel\c_strc_registers_maxlevel\else#1\fi\relax
\dostarttagged\t!registerentries\empty
\let\savedcurrentregister\currentregister
\edef\currentregister{\currentregister:\number\scratchcounter}%
\useregisterstyleandcolor\c!textstyle\c!textcolor
\ifnum\scratchcounter>\plusone
\advance\leftskip\d_strc_registers_distance\relax
\fi
\hangindent\registerparameter\c!distance\relax
\hangafter\plusone
\let\currentregister\savedcurrentregister}
\protect
\startluacode
userdata = userdata or {}
function userdata.photographer(s, author, url)
i = string.find( s, author )
if i == nil then
context( "* \\bold{" .. s .. "}, \\currentregisterpageuserdata{pagenumber}." )
else
context( "\\href{" .. author .. "}{" .. url .. "}." )
end
end
\stopluacode
\define[2]\href{\begingroup\goto{\color[blue]{#1}}[url(#2)]\endgroup}
\define[1]\TextCommand{%
\ctxlua{userdata.photographer([==[#1]==], [==[\currentregisterpageuserdata{author}]==], [==[\currentregisterpageuserdata{authorurl}]==])}}
\define[1]\PageCommand{}
% #1 - Author; #2 - Author URL; #3 - Section title
\define[3]\PhotographCitation{%
\pagereference[#1#3]%
\setregisterentry[PhotographerIndex][entries={#3+#1}][
title={#3},
author={#1},
authorurl={#2},
pagenumber={\at[#1#3]},
]{}
}
\defineregister[PhotographerIndex][
n=1,
indicator=no,
distance=\zeropoint,
before=\empty,
compress=no,
textcommand=\TextCommand,
pagecommand=\PageCommand,
]
\starttext
\startsection[title={Maguro}]
Text
\PhotographCitation{Kenji Fujimoto}{http://bit.ly/1fNWF0Y}{Maguro}
\index{maguro}{maguro}
\stopsection
\startsection[title={Unagi}]
Text
\PhotographCitation{Kenji Fujimoto}{http://google.com}{Unagi}
\index{unagi}{unagi}
\stopsection
\startsection[title={Tamago}]
Text
\PhotographCitation{Chen Kenichi}{http://www.sisen.jp/}{Tamago}
\index{tamago}{tamago}
\stopsection
\define\IndexStyle\PhotographIndexStyle
\placePhotographerIndex
\page
\define\IndexStyle\RegularIndexStyle
\completeindex
\stoptext
生成: