Skip to content

Commit 6083993

Browse files
committed
cellpress-unofficial:0.1.0
1 parent 9c7f151 commit 6083993

File tree

6 files changed

+137
-0
lines changed

6 files changed

+137
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Permission to use, copy, modify, and/or distribute this software for
2+
any purpose with or without fee is hereby granted.
3+
4+
THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL
5+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
6+
OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
7+
FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
8+
DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
9+
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
10+
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# CELL press tables
2+
3+
Styles for tables as used in CELL press articles.
4+
5+
## Usage
6+
7+
See [example/example.typ].
8+
9+
![Example table](example/example.png)
59.4 KB
Loading
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#import "@preview/cellpress-unofficial:0.1.0" as cellpress
2+
3+
#show: cellpress.style-table
4+
5+
= Example table
6+
7+
As seen in @tbl-foo, #lower(lorem(8))
8+
9+
#figure(
10+
caption: [Table caption],
11+
table(
12+
columns: 3,
13+
cellpress.toprule(),
14+
table.header([foobar], [baz], [qux]),
15+
cellpress.midrule(),
16+
cellpress.tabsubhdr(colspan: 3)[qwerty],
17+
cellpress.midrule(),
18+
[a], [b], [c],
19+
[d], [e], [f],
20+
cellpress.midrule(),
21+
cellpress.tabsubhdr(colspan: 3)[asdf],
22+
cellpress.midrule(),
23+
[g], [h], [i],
24+
[j], [k], [l],
25+
[m], [n], [o],
26+
cellpress.bottomrule(),
27+
)
28+
) <tbl-foo>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// CELL press template.
2+
3+
#let cellpress-red = rgb(169, 59, 69) // CELL press red
4+
#let zebra-gray = rgb(luma(95.25%)) // rgb("#f3f3f3")
5+
6+
// --- [ tables ] --------------------------------------------------------------
7+
8+
#let toprule(color: cellpress-red) = {
9+
table.hline(stroke: 0.7pt + color)
10+
}
11+
12+
#let bottomrule(color: cellpress-red) = {
13+
table.hline(stroke: 0.7pt + color)
14+
}
15+
16+
#let midrule(color: cellpress-red) = {
17+
table.hline(stroke: 0.5pt + color)
18+
}
19+
20+
#let tabsubhdr(content, colspan: 3, color: cellpress-red) = table.header(
21+
level: 2, // sub header
22+
table.cell(
23+
colspan: colspan,
24+
inset: (y: 5pt),
25+
fill: none,
26+
{
27+
set text(fill: color)
28+
show text: emph
29+
content
30+
}
31+
)
32+
)
33+
34+
#let style-table(body) = {
35+
// tables
36+
show figure.where(kind: table): set figure.caption(position: top, separator: [. ])
37+
show figure.where(kind: table): set block(breakable: true, above: 14pt, below: 14pt)
38+
show figure.where(kind: table): it => {
39+
show figure.caption: it => align(
40+
center,
41+
[
42+
#strong[#it.supplement #context it.counter.display(it.numbering)#it.separator]
43+
#it.body
44+
]
45+
)
46+
it
47+
}
48+
show table: set table(
49+
stroke: none,
50+
align: left,
51+
fill: (_, y) => {
52+
// TODO: remove `y != 0 and` when https://github.com/typst/typst/issues/4159#issuecomment-3124855835 is resolved
53+
if y != 0 and not calc.odd(y) {
54+
zebra-gray
55+
}
56+
},
57+
// TODO: uncomment when https://github.com/typst/typst/issues/4159#issuecomment-3124855835 is resolved is resolved
58+
//inset: (x: 2.5pt, y: 3pt),
59+
// TODO: remove when https://github.com/typst/typst/issues/4159#issuecomment-3124855835 is resolved is resolved
60+
inset: (x, y) => {
61+
let y_pad = 3pt
62+
if y == 0 {
63+
y_pad = 4pt
64+
}
65+
(x: 2.5pt, y: y_pad)
66+
}
67+
)
68+
// table header style.
69+
show table.cell.where(y: 0): it => {
70+
show text: strong
71+
set text(fill: cellpress-red)
72+
// TODO: uncomment when https://github.com/typst/typst/issues/4159#issuecomment-3124855835 is resolved is resolved
73+
//set table.cell(
74+
// inset: (x: 2.5pt, y: 4pt),
75+
// fill: none,
76+
//)
77+
it
78+
}
79+
80+
body
81+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "cellpress-unofficial"
3+
version = "0.1.0"
4+
entrypoint = "src/lib.typ"
5+
authors = ["Robin Eklind"]
6+
license = "0BSD"
7+
description = "Unofficial CELL press styles for Typst."
8+
exclude = ["example", "inc"]
9+
repository = "https://github.com/mewmew/cellpress-unofficial"

0 commit comments

Comments
 (0)