-
Notifications
You must be signed in to change notification settings - Fork 954
formal-homework:0.1.0 #4239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
formal-homework:0.1.0 #4239
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| # formal-homework | ||
|
|
||
| `formal-homework` is a small [Typst](https://typst.app) package that provides an easy way to start writing formal homework documents. | ||
|
|
||
|
|
||
| ## Usage | ||
|
|
||
| First, create a new `.typ` file and import this package at the top: | ||
|
|
||
| ```typst | ||
| #import "@preview/formal-homework:0.1.0": hw, q, a, br | ||
| ``` | ||
|
|
||
| The entirety of the homework portion of your document will be contained in `hw()[]`, including the title page. Call it and pass the following (optional) parameters: | ||
|
|
||
| - `title-text` -> Text to be used as title of document | ||
|
|
||
| - `number` -> Number of the homework, only used if `title_text` is omitted | ||
|
|
||
| - `author` -> Your name | ||
|
|
||
| - `class` -> Name of the class/course that the homework is for | ||
|
|
||
| - `due-date` -> Date that the homework is due | ||
|
|
||
| ```typst | ||
| #hw( | ||
| number: 5, | ||
| author: "George P. Burdell", | ||
| class: "CS 2050", | ||
| due-date: "January 1, 1970" | ||
| )[ | ||
| Your content goes here. | ||
| ] | ||
| ``` | ||
|
|
||
|  | ||
|
|
||
| New Computer Modern is the default font, aiming for semblance to vanilla LaTeX, which professors likely prefer. To revert it, insert `#set text(font: "libertinus serif")` into the body of `#hw()[]`. | ||
|
|
||
| The content of the document is laid out with the remaining macros: `#q[]`, `#a[]`, and `#br()` | ||
|
|
||
| `#q[]` -> Contains the question, automatically enumerated | ||
| `#a[]` -> Contains the answer, bordered with a black box | ||
| `#br()` -> Shortcut for `#pagebreak()`, may be used to keep questions on their own page | ||
|
|
||
| Note that `#q[]`s may embed `#a[]`, which is often useful for multi-part questions. An exhaustive example is provided below. | ||
|
|
||
| ```typst | ||
|
|
||
| #q[ | ||
| Let $f: ZZ^+ times ZZ^+ -> ZZ^+$ such that $f(m,n) = 2^(m - 1) (2n - 1)$. Prove that $f$ is bijective. | ||
| ] | ||
|
|
||
| #a[ | ||
| *Lemma:* #h(0.5em) We proceed directly to show that the product of an even integer and an odd integer is an even integer. | ||
|
|
||
| Let $x$ be an odd integer. By definition of odd integer, $x = 2k + 1$ for some integer $k$. Let $y$ be an even integer. By definition of even integer, $y = 2j$ for some integer $j$. We show that the product of $x$ and $y$ is even. | ||
|
|
||
| $ | ||
| x y &= (2k + 1)(2j) \ | ||
| &= 4 k j + 2 j \ | ||
| &= 2 (2 k j + j) \ | ||
| $ | ||
|
|
||
| Since integers are closed under multiplication and addition, the expression $2 k j + j$ is an integer. Let that expression be assigned the variable $z$. Since $x y = 2z$, the product of $x$ and $y$ is an even integer. Therefore, the product of an even integer and an odd integer is an even integer. #sym.qed | ||
|
|
||
| *Proof:* #h(0.5em) We proceed directly to show that the function $f: ZZ^+ times ZZ^+ -> ZZ^+$ such that $f(m, n) = 2^(m - 1) (2n - 1)$ is bijective. | ||
|
|
||
| Let $f: ZZ^+ times ZZ^+ -> ZZ^+$ such that $f(m, n) = 2^(m - 1) (2n - 1)$. To show that $f$ is bijective, we must show injectivity and surjectivity. | ||
|
|
||
| *Injectivity Proof:* #h(0.5em) To show that $f$ is injective, we show that if $f(a,b) = f(c,d)$ for arbitrary $(a,b), (c,d) in (ZZ^+ times ZZ^+)$, then $(a,b) = (c,d)$. | ||
|
|
||
| Assume that for arbitrary $(a,b), (c,d) in (ZZ^+ times ZZ^+)$, $f(a,b) = f(c,d)$. | ||
|
|
||
| $ | ||
| f(a,b) &= 2^(a - 1) (2b - 1) \ | ||
| f(c,d) &= 2^(c - 1) (2d - 1) \ | ||
| $ | ||
| $ | ||
| &=> 2^(a - 1) (2b - 1) = 2^(c - 1) (2d - 1) \ | ||
| &= 2^(a - c) (2b - 1) = 2d - 1 \ | ||
| $ | ||
|
|
||
| By Lemma, the product of an even integer and a positive integer is an even integer. Since $2b - 1$ and $2d - 1$ are odd integers, $2^(a - c)$ cannot be even. If $2^(a - c)$ was even, then $2d - 1$ would be even by Lemma, which is a contradiction. Thus, $2^(a - c)$ must be odd, and the only power of two that is odd is $2^0 = 1$. It follows that $2^(a - c) = 2^0$, so $a = c$. | ||
|
|
||
| Since $a = c$, we plug $a$ back into $f(a,b) = f(c,d)$ for $c$. | ||
|
|
||
| $ | ||
| 2^(a - 1) (2b - 1) &= 2^(a - 1) (2d - 1) \ | ||
| 2b - 1 &= 2d - 1 \ | ||
| 2b &= 2d \ | ||
| b &= d | ||
| $ | ||
|
|
||
| Since $a = c$ and $b = d$, we have shown that if $f(a,b) = f(c,d)$, then $(a,c) = (c,d)$. Therefore, $f$ is injective. | ||
|
|
||
| *Surjectivity Proof:* #h(0.5em) To show that $f$ is surjective, we prove that for an arbitrary positive integer $z$, there exists an element $(x, y) in (ZZ^+ times ZZ^+)$ such that $z = f(x, y)$. | ||
|
|
||
| Let $z$ be an arbitrary positive integer. By the Fundamental Theorem of Arithmetic, $z$ may be uniquely written as $z = 2^p q$, where $p$ is a non-negative integer and $q$ is an odd positive integer. By the definition of odd positive integers, $q$ may be expressed as $q = 2k + 1$, where $k$ is a non-negative integer. Expressing $z$ in terms of $p$ and $k$ gives $z = 2^p (2k + 1)$. Define the variables $x = p + 1$ and $y = k + 1$. By the closure of integers under addition, $x$ and $y$ must be integers. Since $p$ and $q$ are positive, $x$ and $y$ must be positive. Therefore, $z$ may be expressed as a function of $x$ and $y$, and $(x,y)$ is an element of $ZZ^+ times ZZ^+$ by definition of Cartesian product. | ||
|
|
||
| Therefore, since we have shown that the function $f: ZZ^+ times ZZ^+ -> ZZ^+$ such that $f(m, n) = 2^(m - 1) (2n - 1)$ is injective and surjective, $f$ is bijective by definition of bijectivity. #sym.qed | ||
| ] | ||
|
|
||
| #br() | ||
|
|
||
| #q[ | ||
| Determine whether the following sets are finite, countably infinite, or uncountably infinite. If finite, find it's cardinality. If countable, construct an injection from it to $NN $ (you do not have to prove that your function is an injection). | ||
|
|
||
| + The set of all multiples of 6. | ||
|
|
||
| #a[Countably infinite. For $s = 6k$, where $k in ZZ$, let $f(s) = |s| + 1$.] | ||
|
|
||
| + The set of all even prime numbers. | ||
|
|
||
| #a[Finite. The only even prime is 2; this set has a cardinality of 1.] | ||
|
|
||
| + The set of finite binary strings. Note: a binary string consists of $0 $s and $1 $s, for example: $1 0 1 1 $ and $0 0 1 0 0 0 0 1 1 $ are binary strings. | ||
|
|
||
| #a[Countably infinite. Let $f$ be a function that takes a binary string as input and outputs the base 10 conversion of a 1 followed by the binary string. ] | ||
|
|
||
| + The set of all infinite binary strings. | ||
|
|
||
| #a[Uncountably infinite.] | ||
|
|
||
| + The set of all real numbers between $e $ and $pi $ (inclusive). | ||
|
|
||
| #a[Uncountably infinite.] | ||
|
|
||
| + The set of all integers between $e $ and $pi $ (inclusive). | ||
|
|
||
| #a[Finite. This set has a cardinality of 1, with its only element being 3.] | ||
|
|
||
| ] | ||
| ``` | ||
|
|
||
|    | ||
|
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| #let styles = ("1.", "(a)", "(i)") | ||
|
|
||
| #let enum-offset = state("offset", 0) | ||
|
|
||
| #let q-counter = counter("q") | ||
|
|
||
| #let q(body) = [ | ||
| #q-counter.step() | ||
|
|
||
| #context { | ||
| let num = q-counter.display("1.") | ||
| enum-offset.update(1) | ||
|
|
||
| block(width: 100%, above: 0.75em, below: 1em)[ | ||
| #place(left)[#box(width: 0.5em, align(right, num))] | ||
| #pad(left: 1.3em, body) | ||
| ] | ||
|
|
||
| enum-offset.update(0) | ||
| } | ||
| ] | ||
|
|
||
| #let a(body) = [ | ||
| #block( | ||
| width: 100%, | ||
| // In the future, these should be optional arguments | ||
| // fill: none, | ||
| // radius: 0pt, | ||
| inset: 10pt, | ||
| stroke: 1pt + black, | ||
| breakable: true, | ||
| )[#body] | ||
| ] | ||
|
|
||
| #let br() = pagebreak() | ||
|
|
||
|
|
||
| #let hw( | ||
| title-text: none, | ||
| number: 1, | ||
| author: none, | ||
| class: none, | ||
| due-date: none, | ||
| body, | ||
| ) = { | ||
|
|
||
| counter(page).update(0) | ||
|
|
||
| set page( | ||
| paper: "us-letter", | ||
| margin: 1in, | ||
| footer: context { | ||
| if counter(page).get().first() > 0 [ | ||
| #align(center)[ | ||
| #counter(page).display() | ||
| ] | ||
| ] | ||
| }, | ||
| ) | ||
|
|
||
| set text( | ||
| size: 12pt, | ||
| lang: "en", | ||
| font: "New Computer Modern" | ||
| ) | ||
|
|
||
| set enum( | ||
| full: true, | ||
| numbering: (..nums) => context { | ||
| let offset = enum-offset.get() | ||
| let depth = nums.pos().len() + offset | ||
| let style = styles.at(depth - 1) | ||
| numbering(style, nums.pos().last()) | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| align(horizon + center, block[ | ||
| #if title-text != none [ | ||
| #title[#title-text] | ||
| ] else [ | ||
| #title[Homework #number Submission] | ||
| ] | ||
|
|
||
| #class | ||
|
|
||
| #author | ||
|
|
||
| #due-date | ||
| ]) | ||
|
|
||
|
|
||
| pagebreak() | ||
|
|
||
| body | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [package] | ||
| name = "formal-homework" | ||
| version = "0.1.0" | ||
| entrypoint = "lib.typ" | ||
|
|
||
| authors = ["<@daqnal>"] | ||
| license = "GPL-3.0-or-later" | ||
| description = "Submit homeworks with simplicity and formality." | ||
|
|
||
| repository = "https://github.com/daqnal/formal-homework" | ||
| categories = ["report"] | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this repository public please (or actually create it if it just doesn't exist yet)?