Skip to content

Commit

Permalink
help: showman show -> showcode(); template: change example image
Browse files Browse the repository at this point in the history
  • Loading branch information
lace-wing committed Jan 8, 2025
1 parent dac03a2 commit ab690cc
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 116 deletions.
65 changes: 65 additions & 0 deletions packages/preview/lacy-ubc-math-project/0.1.0/format.typ
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,68 @@
#supplement#body
]
}

#let get-orientation(dir) = {
if dir == ltr {
return (
dir: ltr,
cols: (1fr, 1fr),
align: (x, y) => horizon + (right, left).at(calc.rem(x, 2)),
line: grid.vline,
)
} else if dir == ttb {
return (
dir: ttb,
cols: 1,
align: (x, y) => (bottom, top).at(calc.rem(y, 2)),
line: grid.hline,
)
}
}

#let showcode(code, dir: ltr) = {
import "@preview/showman:0.1.2": runner
let prefix-orig = (
"#import \"@preview/lacy-ubc-math-project:0.1.0\": *",
"#let __example-question-counters = range(1, unsafe.__max-qs-level + 1).map(i => counter(\"example-question-\" + str(i)))",
"#for c in __example-question-counters {",
" c.update(1)",
"}",
"#let __example-question-labels = (\"ex:1\", \"a\", \"i\",)",
"#set text(font: (\"DejaVu Serif\", \"New Computer Modern\"))",
"#let question = question.with(counters: __example-question-counters, labels: __example-question-labels)",
"#set math.equation(numbering: \"(1.1)\")",
"#show: equate.with(breakable: true, sub-numbering: true)",
).join("\n")
let suffix-orig = ""
let orientation = get-orientation(dir)
let prefix = prefix-orig
let suffix = suffix-orig
if code.lang == "typc" {
prefix = prefix + "\n#{"
suffix = "}\n" + suffix
}

runner.standalone-example(
code,
eval-prefix: prefix,
eval-suffix: suffix,
direction: orientation.dir,
container: (input, output, direction: ltr) => {
block(
// breakable: false,
width: 100%,
grid(
columns: orientation.cols,
align: orientation.align,
inset: (x: 1em, y: 0.8em),
grid.cell(input),
orientation.at("line")(stroke: 0.5pt),
grid.cell(output),
),
)
},
)
}


65 changes: 0 additions & 65 deletions packages/preview/lacy-ubc-math-project/0.1.0/help.typ
Original file line number Diff line number Diff line change
Expand Up @@ -12,72 +12,7 @@
"caveats",
)

#let get-orientation(tag) = {
if tag == <show> {
return (
dir: ltr,
cols: (1fr, 1fr),
align: (x, y) => horizon + (right, left).at(calc.rem(x, 2)),
line: grid.vline,
)
} else if tag == <showt> {
return (
dir: ttb,
cols: 1,
align: (x, y) => (bottom, top).at(calc.rem(y, 2)),
line: grid.hline,
)
}
}

#let help-setup(body) = {
import "@preview/showman:0.1.2": runner
let prefix-orig = (
"#import \"@preview/lacy-ubc-math-project:0.1.0\": *",
"#let __example-question-counters = range(1, unsafe.__max-qs-level + 1).map(i => counter(\"example-question-\" + str(i)))",
"#for c in __example-question-counters {",
" c.update(1)",
"}",
"#let __example-question-labels = (\"ex:1\", \"a\", \"i\",)",
"#set text(font: (\"DejaVu Serif\", \"New Computer Modern\"))",
"#let question = question.with(counters: __example-question-counters, labels: __example-question-labels)",
"#set math.equation(numbering: \"(1.1)\")",
"#show: equate.with(breakable: true, sub-numbering: true)",
).join("\n")
let suffix-orig = ""
show raw.where(block: true): it => context {
if "label" in it.fields() and it.label in (<show>, <showt>) and it.lang in ("typst", "typc") {
let orientation = get-orientation(it.label)
let prefix = prefix-orig
let suffix = suffix-orig
if it.lang == "typc" {
prefix = prefix + "\n#{"
suffix = "}\n" + suffix
}

runner.standalone-example(
it,
eval-prefix: prefix,
eval-suffix: suffix,
direction: orientation.dir,
container: (input, output, direction: ltr) => {
block(
// breakable: false,
width: 100%,
grid(
columns: orientation.cols,
align: orientation.align,
inset: (x: 1em, y: 0.8em),
grid.cell(input),
orientation.at("line")(stroke: 0.5pt),
grid.cell(output),
),
)
},
)
} else { it }
}

