Skip to content

Commit

Permalink
use citext for cite
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuenhoy authored and Lucas-Wye committed Feb 27, 2025
1 parent 58b80ee commit b41f7ad
Show file tree
Hide file tree
Showing 18 changed files with 6,881 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
utils/citext/** linguist-vendored
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
)
#let doc = graduate-general(info: info, twoside: true)
#let doc = graduate-general(
info: info,
twoside: true,
bibsource: read("ref.bib"),
)
#show: doc.style
#doc.pages.cover
Expand All @@ -58,9 +62,7 @@
= Hello
== World
#individual("参考文献", outlined: true)[
#bibliography("ref.bib", style: "gb-7714-2015-numeric", title: none)
]
#doc.pages.bibliography
#individual("附录", outlined: true)[
#appendix(level: 1)[
Expand Down
23 changes: 18 additions & 5 deletions documentclass/graduate-general.typ
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import "../pages/graduate-title-zh.typ": graduate-title-zh
#import "../pages/graduate-title-en.typ": graduate-title-en
#import "../pages/graduate-decl.typ": graduate-decl
#import "../pages/bibliography.typ": bibliography-page
#import "../pages/template-individual.typ": template-individual
#import "../pages/outline.typ": main-outline, figure-outline, table-outline

Expand All @@ -11,7 +12,7 @@
#import "../utils/supplement.typ": show-set-supplement
#import "../utils/twoside.typ": show-twoside-pagebreak, twoside-numbering-footer, twoside-pagebreak
#import "../utils/near-chapter.typ": near-chapter
#import "../utils/bilingual-bibliography.typ": show-bilingual-bibliography
#import "../utils/bib-provider.typ": bib-provider
#import "../utils/structure.typ": frontmatter, mainmatter
#import "../utils/appendix.typ": appendix

Expand Down Expand Up @@ -107,13 +108,21 @@
show figure.where(kind: "algorithm"): set figure.caption(position: top)
show figure.where(kind: "listing"): set figure(supplement: [代码])

show: show-bilingual-bibliography
doc
}


#let graduate-general(info: (:), twoside: false) = {
#let graduate-general(
info: (:),
twoside: false,
bibsource: "",
bibmode: "citext",
) = {
assert(bibmode == "citext" or bibmode == "bilingual")
let info = graduate-general-default-info + info
let individual = template-individual.with(outlined: true, titlelevel: 1, bodytext-settings: (size: 字号.小四))

let bib = bib-provider(bibsource, mode: bibmode)
(
pages: (
cover: graduate-cover(info: info),
Expand All @@ -123,11 +132,15 @@
outline: show-outline(main-outline(outlined: true, titlelevel: 1)),
figure-outline: figure-outline(outlined: true, titlelevel: 1),
table-outline: table-outline(outlined: true, titlelevel: 1),
individual: template-individual.with(outlined: true, titlelevel: 1, bodytext-settings: (size: 字号.小四)),
individual: individual,
bibliography: bibliography-page(bib: bib.bibcontent, individual: individual),
),
style: doc => {
set document(title: info.title.join())
graduate-general-set-style(doc, degree: info.degree, twoside: twoside)
let doc = graduate-general-set-style(doc, degree: info.degree, twoside: twoside)

show: bib.bibshow
bib.hiddenbib + doc
},
)
}
28 changes: 23 additions & 5 deletions documentclass/undergraduate-cs.typ
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import "../pages/undergraduate-decl.typ": undergraduate-decl
#import "../pages/template-individual.typ": template-individual
#import "../pages/outline.typ": main-outline
#import "../pages/bibliography.typ": bibliography-page
#import "../pages/undergraduate-task.typ": undergraduate-task
#import "../pages/undergraduate-eval.typ": undergraduate-eval
#import "../pages/undergraduate-proposal-cover.typ": undergraduate-proposal-cover
Expand All @@ -10,6 +11,7 @@

#import "../utils/fonts.typ": *
#import "../utils/part.typ": show-part, show-outline-with-part, part-and-headings, part, part-bib
#import "../utils/bib-provider.typ": bib-provider
#import "../utils/header.typ": header, footer
#import "../utils/fakebold.typ": show-cn-fakebold
#import "../utils/supplement.typ": show-set-supplement
Expand All @@ -20,7 +22,7 @@
#import "../dependency/i-figured.typ"


#let undergraduate-cs-set-style(doc, twoside: true) = {
#let undergraduate-cs-set-style(doc, twoside: true, bibmode: "part") = {
// Page geometry
set page(
paper: "a4",
Expand Down Expand Up @@ -90,7 +92,7 @@
show figure.where(kind: table): set figure.caption(position: top)

// Part
show: show-part
show: show-part.with(enable-ref: bibmode == "partbib")
show: show-outline-with-part


Expand All @@ -110,8 +112,17 @@
submit-date: datetime.today(),
)

#let undergraduate-cs(info: (:), twoside: true) = {
#let undergraduate-cs(
info: (:),
twoside: true,
bibsource: "",
bibmode: "citext",
) = {
assert(bibmode == "citext" or bibmode == "partbib")

let info = undergraduate-cs-default-info + info
let bib = bib-provider(bibsource, mode: bibmode)

(
pages: (
cover: undergraduate-cover(info: info),
Expand All @@ -120,15 +131,22 @@
task: undergraduate-task.with(info: info),
individual: template-individual,
eval: undergraduate-eval,
bibliography: bibliography-page(bib: bib.bibcontent, individual: template-individual),
proposal-cover: undergraduate-proposal-cover(info: info),
proposal-task: undergraduate-proposal-task.with(info: info),
proposal-eval: undergraduate-proposal-eval,
),
components: (
bibliography: bib.bibcontent,
new-bib: bib.new-bib,
),
style: doc => {
set document(title: info.title.join())
show bibliography: none

undergraduate-cs-set-style(doc, twoside: twoside)
let doc = undergraduate-cs-set-style(doc, twoside: twoside, bibmode: bibmode)
show: bib.bibshow

bib.hiddenbib + doc
},
)
}
13 changes: 9 additions & 4 deletions examples/graduate-general.typ
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
submit-date: "递交日期",
)

#let doc = graduate-general(info: info, twoside: true)
#let doc = graduate-general(
info: info,
twoside: true,
bibsource: read("ref.bib"),
bibmode: "citext",
)
#show: doc.style


Expand All @@ -35,6 +40,7 @@
#individual("摘 要")[]
#individual("Abstract")[]


#doc.pages.outline
#doc.pages.figure-outline
#doc.pages.table-outline
Expand All @@ -43,9 +49,8 @@

#include "common-body.typ"

#individual("参考文献", outlined: true)[
#bibliography("ref.bib", style: "gb-7714-2015-numeric", title: none)
]
#doc.pages.bibliography


#individual("附录", outlined: true)[
#appendix(level: 1)[
Expand Down
4 changes: 2 additions & 2 deletions examples/ref.bib
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
% use `texdoc biblatex` to get help
@www{zjuthesisrules,
title = {浙江大学本科生毕业论文(设计)编写规则},
author = {浙江大学本科生院},
Expand Down Expand Up @@ -42,7 +41,8 @@ @article{WANG2022102149
year = {2022},
issn = {0167-8396},
author = {Shiyi Wang and Jiong Chen and Xifeng Gao and Hujun Bao and Jin Huang},
keywords = {Atlas packing, Surface cut, Parameterization, Cone singularity}
keywords = {Atlas packing, Surface cut, Parameterization, Cone singularity},
language = {en-US}
}

@article{chCurl,
Expand Down
25 changes: 18 additions & 7 deletions examples/undergraduate-cs.typ
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
)


#let doc = undergraduate-cs(info: info, twoside: true)
#let doc = undergraduate-cs(
info: info,
twoside: true,
bibsource: read("ref.bib"),
bibmode: "citext",
)
#show: doc.style

#doc.pages.cover
Expand All @@ -35,15 +40,14 @@
#part[毕业论文]
#include "common-body.typ"

#bibliography("ref.bib", style: "gb-7714-2015-numeric")
#individual("参考文献", outlined: true)[
#part-bib
]
#doc.pages.bibliography

#individual("附录", outlined: true)[
#appendix[
=== 一个附录 <app1>
这里是附录。
@app1
@WANG2022102149
=== 另一个附录

]
Expand Down Expand Up @@ -73,16 +77,23 @@


#counter(page).update(0)
#(doc.components.new-bib)()

= 文献综述

这里是文献综述。

@zjugradthesisrules

== 参考文献
#part-bib
#doc.components.bibliography

= 开题报告
#(doc.components.new-bib)()

== 参考文献
#part-bib
#doc.components.bibliography

= 外文翻译
= 外文原文

Expand Down
8 changes: 8 additions & 0 deletions pages/bibliography.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import "./template-individual.typ": template-individual

#let bibliography-page(bib: auto, individual: auto) = {
individual(
"参考文献",
bib,
)
}
36 changes: 36 additions & 0 deletions utils/bib-provider.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

#let bib-provider(bibsource, mode: "") = {
let typstbib = bibliography(bytes(bibsource), style: "gb-7714-2015-numeric", title: none)
let hiddenbib = [
#show bibliography: none // to provide hint in the editor
#typstbib
]
if mode == "bilingual" {
import "./bilingual-bibliography.typ": show-bilingual-bibliography

(
bibcontent: typstbib,
bibshow: show-bilingual-bibliography,
hiddenbib: none,
new-bib: () => (),
)
} else if (mode == "citext") {
import "./citext/lib.typ": *
let bib = init-citation(bibsource)

(
bibcontent: extbib(bib),
bibshow: show-extcite.with(bib: bib, gen-id: true),
hiddenbib: hiddenbib,
new-bib: new-citext-session,
)
} else if (mode == "partbib") {
import "./part.typ": *
(
bibcontent: part-bib,
bibshow: x => x,
hiddenbib: hiddenbib,
new-bib: () => part-refs.update(()),
)
}
}
21 changes: 21 additions & 0 deletions utils/citext/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 mgt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions utils/citext/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This folder is copied from https://github.com/Shuenhoy/citext

Any changes should be made there first.
Loading

0 comments on commit b41f7ad

Please sign in to comment.