Skip to content

Commit

Permalink
update files
Browse files Browse the repository at this point in the history
  • Loading branch information
aFei-CQUT committed Dec 18, 2024
1 parent c059119 commit b31cf8c
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import "@preview/anti-matter:0.0.2": anti-front-end
#import "@preview/i-figured:0.2.4"
#import "../utils/anti-matter.typ": anti-front-end
#import "../utils/style.typ": 字号, 字体
#import "../utils/custom-numbering.typ": custom-numbering
#import "../utils/custom-heading.typ": heading-display, active-heading, current-heading
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "@preview/anti-matter:0.0.2": anti-matter
#import "../utils/anti-matter.typ": anti-matter

// 前言,重置页面计数器
#let preface(
Expand Down
4 changes: 3 additions & 1 deletion packages/preview/modern-cqut-thesis/0.1.0/lib.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#import "@preview/anti-matter:0.0.2": anti-inner-end as mainmatter-end
#import "layouts/doc.typ": doc
#import "layouts/preface.typ": preface
#import "layouts/mainmatter.typ": mainmatter
Expand All @@ -18,6 +17,8 @@
#import "pages/list-of-tables.typ": list-of-tables
#import "pages/notation.typ": notation
#import "pages/acknowledgement.typ": acknowledgement

#import "utils/anti-matter.typ": anti-inner-end as mainmatter-end
#import "utils/custom-cuti.typ": *
#import "utils/bilingual-bibliography.typ": bilingual-bibliography
#import "utils/custom-numbering.typ": custom-numbering
Expand All @@ -30,6 +31,7 @@
#import "utils/cite-style.typ": custom-cite