show raw.where(block: false): r => box(
fill: black.transparentize(95%),
radius: 0.4em,
Expand Down
Binary file modified packages/preview/lacy-ubc-math-project/0.1.0/manual.pdf
Binary file not shown.
14 changes: 8 additions & 6 deletions packages/preview/lacy-ubc-math-project/0.1.0/manuals/author.typ
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#import "../format.typ": showcode

= Author
The `author()` function is to be used as an argument of the `setup()` function, providing an author dictionary. It takes the first name, last name, and student number as arguments. For example,
```typst
Expand All @@ -7,9 +9,9 @@ The `author()` function is to be used as an argument of the `setup()` function,
)
```
Inside, the `author()` function will return a dictionary:
```typc
#showcode(```typc
author("Jane", "Doe", 12345678)
``` <show>
```)

And in the PDF metadata there will be a "Jane Doe" in the authors field, student number not included.

Expand All @@ -24,22 +26,22 @@ Hypothesize that
In this case, we can
- provide an English translation of the name;
- use the `strname` argument to specify the English version of the name.
```typc
#showcode(```typc
author(
"Alex",
"k\u{02b7}ik\u{02b7}\u{0259}\u{019b}\u{0313} (Coquitlam)",
12345678,
strname: "Alex Coquitlam"
)
``` <show>
```)
If `strname` is set, it will be used in the PDF metadata instead of the displayed name.

In some more extreme cases, `strname` would be a necessity, rather than a backup. Take name #underline(text(fill: purple)[Ga])#strike[*_lli_*]#overline($cal("leo")$) as an example. The name is so special that it cannot be converted to plain text. In this case, you must provide a `strname` to avoid incomprehensible PDF metadata.
```typc
#showcode(```typc
author(
[#underline(text(fill: purple)[Ga])#strike[*_lli_*]#overline($cal("leo")$)],
"Smith",
12345678,
strname: "Gallileo Smith"
)
``` <showt>
```, dir: ttb)
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#import "../format.typ": showcode

= Drawing
As we are doing math, inevitably we will need to draw some graphs.

Expand Down Expand Up @@ -35,7 +37,7 @@ Find more visualization packages #link("https://staging.typst.app/universe/searc
Besides importing the drawing packages, the `drawing` module also provides some helper functions.

For example, the `cylinder()` function draws an upright no-perspective cylinder.
```typst
#showcode(```typst
#import drawing: *
#cetz.canvas({
import cetz.draw: *
Expand All @@ -50,7 +52,7 @@ For example, the `cylinder()` function draws an upright no-perspective cylinder.
)
})
})
``` <show>
```)

== Example//s
#[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#import "../format.typ": showcode

= Getting Started
#quote[So, how do I even start using Typst?]

Expand Down Expand Up @@ -66,7 +68,7 @@ Below this ```typst #show: setup.with(...)``` is your project content.

== Questions & Solutions
A math group project mostly consists of questions and solutions. You can use the ```typc question()``` and ```typc solution()``` functions to structure your content.
```typst
#showcode(```typst
#question(1)[
What is the answer to the universe, life, and everything?
// The solution should be in the question.
Expand All @@ -81,13 +83,13 @@ A math group project mostly consists of questions and solutions. You can use the
]
]
]
``` <show>
```)

== Learn Typst
Yes, you do have to learn it, but it is simple (for our purpose).

Here is a quick peek at some useful syntaxes:
```typst
#showcode(```typst
You will sometimes _emphasize important information_ in your questions and solutions. // 1 linebreak = 1 space.
Or, go a step further to *boldly* state the matter. <ex:bold> // <label-name> to place a label.
// 1+ blank lines = 1 paragraph break.
Expand All @@ -101,7 +103,7 @@ $
// #link(<label-name>)[displayed text] to reference a label.
// For equation, figure and bibliography, @label-name is also available.
Want to get #link(<ex:bold>)[*_bold_*]? Let's look at @eq:ex:lim.
``` <showt>
```)

