|
| 1 | +# derive-it |
| 2 | + |
| 3 | +A Typst package to create Fitch-style natural deductions. Available on [Typst Universe](https://typst.app/universe/package/derive-it). |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## Usage |
| 8 | + |
| 9 | +This package provides two functions: |
| 10 | + |
| 11 | +`ded-nat` is a function that expects: |
| 12 | +- `stcolor`: the stroke color of the indentation guides. Optional: Default is `black`. |
| 13 | +- `arr`: an array with the shape, it can be provided in two shapes. |
| 14 | + - 4 items: (dependency: text content, indentation: integer starting from 0, formula: text content, rule: text content). |
| 15 | + - 3 items: the same as above, but without the dependency. |
| 16 | +- `style-dep`: the styling function that will be applied to the dependencies. Optional: Default is `content => text(style: "italic", content)`. |
| 17 | +- `style-formula`: the styling function that will be applied to the formula. Optional: Default is `content => content`. |
| 18 | +- `style-rule`: the styling function that will be applied to the rule. Optional: Default is `content => text(style: "bold", content)`. |
| 19 | +- `nested-boxes`: instead of using indentation lines, use nested boxes. Optional: Default is `false`. |
| 20 | + |
| 21 | +`ded-nat-boxed` is a function that returns the deduction in a `box` and expects: |
| 22 | +- `stcolor`: the stroke color of the indentation guides. Optional: Default is `black`. |
| 23 | +- `premises-and-conclusion`: bool, whether to automatically insert or not the premises and conclusion of the derivation above the lines. Optional: Default is `true`. |
| 24 | +- `premise-rule-text`: text content, used for finding the premises' formulas when `premises-and-conclusion` is set to `true`. Optional: Default is `"PR"`. |
| 25 | +- `arr`: an array with the shape, it can be provided in two shapes. |
| 26 | + - 4 items: (dependency: text content, indentation: integer starting from 0, formula: text content, rule: text content). |
| 27 | + - 3 items: the same as above, but without the dependency. |
| 28 | +- `style-dep`: the styling function that will be applied to the dependencies. Optional: Default is `content => text(style: "italic", content)`. |
| 29 | +- `style-formula`: the styling function that will be applied to the formula. Optional: Default is `content => content`. |
| 30 | +- `style-rule`: the styling function that will be applied to the rule. Optional: Default is `content => text(style: "bold", content)`. |
| 31 | +- `nested-boxes`: instead of using indentation lines, use nested boxes. Optional: Default is `false`. |
| 32 | + |
| 33 | + |
| 34 | +> Note: depending on your layout, this functions may fail to compile due to a high enough amount of indentation (due to the recursive implementation of the layout). |
| 35 | +> In my tests, depending on the content of the line, the compiler will panic at around 15-20 indentation levels. |
| 36 | +> ```typst |
| 37 | +> ("1", 16, $forall y ((Q y a and R y a) -> not Q a y)$, "TEST") |
| 38 | +> ``` |
| 39 | +>  |
| 40 | +
|
| 41 | +
|
| 42 | +### Example |
| 43 | +
|
| 44 | +```typ |
| 45 | +#import "@preview/derive-it:1.1.0": * |
| 46 | +
|
| 47 | +#ded-nat(stcolor: black, arr:( |
| 48 | + ("1", 0, $forall x (P x) and forall x (Q x)$, "PR"), |
| 49 | + ("2", 0, $forall x (P x -> R x)$, "PR"), |
| 50 | + |
| 51 | + ("1", 0, $forall x (P x)$, "S 1"), |
| 52 | + ("1", 0, $P a$, "IU 3"), |
| 53 | + ("2", 0, $P a -> R a$, "IU 2"), |
| 54 | + ("1,2", 0, $R a$, "MP 4, 5"), |
| 55 | + |
| 56 | + ("1,2", 0, $forall x (R x)$, "GU 6"), |
| 57 | +)) |
| 58 | +
|
| 59 | +#ded-nat-boxed(stcolor: black, premises-and-conclusion: false, arr: ( |
| 60 | + ("1", 0, $forall x (S x b) and not forall y (P y -> Q b y)$, "PR"), |
| 61 | + ("2", 0, $forall x forall y (Q x y -> not Q y x)$, "PR"), |
| 62 | + ("3", 1, $not forall x (not P x) -> forall y (S y b -> Q b y)$, "Sup. RAA"), |
| 63 | + ("1", 1, $not forall y (P y -> Q b y)$, "S 1"), |
| 64 | + ("1", 1, $exists y not (P y -> Q b y)$, "EMC 4"), |
| 65 | + ("6", 2, $not (P a -> Q b a)$, "Sup. IE 5"), |
| 66 | + ("7", 3, $not (P a and not Q b a)$, "Sup. RAA"), |
| 67 | + ("7", 3, $not P a or not not Q b a$, "DM 7"), |
| 68 | + ("9", 4, $not P a$, "Sup. PC"), |
| 69 | + ("9", 4, $not P a or Q b a$, "Disy. 9"), |
| 70 | + ("", 3, $not P a -> (not P a or Q b a)$, "PC 9-10"), |
| 71 | + ("12", 4, $not not Q b a$, "Sup. PC"), |
| 72 | + ("12", 4, $Q b a$, "DN 12"), |
| 73 | + ("12", 4, $not P a or Q b a$, "Disy. 13"), |
| 74 | + ("", 3, $not not Q b a -> (not P a or Q b a)$, "PC 12-14"), |
| 75 | + ("7", 3, $not P a or Q b a$, "Dil. 8,11,15"), |
| 76 | + ("7", 3, $P a -> Q b a$, "IM 16"), |
| 77 | + ("6,7", 3, $(P a -> Q b a) and not (P a -> Q b a)$, "Conj. 6, 17"), |
| 78 | + ("6", 2, $P a and not Q b a$, "RAA 7-18"), |
| 79 | + ("6", 2, $P a$, "S 19"), |
| 80 | + ("6", 2, $exists x (P x)$, "GE 20"), |
| 81 | + ("6", 2, $not forall x (not P x)$, "EMC 21"), |
| 82 | + ("3,6", 2, $forall y (S y b -> Q b y)$, "MP 3, 22"), |
| 83 | + ("3,6", 2, $S a b -> Q b a$, "IU 23"), |
| 84 | + ("1", 2, $forall x (S x b)$, "S 1"), |
| 85 | + ("1", 2, $S a b$, "IU 25"), |
| 86 | + ("1,3,6", 2, $Q b a$, "MP 24, 25"), |
| 87 | + ("6", 2, $not Q b a$, "S 19"), |
| 88 | + ("1,3,6", 2, $Q b a or not exists y not (P y -> Q b y)$, "Disy. 27"), |
| 89 | + ("1,3,6", 2, $not exists y not (P y -> Q b y)$, "MTP 28, 29"), |
| 90 | + ("1,3", 1, $not exists y not (P y -> Q b y)$, "IE 5, 6, 30"), |
| 91 | + ("1,3", 1, $not exists y not (P y -> Q b y) and exists y not (P y -> Q b y)$, "Conj. 5, 31"), |
| 92 | +
|
| 93 | + ("1", 0, $not (not forall x (not P x) -> forall y ( S y b -> Q b y))$, "RAA 3-32"), |
| 94 | +)) |
| 95 | +``` |
| 96 | +
|
| 97 | +# Development |
| 98 | + |
| 99 | +In order to compile locally `examples/example.typ` the command is: |
| 100 | + |
| 101 | +```sh |
| 102 | +typst compile examples/example.typ --root . |
| 103 | +``` |
0 commit comments