I’m using the ctheorems package and for the most part am very happy with it. But I would like a uniform amount of space above and below each thmbox. Currently, if I have one definition right after another, there is more space between the two definitions than there is between the the upper definition and the “Upper line of text” (and more than between the lower definition and the “Lower Line of Text”). How can I fix this?
#import "@preview/ctheorems:1.1.3": *
#show: thmrules
#let definition = thmbox("definition", "Definition", inset: (x: 0em))
Upper Line of Text
#definition[
A natural number is called a #highlight[_prime number_] if it is greater
than 1 and cannot be written as the product of two smaller natural numbers.
]
#definition[
A natural number is called a #highlight[_prime number_] if it is greater
than 1 and cannot be written as the product of two smaller natural numbers.
]
Lower Line of Text
Parameters top and bottom also exist inside the inset parameter, but it seems like the default of them is 0.
If there is any question left, don’t hesitate to ask again.
Setting padding: (bottom: 0em, top: 0em) doesn’t work for me. This sets the space between the Definitions and the surrounding text to be the same as the space between lines. I want more space than that.
Sry, I didn’t catch that part.
The simplest thing that comes to my mind is using something like #v(0.75em) above the first and below the last definition. You could also create a custom function with the bodies of the definitions as parameters:
code
#import "@preview/ctheorems:1.1.3": *
#show: thmrules
#let definition = thmbox(
"definition",
"Definition",
padding: (bottom: 0em, top: 0em),
inset: (x: 0em)
)
#let definitions = (space: 0.75em, ..sink) => {
v(space)
for body in sink.pos() {
definition[
#body
]
}
v(space)
}
Upper Line of Text
#definitions(
[
A natural number is called a #highlight[_prime number_] if it is greater
than 1 and cannot be written as the product of two smaller natural numbers.
],
[
A natural number is called a #highlight[_prime number_] if it is greater
than 1 and cannot be written as the product of two smaller natural numbers.
second definition
]
)
Lower Line of Text
If you want to combine definitions and theorems or something like that, you could use something like this:
generalized code
#let spacing = (body, space: 0.75em) => {
[
#v(space)
#body
#v(space)
]
}
Upper Line of Text
#spacing(
[
#definition[
A natural number is called a #highlight[_prime number_] if it is greater
than 1 and cannot be written as the product of two smaller natural numbers.
]
#definition[
A natural number is called a #highlight[_prime number_] if it is greater
than 1 and cannot be written as the product of two smaller natural numbers.
]
]
)
Lower Line of Text
The space parameter has the default value 0.75em, but you could change it if you would like to have different spacings.
Again: If there are (related) questions left don’t hesitate to ask again
Inspired by your suggestion, I created a wrapper as follows. It fixes the spacing issue. But it causes two other problems that I don’t know how to fix.
Labels and tags don’t work as I want them too
I would like to be able to include bibliographic information or a title to my definitions as in the example below. But I don’t know how to make that work
I currently already have a very long document. I hope any solution will allow me to use my wrapper as the one labelled as the “good-definition”
#import "@preview/ctheorems:1.1.3": *
#show: thmrules
#let definition_inner = thmbox("definition", "Definition", inset: (x: 0em), padding:(top: 0em, bottom: 0em),
)
#let definition = (top_space: 5em, bottom_space: 5em, body) => {
v(top_space, weak:true)
definition_inner[#body]
v(bottom_space, weak:true)
}
Upper Line of Text
#definition(text[@this-would-be-a-bibliographic-reference])[
A natural number is called a #highlight[_prime number_] if it is greater
than 1 and cannot be written as the product of two smaller natural numbers.
]<good-definition>
#definition[
A natural number is called a #highlight[_prime number_] if it is greater
than 1 and cannot be written as the product of two smaller natural numbers.
]<better-definition>
Lower Line of Text
Let us talk about the @good-definition and the @better-definition...
#import "@preview/ctheorems:1.1.3": *
#show: thmrules
#let definition_inner = thmbox("definition", "Definition", inset: (x: 0em), padding:(top: 0em, bottom: 0em)
)
#let definition = (top_space: 5em, bottom_space: 5em, pLabel: none, pTitle: none, body) => [
#v(top_space, weak:true)
#if (pLabel == none) [
#definition_inner(pTitle, supplement: "Def.", refnumbering: "1.1)")[#body]
]
#if (pLabel != none) [
#definition_inner(pTitle, supplement: "Def.", refnumbering: "1.1)")[#body] #label(pLabel)
]
#v(bottom_space, weak:true)
]
figure(definition_inner[ein Text]) <some-label>
Upper Line of Text
#definition(pLabel: "good-definition", pTitle: "a good definition")[
A natural number is called a #highlight[_prime number_] if it is greater
than 1 and cannot be written as the product of two smaller natural numbers.
]
#definition(pLabel: "better-definition", pTitle: "a better definition")[
A natural number is called a #highlight[_prime number_] if it is greater
than 1 and cannot be written as the product of two smaller natural numbers.
]
Lower Line of Text
Let us talk about the @good-definition and the @better-definition...
Again: if there are questions left, don’t hesitate to ask again
Main thought: you showed how weak spacing can be made to work by inserting it directly. If you want to inser v spacing without getting in the way of label attachment, then insert the spacing using a show rule.
The following works for that but the show rule selector needs to be redone to only apply to the right place. That could be the next thing to explore. In future typst with custom types it will be easier to do(?)
#import "@preview/ctheorems:1.1.3": *
#show: thmrules
#let definition = thmbox("definition", "Definition", inset: (x: 0em), padding:(top: 0em, bottom: 0em),
)
#let sp = 2em
#show pad: it => {
v(sp, weak:true)
it
v(sp, weak:true)
}
Upper Line of Text
#definition()[
A natural number is called a #highlight[_prime number_] if it is greater
than 1 and cannot be written as the product of two smaller natural numbers.
]<good-definition>
#definition[
A natural number is called a #highlight[_prime number_] if it is greater
than 1 and cannot be written as the product of two smaller natural numbers.
]<better-definition>
Lower Line of Text