Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/preview/modern-hkust-thesis/0.1.1/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 jlu625

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.
26 changes: 26 additions & 0 deletions packages/preview/modern-hkust-thesis/0.1.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Typst is a next-generation typesetting system, designed as a modern alternative to LaTeX. Written in Rust, it offers the advantages of user-friendly syntax and fast compilation.

This template was created by me for my own graduation project, and it meets [all the formatting requirements of HKUST-GZ](https://fytgs.hkust-gz.edu.cn/wp-content/uploads/2025/10/Guidelines-on-Thesis-Preparation.pdf).
If you find it useful, you can [buy me a ☕️ coffee here](https://www.buymeacoffee.com/jwangl5). Thanks! ☺️
If you encounter any issues, feel free to open a ticket in the issue tracker.
Contributions are also welcome.

---

### Usage

+ Just click the `Creat project in app` on right concer ↗️, and start your writing!

+ Or If you want to run locally, you can use `vscode` and its plugins `Tinymist` to setup environment easily. Just download `typst` and run the command to acquire this template.
```bash
typst init @preview/modern-hkust-thesis:0.1.0
```

+ If you need modify any styles, you can also clone this repo to your local directory, or just download all files from this repo. Open the folder with vscode, then you could modify the `sample.typ` file to finish your thesis.
```git
git clone http://gitlab.hkust-gz.edu.cn/jlu625/typst-thesis-template.git
```

I have already written enough comments in sample file to make sure you could understand how to modify the text with your own info ☺️, feel free to modify the text and preview what you got (shortcut key `ctrl+k v`).

If you have problems in using `typst`, you can read [official documents here](https://typst.app/docs/).
207 changes: 207 additions & 0 deletions packages/preview/modern-hkust-thesis/0.1.1/lib/abbr.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
#import "@preview/titleize:0.1.1": titlecase

#let stringify(text) = {
if type(text) == str {
return text
}
if "text" in text.fields() {
return text.text
}
panic("Cannot stringify")
}

#let get(short) = {
let key = stringify(short)
let entry = state("abbr", (:)).get().at(key, default:none)
return (key, entry)
}

#let warn(short) = [*(?? #short ??)*]

#let style-default(short) = {
let val = if text.weight <= "medium" { 15% } else { 30% }
set text(fill: black.lighten(val))
show: strong
short
}

#let space-default = sym.space.nobreak.narrow

#let mark-first(key, dct) = {
if not dct.frst { return }
dct.frst=false
state("abbr").update(it=>{
it.insert(key, dct)
return it
})
}

#let mark-used(key, dct) = {
if dct.list { return }
dct.list = true
state("abbr").update(it=>{
it.insert(key, dct)
return it
})
}

/// add single entry
#let add(short, ..entry) = context {
let long = entry.at(0)
let plural = entry.at(1, default:none)
let (key, entry) = get(short)
if entry == none { // do not update blindly, it'd reset the counter
state("abbr").update(it => {
let item = (
l: long,
pl: plural,
lbl: label(short + sym.hyph.point + long),
frst: true,
list: false,
)
it.insert(short, item)
return it
})
}
}

/// add list of entries
#let make(..lst) = for (..abbr) in lst.pos() { add(..abbr) }

/// add abbreviations from csv file
#let load(..filename, delimiter:",") = {
let notempty(s) = { return s != "" }
let entries = read(..filename).split("\n")
.filter(notempty)
.map(entry => csv(bytes(entry),delimiter:delimiter)
.flatten().map(str.trim).filter(notempty)
)
make(..entries)
}

/// short form of abbreviation with link
#let s(short) = context {
let (key, dct) = get(short)
if dct == none { return warn(short) }
mark-used(key, dct)
let styleit = state("abbr-style", style-default).get()
if query(dct.lbl).len() != 0 {
link(dct.lbl, styleit(key))
} else {
styleit(key)
}
}

/// long form of abbreviation
#let l(short) = context {
let (key, dct) = get(short)
if dct == none { return warn(short) }
mark-first(key, dct)
dct.l
state("abbr-space", space-default).get()
sym.paren.l
sym.zwj
s(key)
sym.zwj
sym.paren.r
}

/// long form _only_
#let lo(short) = context {
let dct = get(short).at(1)
if dct == none { return warn(short) }
dct.l
}

/// automatic short/long form
#let a(short) = context {
let (key, dct) = get(short)
if dct == none { return warn(short); }
if dct.frst { l(key) }
else { s(key) }
}

/// short form plural
#let pls(short) = context {
let styleit = state("abbr-style", style-default).get()
[#s(short)#styleit[s]]
}

/// long form plural
#let pll(short) = context {
let (key, dct) = get(short)
if dct == none { return warn(short) }
mark-first(key, dct)
if dct.pl != none {
dct.pl
} else {
[#dct.l\s]
}
state("abbr-space", space-default).get()
sym.paren.l
sym.zwj
pls(key)
sym.zwj
sym.paren.r
}

/// long form plural _only_
#let pllo(short) = context {
let dct = get(short).at(1)
if dct == none { return warn(short) }
if dct.pl != none {
dct.pl
} else {
[#dct.l\s]
}
}

/// automatic short/long form plural
#let pla(short) = context {
let (key, dct) = get(short)
if dct == none { return warn(short); }
if dct.frst { pll(key) }
else { pls(key) }
}

/// create list of abbreviations
#let list(
title: [List of Abbreviations],
col: 1,
) = context {
let lst = state("abbr", (:)).final().pairs()
.filter(it => it.at(1).list)
.map(pair => (s: pair.at(0), l: titlecase(pair.at(1).l), lbl: pair.at(1).lbl))
.sorted(key: it => it.s)
if lst.len() == 0 { return }
let styleit = state("abbr-style", style-default).get()
let make-entry(e) = (styleit[#e.s #e.lbl], e.l)
if col == 2 {
let n = int(lst.len()/2)
let last = if calc.odd(lst.len()) {lst.remove(n)}
lst = lst.slice(0, n).zip(lst.slice(n)).flatten()
if last != none { lst.push(last) }
} else if col != 1 {
panic("abbr.list only supports 1 or 2 columns")
}
heading(numbering: none, title)
columns(col)[
#table(
columns: (auto, 1fr),
stroke:none,
..for entry in lst { make-entry(entry) }
)
]

}

/// configure styling of abbreviations
#let config(style: auto, space-char: sym.space.nobreak.narrow) = {
state("abbr-style", style-default).update(it => {
if style == auto {
return style-default
}
return style
})
state("abbr-space", space-default).update(it => space-char)
}
Loading