Skip to content

Instantly share code, notes, and snippets.

@hongjr03
Last active January 5, 2025 06:23
Show Gist options
  • Select an option

  • Save hongjr03/75d3d4f5c891561ec54920d30986f75f to your computer and use it in GitHub Desktop.

Select an option

Save hongjr03/75d3d4f5c891561ec54920d30986f75f to your computer and use it in GitHub Desktop.
#set page(paper: "a4")
#let page-width = 595.28pt - 2 * 2.5cm // A4, 页宽减去页边距
// #set enum(numbering: "A.")
#let with-ans = state("with-ans", true)
#show list: it => context {
let item-counter = counter("item")
item-counter.update(1)
set grid(rows: 1.5em)
let one-line = measure(
grid(
columns: (auto, 1fr),
[A.], [题],
),
width: page-width,
).height
let half = measure(
grid(
columns: (auto, 1fr) * 2,
..it
.children
.map(e => (
context {
item-counter.step()
item-counter.display("A. ")
},
e.body,
))
.flatten()
),
width: page-width,
).height
let full = measure(
grid(
columns: (auto, 1fr) * 4,
..it
.children
.map(e => (
context {
item-counter.step()
item-counter.display("A. ")
},
e.body,
))
.flatten()
),
width: page-width,
).height
if full <= one-line {
// 能放在一行
grid(
columns: (auto, 1fr) * 4,
..it
.children
.map(e => (
context {
item-counter.step()
item-counter.display("A. ")
},
e.body,
))
.flatten()
)
} else if half <= one-line * 2 {
grid(
columns: (auto, 1fr) * 2,
..it
.children
.map(e => (
context {
item-counter.step()
item-counter.display("A. ")
},
e.body,
))
.flatten()
)
} else {
grid(
columns: (auto, 1fr),
..it
.children
.map(e => (
context {
item-counter.step()
item-counter.display("A. ")
},
e.body,
))
.flatten()
)
}
}
#show emph: it => context {
if with-ans.get() {
text(red, it.body)
} else {
it.body
}
}
#let prob(description, items, solution) = context {
show math.equation.where(block: true): set align(left)
[#description]
[#items]
if with-ans.get() {
[#solution]
}
}
#with-ans.update(true)
#prob[
题目题目题目?
][
- 1
- 2
- 3
- 4
][
解析:xxxxx
]
#prob[
题目题目题目?
][
- 意大利面要拌42号混凝土记得加点盐记得加点盐记得加
- $
E = m c^2
$
- _3_
- $
E = 1 / 2 m v^2
$
][
解析:xxxxx
]
#with-ans.update(false)
#prob[
题目题目题目?
][
- 1
- 2
- 3
- 4
][
解析:xxxxx
]
#prob[
题目题目题目?
][
- 春雨惊春清谷天春雨惊春清谷天
- 夏满芒夏暑相连夏满芒夏暑相连
- _秋处露秋寒霜降秋处露秋寒霜降_
- 冬雪雪冬小大寒冬雪雪冬小大寒
][
解析:xxxxx
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment