diff --git a/docs/function-types.typ b/docs/function-types.typ new file mode 100644 index 0000000..032f080 --- /dev/null +++ b/docs/function-types.typ @@ -0,0 +1,49 @@ +#let theorem-kind = (link-to: 0, numbering: 0) + +/// TODO +/// +/// - name (content, str): The name of the #ref-type("theorem"). +/// - link-to (label, selector, selector-function, none): Link the #ref-type("theorem") +/// to some other content. For #ref-type("label")s and #ref-type("selector")s the last +/// match before the #ref-type("theorem") is used. +/// - numbering (theorem-numbering-function, none): See #ref-type("theorem-numbering-function") +/// for more information. Can be set to #ref-type("none") for unnumbered #ref-type("theorem")s. +/// - body (content): +/// -> theorem +#let theorem-function(name: none, link-to: theorem-kind.link-to, numbering: theorem-kind.numbering, body) = 0 + +/// Create combined numberings from `theorem` and the content linked to it. +/// +/// There are two pre-defined #ref-type("theorem-numbering-function")s: @@numbering-concat() and @@numbering-proof(). +/// +/// - thm (theorem): The `theorem` for which the numbering should be generated. +/// See also @@get-theorem-parameters(). +/// - referenced (bool): This is false if +/// the numbering was requested from the `theorem` it belongs to. +/// Otherwise it is false. See @@numbering-proof() as an example. +/// -> content +#let theorem-numbering-function(thm, referenced) = 0 + +/// Defines how the #ref-type("theorem") will look. Use @@get-theorem-parameters() to get +/// all information stored in the #ref-type("theorem"). +/// +/// There are two pre-defined #ref-type("style-function")s: @@style-simple() and @@style-reversed(). +/// +/// - thm (theorem): +/// -> content +#let style-function(thm) = 0 + +/// Useful for more advanced queries. See @@last-heading() for an example. +/// +/// - loc (location): When used in `link-to` parameter +/// of some #ref-type("theorem") its #ref-type("location") +/// will be passed when resolving the link with @@resolve-link(). +/// -> content, none +#let selector-function(loc) = 0 + +/// A normal numbering function as described +/// in the #show-link("https://typst.app/docs/reference/meta/numbering/#parameters-numbering")[typst documentation]. +/// +/// - ..state (int): +/// -> content +#let numbering-function(..state) = 0 diff --git a/docs/generate_readme.py b/docs/generate_readme.py index 1436461..572c1a8 100644 --- a/docs/generate_readme.py +++ b/docs/generate_readme.py @@ -57,13 +57,15 @@ def convert_to_markdown(content): elif element["func"] == "text": result += element["text"] + "\n" elif element["func"] == "raw": - result += "```" + element["lang"] + "\n" + element["text"] + "\n" + "```\n\n" - elif element["func"] == "metadata": + result += "```" + element["lang"] + "\n" + element["text"] + "\n" + "```\n" + elif element["func"] == "metadata" and "code" in element["value"]: with open(file_name(), mode="w") as file: file.write(element["value"]["code"]) compile_file() result += f"\n![image]({image_name()})\n" GENERATED_IMAGE_COUNT += 1 + elif element["func"] == "metadata" and "text" in element["value"]: + result += element["value"]["text"] + "\n" elif element["func"] == "enum": element = element["children"][0] result += str(element["number"]) + ". " + element["body"]["text"] + "\n" diff --git a/docs/images/image_0.png b/docs/images/image_0.png index 586dca1..32dae4b 100644 Binary files a/docs/images/image_0.png and b/docs/images/image_0.png differ diff --git a/docs/readme.pdf b/docs/readme.pdf index 2c9eb29..337066a 100644 Binary files a/docs/readme.pdf and b/docs/readme.pdf differ diff --git a/docs/readme.typ b/docs/readme.typ index ee58715..698ffe1 100644 --- a/docs/readme.typ +++ b/docs/readme.typ @@ -36,6 +36,10 @@ return (scope, code) } +#let export-only(text) = [ + #metadata((text: text)) +] + #show enum: it => [#it ] = Lemmify @@ -47,6 +51,8 @@ This means that the interface might change with updates to typst (for example if user-defined element functions are introduced). But no functionality should be lost. +#export-only("\nIf you are encountering any bugs, have questions or are missing features, feel free to open an issue on [GitHub](\"https://github.com/Marmare314/lemmify\").") + == Basic usage 1. Import the Lemmify library @@ -73,10 +79,16 @@ But no functionality should be lost. ``` #step3 -4. Customize the styling using show rules. For example, to add a red box around proofs +4. Customize the styling using show rules. For example, to add a block around proofs #let step4 = ```typst -#show select-kind(proof): box.with(stroke: red + 1pt, inset: 1em) +#show select-kind(proof): block.with( + breakable: true, + width: 100%, + fill: gray, + inset: 1em, + radius: 5pt +) ``` #step4 @@ -87,6 +99,10 @@ But no functionality should be lost. Theorem content goes here. ] +#theorem(numbering: none)[ + Another theorem. +] + #proof(link-to: )[ Complicated proof. ] @@ -103,6 +119,12 @@ The result should now look something like this export-setup: "#set page(width: 300pt, height: auto, margin: 10pt)" ) +The default-theorems function has one more parameter max-reset-level +which controls on which headings the group counters are reset. +By default they will be reset on every heading. +To customize the look and behaviour of the theorems there +are some more parameters available. + == Examples This example shows how corollaries can be numbered after the last theorem. @@ -183,8 +205,3 @@ This example shows how corollaries can be numbered after the last theorem. -// are missing features, feel free to open an issue on -// #link("https://github.com/Marmare314/lemmify")[GitHub] -// . diff --git a/docs/source_docs.typ b/docs/source_docs.typ index dd977da..246756a 100644 --- a/docs/source_docs.typ +++ b/docs/source_docs.typ @@ -1,41 +1,130 @@ -#import "@preview/tidy:0.1.0": parse-module, show-module - -#let lib-parsed = parse-module(read("../src/lib.typ")) -#let reset-counter-parsed = parse-module(read("../src/reset-counter.typ")) -#let selectors-parsed = parse-module(read("../src/selectors.typ")) -#let styles-parsed = parse-module(read("../src/styles.typ")) -#let numbered-parsed = parse-module(read("../src/numbered.typ")) -#let theorem-parsed = parse-module(read("../src/theorem.typ")) +#import "@preview/tidy:0.1.0": parse-module, show-module, styles + +#let custom-type-colors = ( + "theorem-function": rgb("#f9dfff"), + "theorem-numbering-function": rgb("#f9dfff"), + "numbering-function": rgb("#f9dfff"), + "style-function": rgb("#f9dfff"), + "selector-function": rgb("#f9dfff"), + "theorem": rgb("#fff173"), + "numbered": rgb("#bfb3ff") +) + +#let type-colors = ( + "content": rgb("#a6ebe6"), + "color": rgb("#a6ebe6"), + "str": rgb("#d1ffe2"), + "none": rgb("#ffcbc4"), + "auto": rgb("#ffcbc4"), + "bool": rgb("#ffedc1"), + "int": rgb("#e7d9ff"), + "float": rgb("#e7d9ff"), + "ratio": rgb("#e7d9ff"), + "length": rgb("#e7d9ff"), + "angle": rgb("#e7d9ff"), + "relative-length": rgb("#e7d9ff"), + "fraction": rgb("#e7d9ff"), + "symbol": rgb("#eff0f3"), + "array": rgb("#eff0f3"), + "dictionary": rgb("#eff0f3"), + "arguments": rgb("#eff0f3"), + "selector": rgb("#eff0f3"), + "module": rgb("#eff0f3"), + "stroke": rgb("#eff0f3"), + "function": rgb("#f9dfff"), + ..custom-type-colors +) + +#let get-type-color(type) = type-colors.at(type, default: rgb("#eff0f3")) + +#let link-color = blue.darken(50%) + +#let ref-type(type, text-color: link-color) = { + if type in custom-type-colors { + link(label(type + "()"), text(text-color, raw(type))) + } else { + text(text-color, raw(type)) + } +} + +#let show-link(url, txt) = { + link(url)[#text(link-color, txt)] +} + +#let show-type(type) = { + h(2pt) + box(outset: 2pt, fill: get-type-color(type), radius: 2pt, ref-type(type, text-color: black)) + h(2pt) +} + +#let style = ( + show-type: show-type, + show-outline: styles.default.show-outline, + show-function: styles.default.show-function, + show-parameter-list: styles.default.show-parameter-list, + show-parameter-block: styles.default.show-parameter-block +) + +#let parse-module-params = ( + scope: ( + ref-type: ref-type, + show-link: show-link + ) +) + +#let show-module-params = ( + style: style, + show-module-name: false, + show-outline: false, + sort-functions: none, +) + +#let lib-parsed = parse-module(read("../src/lib.typ"), ..parse-module-params) +#let reset-counter-parsed = parse-module(read("../src/reset-counter.typ"), ..parse-module-params) +#let selectors-parsed = parse-module(read("../src/selectors.typ"), ..parse-module-params) +#let styles-parsed = parse-module(read("../src/styles.typ"), ..parse-module-params) +#let numbered-parsed = parse-module(read("../src/numbered.typ"), ..parse-module-params) +#let theorem-parsed = parse-module(read("../src/theorem.typ"), ..parse-module-params) +#let function-types-parsed = parse-module(read("function-types.typ"), ..parse-module-params) = Documentation -#show-module(lib-parsed) +#show-module(lib-parsed, ..show-module-params) -== Styles +== Function types -There are a few pre-defined `style-function`s and `theorem-numbering-function`s. +#show-module(function-types-parsed, ..show-module-params) -#show-module(styles-parsed) +== theorem +#label("theorem()") -== Selectors +A #ref-type("theorem") is a #ref-type("figure") with some additional +information stored in one of its parameters. -The selectors can be used in show-rules to -customize the `theorem`s styling as well as -with the `link-to` parameter. +#show-module(theorem-parsed, ..show-module-params) -#show-module(selectors-parsed) +== numbered +#label("numbered()") -== Resetting counters +A #ref-type("numbered") is a #ref-type("heading"), #ref-type("page"), +#ref-type("math.equation") or #ref-type("figure") that is already embedded +in the document (that means it was obtained by a query). The `numbering` +also has to be different from #ref-type("none"). -#show-module(reset-counter-parsed) +#show-module(numbered-parsed, ..show-module-params) -== Theorem utilities +== Styles -The functions in the remaining two sections are only needed when defining custom style or -theorem-numbering-functions. +#show-module(styles-parsed, ..show-module-params) -#show-module(theorem-parsed) +== Selectors + +The selectors can be used in show-rules to +customize the #ref-type("theorem")s styling as well as +with the `link-to` parameter. + +#show-module(selectors-parsed, ..show-module-params) -== Numbered utilities +== Resetting counters -#show-module(numbered-parsed) +#show-module(reset-counter-parsed, ..show-module-params) diff --git a/src/lib.typ b/src/lib.typ index 580af41..0518329 100644 --- a/src/lib.typ +++ b/src/lib.typ @@ -8,26 +8,23 @@ #let LEMMIFY-DEFAULT-THEOREM-GROUP = "LEMMIFY-DEFAULT-THEOREM-GROUP" #let LEMMIFY-DEFAULT-PROOF-GROUP = "LEMMIFY-DEFAULT-PROOF-GROUP" -/// Create a new theorem function. The style is only visible -/// once the `theorem-rules` have been applied. -/// The generated functions will be referred to as `kind-function`s -/// and the `figures` created by it will be referred to as `theorem`s. +/// Creates a new #ref-type("theorem-function"). /// -/// - kind-name (str): The name of the theorem kind. It acts -/// as an identifier together with `group` when using `select-kind`, -/// so it should be unique. +/// - kind-name (str): The name of the theorem kind. It also acts +/// as an identifier together with `group` when using `select-kind`, +/// so it should be unique. /// - group (str): The group identifier. Each theorem group shares one counter. -/// - link-to (label, selector, selector-function, none): Link the `theorem` to some -/// other content. See `numbering-concat` for how this is used. For `label`s and `selector`s the last one before the `theorem` is used. `selector-function`s are functions `(location) -> content` which can be used for -/// more advanced queries. -/// - numbering (theorem-numbering-function): A function `(theorem, bool) -> content`. -/// The `bool` argument is true only if -/// the numbering is requested from a reference -/// instead of from the theorem itself (see numbering-proof). +/// - link-to (label, selector, selector-function, none): This parameter sets +/// what the #ref-type("theorem")s created by the #ref-type("theorem-function") will be linked to +/// by default. +/// - numbering (theorem-numbering-function, none): Specify a default value for +/// the `numbering` parameter of the #ref-type("theorem-function"). /// - subnumbering (numbering-function, str, none): The subnumbering is -/// needed to convert the theorems counter to content, -/// which is then used in the `theorem-numbering-function`. -/// - style (style-function): A function `(thm) -> content` which is used to style the theorem. +/// needed to convert the #ref-type("theorem")s counter to content, +/// which is then used in the #ref-type("theorem-numbering-function"). +/// - style (style-function): Specifies how the #ref-type("theorem")s will look. This will only be +/// visible once the @@theorem-rules() have been applied. +/// -> theorem-function #let theorem-kind( kind-name, group: LEMMIFY-DEFAULT-THEOREM-GROUP, @@ -39,7 +36,7 @@ assert-type(kind-name, "kind-name", str) assert-type(group, "group", str) assert-type(link-to, "link-to", label, selector, function, None) - assert-type(numbering, "numbering", function) + assert-type(numbering, "numbering", function, None) assert-type(subnumbering, "subnumbering", function, str, None) assert-type(style, "style", function) @@ -60,7 +57,7 @@ ) } -/// Apply the style of every `theorem` and handle references to `theorem`s. +/// Apply the style of every #ref-type("theorem") and handle references to #ref-type("theorem")s. /// /// - content (content): /// -> content @@ -91,17 +88,21 @@ /// Generate a few common theorem kinds in the specified language. /// -/// This function accepts all parameters of `theorem-kind` once for proofs and +/// Returns a dictionary of the form +/// `(theorem, lemma, corollary, remark, proposition, example, definition, proof, theorem-rules)`. +/// The `theorem-rules` can be applied using a show statement. If `max-reset-level` is `none` +/// it will be the same as @@theorem-rules(). +/// +/// This function accepts all parameters of @@theorem-kind() once for proofs and /// once for all kinds except for proofs. -/// So for information on the missing parameters refer to `theorem-kind`. /// /// - group (str): /// - proof-group (str): /// - lang (str): The language in which the theorem kinds are generated. /// - style (style-function): /// - proof-style (style-function): -/// - numbering (theorem-numbering-function): -/// - proof-numbering (theorem-numbering-function): +/// - numbering (theorem-numbering-function, none): +/// - proof-numbering (theorem-numbering-function, none): /// - link-to (label, selector, selector-function, none): /// - proof-link-to (label, selector, selector-function, none): /// - subnumbering (numbering-function, str, none): @@ -128,8 +129,8 @@ assert-type(lang, "lang", str) assert-type(style, "style", function) assert-type(proof-style, "proof-style", function) - assert-type(numbering, "numbering", function) - assert-type(proof-numbering, "proof-numbering", function) + assert-type(numbering, "numbering", function, None) + assert-type(proof-numbering, "proof-numbering", function, None) assert-type(link-to, "link-to", label, selector, function, None) assert-type(proof-link-to, "proof-link-to", label, selector, function, None) assert-type(subnumbering, "subnumbering", function, str, None) diff --git a/src/numbered.typ b/src/numbered.typ index c60df9e..dd74c3d 100644 --- a/src/numbered.typ +++ b/src/numbered.typ @@ -44,10 +44,7 @@ ) } -/// Check if argument is numbered. -/// That means it is one of -/// `heading`, `page`, `math.equation` or `figure` -/// and its numbering is not `none`. +/// Check if argument is #ref-type("numbered"). /// /// - n (any): /// -> bool diff --git a/src/reset-counter.typ b/src/reset-counter.typ index e97eef0..e003a09 100644 --- a/src/reset-counter.typ +++ b/src/reset-counter.typ @@ -12,33 +12,33 @@ /// Reset theorem group counter to zero. /// The result needs to be added to the document. /// -/// - kind-func (kind-function): The group is obtained from this kind function. +/// - thm-func (theorem-function): The group is obtained from this argument. /// -> content -#let reset-counter(kind-func) = { - assert-type(kind-func, "kind-func", function) - return counter(select-group(kind-func)).update(c => 0) +#let reset-counter(thm-func) = { + assert-type(thm-func, "thm-func", function) + return counter(select-group(thm-func)).update(c => 0) } /// Reset counter of theorem group /// on headings with at most the specified level. /// -/// - kind-func (kind-function): The group is obtained from this kind function. +/// - thm-func (theorem-function): The group is obtained from this argument. /// - max-level (int): Should be at least 1. /// - content (content): /// -> content #let reset-counter-heading( - kind-func, + thm-func, max-level, content ) = { - assert-type(kind-func, "kind-func", function) + assert-type(thm-func, "thm-func", function) assert-type(max-level, "max-level", int) assert(max-level >= 1, message: "max-level should be at least 1") let rules = range(1, max-level + 1).map( k => content => { show heading.where(level: k): it => { - reset-counter(kind-func) + reset-counter(thm-func) it } content diff --git a/src/selectors.typ b/src/selectors.typ index 2cceba3..26c593f 100644 --- a/src/selectors.typ +++ b/src/selectors.typ @@ -48,23 +48,23 @@ /// theorems of the same group as the /// argument. /// -/// - kind-func (kind-function): +/// - thm-func (theorem-function): /// -> selector -#let select-group(kind-func) = { - assert-type(kind-func, "kind-func", function) - let params = get-theorem-parameters(kind-func[]) +#let select-group(thm-func) = { + assert-type(thm-func, "thm-func", function) + let params = get-theorem-parameters(thm-func[]) return figure.where(kind: params.group) } /// Generate selector that selects only /// theorems that were create from -/// the provided `kind-function`. +/// the #ref-type("theorem-function"). /// -/// - kind-func (kind-function): +/// - thm-func (theorem-function): /// -> selector -#let select-kind(kind-func) = { - assert-type(kind-func, "kind-func", function) +#let select-kind(thm-func) = { + assert-type(thm-func, "thm-func", function) - let params = get-theorem-parameters(kind-func[]) + let params = get-theorem-parameters(thm-func[]) return figure.where(kind: params.group, supplement: [#params.kind-name]) } diff --git a/src/styles.typ b/src/styles.typ index bfb5f96..63a8c2d 100644 --- a/src/styles.typ +++ b/src/styles.typ @@ -3,7 +3,7 @@ #import "types.typ": assert-type /// If the linked content is numbered combine it with the numbering -/// of the theorem. +/// of the #ref-type("theorem"). /// /// - thm (theorem): /// - referenced (bool): @@ -18,7 +18,7 @@ display-numbered(thm) } -/// Copy the numbering of a linked `theorem` if referenced. +/// Copy the numbering of a linked #ref-type("theorem") if referenced. /// Otherwise no numbering is returned. /// /// - thm (theorem): @@ -57,7 +57,7 @@ }) } -/// Reverses numbering and `kind-name`. +/// Reverses numbering and `kind-name`, otherwise the same as @@style-simple(). /// /// - thm (theorem): /// - qed (bool): Select if a box should be shown at the end. diff --git a/src/theorem.typ b/src/theorem.typ index b67e668..4a33b91 100644 --- a/src/theorem.typ +++ b/src/theorem.typ @@ -36,7 +36,7 @@ ) } -/// Check if argument is of type theorem. +/// Check if argument is #ref-type("theorem"). /// /// - c (any): /// -> bool @@ -62,10 +62,8 @@ } /// Extract theorem parameters from figure. -/// Returns a dictionary of the form -/// (body, group, kind-name, -/// name, link-to, numbering, -/// subnumbering, style). +/// Returns a #ref-type("dictionary") of the form +/// `(body, group, kind-name, name, link-to, numbering, subnumbering, style)`. /// /// - thm (theorem): /// -> dictionary @@ -81,8 +79,8 @@ ) } -/// Return the content that is linked -/// to the theorem. +/// Return the #ref-type("content") that is linked +/// to the #ref-type("theorem"). /// /// - thm (theorem): /// -> content