// 使用函数闭包特性,通过 `documentclass` 函数类进行全局信息配置,然后暴露出拥有了全局配置的、具体的 `layouts` 和 `templates` 内部函数。
#let documentclass(
doctype: "bachelor", // "bachelor" | "master" | "doctor" | "postdoc",文档类型,默认为本科生 bachelor
Expand Down
204 changes: 204 additions & 0 deletions packages/preview/modern-cqut-thesis/0.1.0/utils/anti-matter.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
// 导出 anti-matter 中的函数
#let (
anti-front-end,
anti-inner-end,
anti-outer-counter,
anti-inner-counter,
anti-active-counter-at,
anti-page-at,
anti-page,
anti-header,
anti-thesis,
anti-matter,
) = {
// TODO: 我认为可以移除spec,改用loc.page-numbering()

// 验证spec
let assert-spec-valid(spec) = {
if type(spec) != dictionary {
panic("spec必须是一个字典,而不是 " + type(spec))
}

if spec.len() != 3 {
panic("spec必须恰好包含3个元素,而不是 " + str(spec.len()))
}

if "front" not in spec { panic("缺少front键") }
if "inner" not in spec { panic("缺少inner键") }
if "back" not in spec { panic("缺少back键") }
}

let meta-label = <anti-matter:label>
let key-front-end = "anti-matter:front-end"
let key-inner-end = "anti-matter:inner-end"

// 获取给定位置的事项和修正
let where-am-i(spec, loc) = {
let markers = query(meta-label)

assert.eq(
markers.len(),
2,
message: "必须恰好有两个标记(不要使用 <anti-matter:meta>)"
)
assert.eq(markers.at(0).value, key-front-end, message: "第一个标记必须是前端标记")
assert.eq(markers.at(1).value, key-inner-end, message: "第二个标记必须是内部结束标记")

let front-matter = markers.first().location()
let inner-matter = markers.last().location()

let front-matter-end = counter(page).at(front-matter).at(0)
let inner-matter-end = counter(page).at(inner-matter).at(0)

if loc.page() <= front-matter.page() {
("front", spec.front, 0)
} else if front-matter.page() < loc.page() and loc.page() <= inner-matter.page() {
("inner", spec.inner, front-matter-end)
} else {
("back", spec.back, inner-matter-end - front-matter-end)
}
}

/// 标记文档前端事项的结束,将其放在前端事项的最后一页。
/// 确保将其放在尾随的`pagebreaks`之前。
///
/// -> content
let anti-front-end() = [#metadata(key-front-end) #meta-label]

/// 标记文档内部事项的结束,将其放在内部事项的最后一页。
/// 确保将其放在尾随的`pagebreaks`之前。
///
/// -> content
let anti-inner-end() = [#metadata(key-inner-end) #meta-label]

/// 返回文档前端和后端事项的计数器。
///
/// -> counter
let anti-outer-counter() = counter("anti-matter:outer")

/// 返回文档主要内容的计数器。
///
/// -> counter
let anti-inner-counter() = counter("anti-matter:inner")

/// 返回给定位置的活动计数器。这可用于在特定位置设置页面计数器。
///
/// - spec (dictionary): 文档的规格,参见 @@anti-matter
/// - loc (location): 获取活动计数器的位置
/// -> counter
let anti-active-counter-at(spec, loc) = {
let (matter, _, _) = where-am-i(spec, loc)

if matter == "inner" {
anti-inner-counter()
} else {
anti-outer-counter()
}
}

/// 使用默认规格,共享外部编号和计数器。
///
/// 返回的字典简单地包含`front`、`inner`和`back`键的编号。
///
/// - outer (string, function): 用于前端和后端事项的编号
/// - inner (string, function): 用于文档主要内容的编号
/// -> dictionary
let anti-thesis(outer: "I", inner: "1") = (
front: outer,
inner: inner,
back: outer,
)

/// 返回给定位置的页面编号,根据规格进行必要的调整和编号。
///
/// - spec (dictionary): 文档的规格,参见 @@anti-matter
/// - loc (location): 评估编号的位置
/// -> content
let anti-page-at(spec, loc) = {
let (_, num, correction) = where-am-i(spec, loc)

let vals = counter(page).at(loc)
vals.at(0) = vals.at(0) - correction

numbering(num, ..vals)
}

/// 返回给定位置的格式化页码,根据规格进行必要的调整和编号。
///
/// - spec (dictionary): 描述文档编号的规格,参见 @@anti-matter
/// -> content
let anti-page(spec) = context {
let loc = here()
anti-page-at(spec, loc)
}

/// 渲染页眉,同时维护anti-matter计数器步进。
///
/// - spec (dictionary): 描述文档编号的规格,参见 @@anti-matter
/// - header (content): 要渲染的页眉
/// -> content
let anti-header(spec, header) = {
context {
let loc = here()
anti-active-counter-at(spec, loc).step()
}
header
}

/// 应用页面编号和outline.entry的show规则以修复其页面编号的模板函数。
/// 如果需要更细粒度地控制大纲条目和页眉,请参阅库文档。
/// 这可以用于show规则。参数会被验证。
///
/// - spec (dictionary): 描述文档编号的规格,参见 @@anti-matter
/// - debug (bool): 在页眉中显示当前事项和相关信息
/// - body (content): 要使用anti-matter编号渲染的内容
/// -> content
let anti-matter(
spec: anti-thesis(),
debug: false,
body,
) = {
assert-spec-valid(spec)

set page(
header: if debug {
context {
let loc = here()
anti-header(spec)[
#let (matter, numbering, correction) = where-am-i(spec, loc)
#(matter: matter, numbering: numbering, correction: correction)
]
}
} else {
anti-header(spec, none)
},
numbering: (..args) => anti-page(spec),
)
show outline.entry: it => {
link(it.element.location(), it.body)
if it.fill != none {
[ ]
box(width: 1fr, it.fill)
[ ]
} else {
h(1fr)
}
link(it.element.location(), anti-page-at(spec, it.element.location()))
}

body
}

(
anti-front-end,
anti-inner-end,
anti-outer-counter,
anti-inner-counter,
anti-active-counter-at,
anti-page-at,
anti-page,
anti-header,
anti-thesis,
anti-matter,
)
}

0 comments on commit b31cf8c

Please sign in to comment.