Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/preview/meppp/0.2.2/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 CL4R3T

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
106 changes: 106 additions & 0 deletions packages/preview/meppp/0.2.2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# meppp

A simple template for modern physics experiments (MPE) courses at the Physics School of PKU.

## meppp-lab-report

The recommended report format of MPE course.
Default arguments are shown as below:

```typ
#import "@preview/meppp:0.2.1": *

Check warning on line 11 in packages/preview/meppp/0.2.2/README.md

View check run for this annotation

Typst package check / @preview/meppp:0.2.2

packages/preview/meppp/0.2.2/README.md#L11

This import seems to use an older version of the package.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This imports seems to be outdated.


#let meppp-lab-report(
title: "",
author: "",
info: [],
abstract: [],
keywords: (),
author-footnote: [],
heading-numbering-array: ("I" ,"A", "1", "a"),
heading-suffix: ". ",
doc,
) = ...

Check warning on line 23 in packages/preview/meppp/0.2.2/README.md

View check run for this annotation

Typst package check / @preview/meppp:0.2.2

packages/preview/meppp/0.2.2/README.md#L23

Syntax error in README. expected expression If this code block is not supposed to be parsed as a Typst source, please explicitely specify another language.

Check warning on line 23 in packages/preview/meppp/0.2.2/README.md

View check run for this annotation

Typst package check / @preview/meppp:0.2.2

packages/preview/meppp/0.2.2/README.md#L23

Syntax error in README. expected semicolon or line break If this code block is not supposed to be parsed as a Typst source, please explicitely specify another language.
```

- `title` is the title of the report.
- `author` is the name of the author.
- `info` is a line (or lines) of brief information of author and the report (e.g. student ID, school, experiment date...)
- `abstract` is the abstract of the report, not shown when it is empty.
- `keywords` are keywords of the report, only shown when the abstract is shown.
- `author-footnote` is the phone number or the e-mail of the author, shown in the footnote.
- `heading-numbering-array` is the heading numbering of each level. Only shows the numbering of the deepest level.
- `heading-suffix` is the suffix of headings

It is recommended to use `#show` to use the template:

```typ
#show: meppp-lab-report.with(
title: [Test title],
..args
)
...your report below.
```

## meppp-tl-table

Modify your input `table` to a three-lined table (AIP style), returned as a `figure`. Double-lines above and below the table, and a single line below the header.

```typ
#let meppp-tl-table(
caption: none,
supplement: auto,
stroke: 0.5pt,
tbl
) = ...

Check warning on line 55 in packages/preview/meppp/0.2.2/README.md

View check run for this annotation

Typst package check / @preview/meppp:0.2.2

packages/preview/meppp/0.2.2/README.md#L55

Syntax error in README. expected expression If this code block is not supposed to be parsed as a Typst source, please explicitely specify another language.

Check warning on line 55 in packages/preview/meppp/0.2.2/README.md

View check run for this annotation

Typst package check / @preview/meppp:0.2.2

packages/preview/meppp/0.2.2/README.md#L55

Syntax error in README. expected semicolon or line break If this code block is not supposed to be parsed as a Typst source, please explicitely specify another language.
```

- `caption` is the caption above the table, center-aligned
- `supplement` is same as the supplement in the figure.
- `stroke` is the stroke used in the three lines (maybe five lines).
- `tbl` is the input table, which must contains a `table.header`

Example:

```typ
#meppp-tl-table(
table(
columns: 4,
rows: 2,
table.header([Item1], [Item2], [Item3], [Item4]),
[Data1], [Data2], [Data3], [Data4],
)
)
```

## subfigure

Counts subfigures and displays in the figure, mostly used when inserting multiple images.