For general techniques, consult the #link("https://staging.typst.app/docs")[Typst documentation].

Expand Down
65 changes: 34 additions & 31 deletions packages/preview/lacy-ubc-math-project/0.1.0/manuals/math.typ
Original file line number Diff line number Diff line change
Expand Up @@ -15,97 +15,100 @@ Unlike LaTex, math in Typst is simple.
"cal(l) = (-b plus.minus sqrt(b^2 - 4a c))\n\t / (2a)",
)
.map(eq => [
#raw("$" + eq + "$", lang: "typst", block: true) <show>
#showcode(raw("$" + eq + "$", lang: "typst", block: true))
])
.join()
)

Most of the time, you have to leave a space between single letters to show consecutive letters.
The template has you covered on some common multi-letter operators, like
```typst
#showcode(```typst
$lim, inf$
``` <show>
```)

For "block" or "display" math, leave a space or newline between _both_ dollar signs and the equations.
```typst
#showcode(```typst
$ E = m c^2 $
``` <show>
```)

Documented are the built-in #link("https://staging.typst.app/docs/reference/math/")[math functions] and #link("https://staging.typst.app/docs/reference/symbols/sym/")[symbols]

== Texts In Math
To display normal text in math mode, surround the text with double quotes function.
```typst
#showcode(```typst
$x = "We are going to find out!"$
``` <show>
```)

If you need normal single-letter text, fist see if it is a lone unit.
If so, use the ```typc unit()``` function.
```typst
#showcode(```typst
$unit(N) = unit(kg m s^(-2))$
``` <show>
```)
A unit with a value is called a quantity, ```typc qty()```.
```typst
#showcode(```typst
$qty(1, m) = qty(100, cm)$
``` <show>
```)

More about these in #link(<sc:metro>)[Units and Quantities].

Otherwise, use ```typc upright()```.
```typst
#showcode(```typst
$U space upright(U) space U$
``` <show>
```)

There are other text styles available in math mode.
```typst
#showcode(```typst
$serif("Serif") sans("Sans-serif") frak("Fraktur") \
mono("Monospace") bb("Blackboard bold") cal("Calligraphic")$
``` <show>
```)

== Language Syntax in Math
In (at least) MATH 100 group projects, math equations is a part of your English (or whatever) writings. Make sure to use proper grammar and *punctuations*. Yes, you will add periods after finishing equations.

== Numbering and Referencing Equations
Note that you must enable equation numbering to reference equations, which is set by this template. Add a ```typst #<label-name>``` right after the equation you wish to reference.
```typst
#showcode(```typst
$
e^(i pi) = -1 #<eq:ex:euler>
$
@eq:ex:euler is Euler's identity. \
#link(<eq:ex:euler>)[The same reference].
``` <show>
```)

== Extra Math Symbols and Functions
The `physica` package provides additional math symbols and functions.
```typst
#showcode(```typst
$A^T, curl vb(E) = - pdv(vb(B), t)$
``` <show>
```)

```typst
#showcode(```typst
$tensor(Lambda,+mu,-nu) = dmat(1,RR)$
``` <show>
```)

```typst
#showcode(```typst
$f(x,y) dd(x,y)$
``` <show>
```)

It is imported in this template.

== Units and Quantities
<sc:metro>
Although no as common as in physics, we do sometimes need to use units and quantities.
Directly typing the 'units' will not result in correct output.
```typst
#showcode(```typst
$1 m = 100 cm$
``` <show>
```typst
```)
#showcode(```typst
$N = kg m s^(-2)$
``` <show>
```)

This template uses the `metro` package for this purpose.
If you prefer, you can also import and use the `unify` package.
```typst
#showcode(```typst
$qty(1, m) = qty(100, cm)$
``` <show>
```typst
```)
#showcode(```typst
$unit(N) = unit(kg m s^(-2))$
``` <show>
```)

As you see, the ```typc qty()``` and ```typc unit()``` functions correct the numbers, units and spacing.
Loading

0 comments on commit ab690cc

Please sign in to comment.