#newcommand and renewcommand from latex to typst
36 messages · Page 1 of 1 (latest)
so that's an example of how the following code blocks can be used
\newcommand{\fonct}[5]{
{#1}\ \colon \left \{ \begin{array}{@{\;}r@{}c@{}l@{}c@{}}
& #2 & {} \longrightarrow {} & #3 \\
& #4 & {} \longmapsto {} & #5
\end{array} \right.
}
\newcounter{question}[chaptr]
\renewcommand{\thequestion}{\arabic{question}}
\newenvironment{question}{
\refstepcounter{question}
\vspace{0.5cm}\noindent\textbf{Q \thequestion .}
}{\par\noindent\hrulefill\par}
i'd also like to create something like a gradual counter, which increments everytime I add \question blocks
The equivalent of \newcommand would be let (https://typst.app/docs/reference/scripting#bindings)
And you can define custom counters (https://typst.app/docs/reference/introspection/counter)
?r
#let fonct(var, from1, to1, from2, to2) = {
$
#var : cases(from1 &--> to1, from2 &arrow.long.bar to2)
$
}
#fonct($Delta$, $K[X]$, $K[X]$, $P$, $P(X + 1) - P(X)$)
$ fonct(Delta, K[X], K[X], P, P(X - 1) - P(X)) $
for your first function, you can call it one of the two ways (either outside or inside of math mode)
well i suppose in your case, the left and right values are centered
For the numbered questions part, I think there are some packages that provide that
I would avoid using cases. It's not intended for this use, and alignment is not gonna work as you intend it to
what else would you recommend using?
also how do I create new environments in typst ?
there is no such thing as an environment in typst in that sense, so you dont
you would more or less create a function
a typst equivalent to a latex environment
A function that takes content as an argument
?r ```
#let my-env(body) = [
#line(length: 100%)
#body
#line(length: 100%)
]
#my-env[#lorem(50)]
i forgot to do smth
do you know how to create custom numbering like the one from my latex code ?
something that increments each time I use the question function
Maybe the ctheorems package, let me get a link
if we assume that the question function allows me to do the same as my latex question environment
?r ```
#let question-counter = counter("question")
#let question(body) = [
#question-counter.step()
#line(length: 100%)
#question-counter.display("Q1.") #body
#line(length: 100%)
]
#question[#lorem(50)]
#question[#lorem(50)]
This is how you would use a counter
Everything is native. ctheorems seems to do pretty much the same as igidrau described