```typ
#let subfigure(
body,
caption: none,
numbering: "(a)",
inside: true,
dx: 10pt,
dy: 10pt,
boxargs: (fill: white, inset: 5pt),
alignment: top + left,
) = ...

Check warning on line 90 in packages/preview/meppp/0.2.2/README.md

View check run for this annotation

Typst package check / @preview/meppp:0.2.2

packages/preview/meppp/0.2.2/README.md#L90

Syntax error in README. expected expression If this code block is not supposed to be parsed as a Typst source, please explicitely specify another language.

Check warning on line 90 in packages/preview/meppp/0.2.2/README.md

View check run for this annotation

Typst package check / @preview/meppp:0.2.2

packages/preview/meppp/0.2.2/README.md#L90

Syntax error in README. expected semicolon or line break If this code block is not supposed to be parsed as a Typst source, please explicitely specify another language.
```

## pku-logo

The logo of PKU, returned as a `image`

```typ
#let pku-logo(..args) = image("pkulogo.png", ..args)
```

Example:

``` typ
#pku-logo(width: 50%)
#pku-logo()
```
31 changes: 31 additions & 0 deletions packages/preview/meppp/0.2.2/lib.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#import ("table.typ"): meppp-tl-table
#import ("template.typ"): meppp-lab-report
#let pku-logo(..args) = image("pkulogo.png", ..args)

#let subfigure(
body,
caption: none,
numbering: "(a)",
inside: true,
dx: 10pt,
dy: 10pt,
boxargs: (fill: white, inset: 5pt),
alignment: top + left,
) = {
let lsa = counter("last-subfigure-at")
let sc = counter("subfigure-counter")
context if lsa.get() != counter(figure).get() {
sc.update((1,))
lsa.update(counter(figure).get())
} else {
sc.step()
}
let number = context sc.display(numbering)
body
if (inside) {
place(alignment, box([#number #caption], ..boxargs), dx: dx, dy: dy)
} else {
linebreak()
align(center, [#number #caption])
}
}
Binary file added packages/preview/meppp/0.2.2/pkulogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 111 additions & 0 deletions packages/preview/meppp/0.2.2/table.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// return the number of rows of the table
#let table-row-counter(cells, columns) = {
let last-row = (0,) * columns
let x = 0
let y = 0
let volume = 0
for cell in cells {
if cell.has("body") {
let colspan = 1
let rowspan = 1
if cell.has("colspan") {
colspan = cell.colspan
}
if cell.has("rowspan") {
rowspan = cell.rowspan
}
volume += colspan * rowspan
let end = x + colspan
while x < end {
last-row.at(x) += rowspan
x += 1
}
let next = last-row.position(ele => {
ele == y
})
if next == none {
y = calc.min(..last-row)
x = last-row.position(ele => {
ele == y
})
} else {
x = next
}
}
}
let rows = calc.max(..last-row)
let volume-empty = columns * rows - volume
assert(volume == last-row.sum())
return (rows, volume-empty)
}

// A three-line-table returned as a figure
#let meppp-tl-table(
caption: none,
supplement: auto,
stroke: 0.5pt,
tbl,
) = {
let align = center + horizon
if tbl.has("align") {
align = tbl.align
}

let columns = 1
let column-count = 1
if tbl.has("columns") {
columns = tbl.columns
if type(tbl.columns) == int {
column-count = tbl.columns
} else if type(tbl.columns) == array {
column-count = columns.len()
}
}

let header = tbl.children.at(0)
assert(
header.has("children"),
message: "Header is needed.",
)
let header-children = header.children
let header-rows = table-row-counter(header-children,column-count).at(0)

let content = tbl.children.slice(1)
let content-trc = table-row-counter(content, column-count)
let content-rows = content-trc.at(0)
let content-empty-cells = content-trc.at(1)
content = content + ([],) * content-empty-cells

let rows = (1.5pt,) + (1.5em,) * (header-rows + content-rows) + (1.5pt,)

let hline = table.hline(stroke: stroke)
let empty-row = table.cell([], colspan: column-count)


return figure(
table(
align: align,
columns: columns,
rows: rows,
stroke: none,
table.header(
hline,
empty-row,
hline,
..header-children,
hline,
),
..content,
table.footer(
hline,
empty-row,
hline,
repeat: false,
)

),
kind: table,
caption: figure.caption(caption, position: top),
supplement: supplement,
)
}
Loading
Loading