如何使用s
以下示例中的出版物条目的(“短”)字段按字母顺序对参考书目列表条目进行排序?我不想使用 BibTeX 文件,而是使用命令start/stoppublication
。
\setuppublications[
alternative=apa-de,
criterium=text,
sorttype=cite, % "cite" oder "bbl" are supported, something like "short" needed
refcommand=short,
numbering=short,
autohang=yes,
setupinteraction=start,
]
\setuppublicationlist[
samplesize={AAAAAAA},
author=\invertedauthor,
artauthor=\invertedauthor,
]
%=== entries ===
\startpublication[
k=bh2008,
t=book,
a={Bringhurst},
y=2008,
n=1,
s={Elements},
]
\author[]{Robert}[]{}{Bringhurst}
\pubyear{2008}
\title{The Elements of Typographic Style}
\edition{3.2}
\city{Point Roberts WA, Vancouver}
\stoppublication
\startpublication[
k=taco1999,
t=article,
a=Hoekwater,
y=1999,
s=TH99,
n=1
]
\artauthor[]{Taco}[T.]{}{Hoekwater}
\arttitle{\CONTEXT\ Publication Module, The user documententation} \journal{MAPS}
\pubyear{To appear}
\note{This article}
\pages{66--76}
\stoppublication
\startpublication [
k=fielding2000,
t=phdthesis,
a={Fielding},
y=2000,
n=1,
s={FIE2000},
]
\author[]{Roy Thomas}[R. T.]{}{Fielding}
\title{Architectural Styles and
the Design of Network-based Software Architectures}
\pubname{University of California, Irvine}
\isbn{0-599-87118-0}
\stoppublication
%=== /entries ===
\starttext
Foo \cite[fielding2000]. Bar \cite[taco1999]. Baz \cite[bh2008]
\completepublications
\stoptext
其结果是:
但想要的顺序是:
- 元素
- 国际剑联2000
- TH99
一个可行的解决方案是按照正确的字母顺序编写出版物条目并设置sorttype=bbl
。但这太复杂了。
有没有简单的方法可以实现这个目标?
答案1
好的,这是一个 hackish 解决方案:因为我对 ConTeXt/LuaTeX 了解不多,所以我使用带有filter
模块的外部 Tcl 脚本对条目进行排序start-/stoppublication
。
分类机:
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh8.6 "$0" "$@"
if {$::argc != 2} {
puts stderr "Usage: $::argv0 {input file} {output file}"
exit 1
}
proc getShortname {entry} {
# maybe improve this quite optimistic regex
if {[regexp {\\startpublication\s*\[[^\]]*s=\{?(\w+)} $entry _ val]} {
return $val
} else {
return ""
}
}
proc compareEntry {arg1 arg2} {
return [string compare [getShortname $arg1] [getShortname $arg2]]
}
set inputFile [lindex $::argv 0]
set outputFile [lindex $::argv 1]
# read input file
set f [open $inputFile]
set fileContent [read $f]
close $f
# split publication entries to list
set bblList [regexp -inline -all -- {\\startpublication.*?\\stoppublication} $fileContent]
# sort publication list
set sortedBblList [lsort -command compareEntry $bblList]
# write sorted publication list
set f [open $outputFile w]
puts $f [join $sortedBblList "\n\n"]
close $f
为了保持简单,Tcl 脚本需要一个格式正确的输入文件。不进行任何错误检测。
主文本:
\usemodule[filter]
\defineexternalfilter
[bblsorter]
[filtercommand={./bblsorter \externalfilterinputfile\space \externalfilteroutputfile}]
\setuppublications[
alternative=apa-de,
criterium=text,
sorttype=bbl,
refcommand=short,
numbering=short,
autohang=yes,
setupinteraction=start,
]
\setuppublicationlist[
samplesize={AAAAAAA},
author=\invertedauthor,
artauthor=\invertedauthor,
]
%=== entries ===
\startbblsorter
\startpublication[
k=bh2008,
t=book,
a={Bringhurst},
y=2008,
n=1,
s={Elements},
]
\author[]{Robert}[]{}{Bringhurst}
\pubyear{2008}
\title{The Elements of Typographic Style}
\edition{3.2}
\city{Point Roberts WA, Vancouver}
\stoppublication
\startpublication[
k=taco1999,
t=article,
a=Hoekwater,
y=1999,
s=TH99,
n=1
]
\artauthor[]{Taco}[T.]{}{Hoekwater}
\arttitle{\CONTEXT\ Publication Module, The user documententation} \journal{MAPS}
\pubyear{To appear}
\note{This article}
\pages{66--76}
\stoppublication
\startpublication [
k=fielding2000,
t=phdthesis,
a={Fielding},
y=2000,
n=1,
s={FIE2000},
]
\author[]{Roy Thomas}[R. T.]{}{Fielding}
\title{Architectural Styles and
the Design of Network-based Software Architectures}
\pubname{University of California, Irvine}
\isbn{0-599-87118-0}
\stoppublication
\stopbblsorter
%=== /entries ===
\starttext
Foo \cite[fielding2000]. Bar \cite[taco1999]. Baz \cite[bh2008]
\completepublications
\stoptext
由于模块非常棒,这种方法行之有效,而且并不复杂filter
。但纯 ConTeXt 解决方案可能更好、更强大。