Closed shivangp76 closed 1 month ago
Hey, thanks for your question!
It seems like you don't even want the exercise environment itself to be counted. In that case, the best solution right now is to make a second exercise-extra
environment, which looks just like the first one, but has no counter:
#import "@preview/great-theorems:0.1.1": *
#import "@preview/rich-counters:0.2.1": *
#show: great-theorems-init
#let mathcounter = rich-counter(
identifier: "mathblocks",
inherited_levels: 0
)
#let exercise = mathblock(
blocktitle: "Exercise",
counter: mathcounter,
)
#let exercise-extra = mathblock(
blocktitle: "Exercise",
// put same properties as `exercise` except the counter
)
#exercise[
Some exercise.
]
#exercise-extra[
Uncounted exercise.
]
#exercise[
Some exercise.
]
Now you can adjust the prefix for that environment on an individual basis:
#exercise[
Some exercise.
]
#exercise-extra(prefix: [*Exercise 6.7(a).*])[
Uncounted exercise.
]
#exercise[
Some exercise.
]
Also note that title
s exist, if you want to utilize them:
#exercise[
Some exercise.
]
#exercise(title: [6.7(a) in the book])[
Some other exercise.
]
#exercise[
Some exercise.
]
Replacing the counter value directly is currently not possible. If more people want this feature, I can add it though.
So if you would like to have this feature (to replace the counter value with your own number) please comment here.
Thank you for the suggestions! The extra
suffix seems a bit clunky. It also requires that I specify the full blocktitle, so I have to retype "Exercise". This means I can't edit the markup on "Exercise" globally. For this reason, I am in favor of replacing the counter value directly.
For reference, here is the Latex I am aiming to replicate:
\newcounter{exercisenum}
\newenvironment{exercise}[1][\theexercisenum]{
\IfValueT{#1}{
\stepcounter{exercisenum}
}
\textbf{Exercise #1:}
}
{}
I have implemented this now. Please have a look at the README, you have to pass number: ...
to the environment.
Note that this is not yet on Typst Universe (and will take a few days at least). Please download lib.typ
from this repo and use #import "lib.typ": *
instead of importing the package.
Could you try it and tell me if it works for you or if anything breaks?
Thank you for working on this! It works well. The trick mentioned here doesn't work, but I suspect that will change as #3 get resolved anyway.
Wait, what do you mean by this trick doesn't work? It should work exactly the same as before, the code which handles this hasn't been changed. Can you give a reproducible example of what doesn't work?
I think I did a poor job of testing it last time. It looks fine.
Okay thanks. I will close this issue then. I hope to release the functionality to Typst Universe soon.
Hi,
Thank you for making this package! I was wondering if it is possible to override a counter for a specific instance of a mathblock. For example, I made an "Exercise" block using code similar to that provided in the README. I want to have a default counter, but be able to override the counter with specific text. Something like:
to render something like: