pku-typst / pkuthss-typst

Typst template for dissertations in Peking University (PKU).
MIT License
87 stars 18 forks source link

Customize bibliography #6

Open lucifer1004 opened 1 year ago

werifu commented 1 year ago

A temporary solution: using show rule to customize bibliography.

typst is able to read yaml using yaml(path)(or other file): https://typst.app/docs/reference/data-loading/yaml/ and we can overwrite the bibliography with other formats like GBT-7714....

But this solution will lose the ability to reorder the references so that it only works well when the bibs are ordered correctly in the ref.yml file. I don't know how this can be improved before typst's support for custom bib

guyutongxue commented 1 year ago

FYI: patch the typst source code to make citations superscripted.

Now typst only support plain #cite style like [1], but we expect something like [1]. So I tried to modify the source code of typst to change this behavior.

Here is the diff:

diff --git a/library/src/meta/bibliography.rs b/library/src/meta/bibliography.rs
index 2bf0e6f4..3a3a49b3 100644
--- a/library/src/meta/bibliography.rs
+++ b/library/src/meta/bibliography.rs
@@ -547,6 +547,8 @@ fn create(

             if style == CitationStyle::ChicagoNotes {
                 content = FootnoteElem::new(content).pack();
+            } else {
+                content = crate::text::SuperElem::new(content).pack();
             }

             (location, Some(content))

Just clone typst repository, git apply this diff, and cargo build.

This is just a workaround; an official customizable option should be given in the future.