#newcommand and renewcommand from latex to typst

36 messages · Page 1 of 1 (latest)

dull prairie
#

hi, i'd like to use set/show/whatever function lets me do this from latex over to typst

#

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

desert sapphire
ivory notch
#

?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)) $
ivory notch
#

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

alpine stag
#

For the numbered questions part, I think there are some packages that provide that

livid ridge
#

I would avoid using cases. It's not intended for this use, and alignment is not gonna work as you intend it to

ivory notch
#

ehh

#

if the center alignment isnt an issue, its completely fine

dull prairie
#

also how do I create new environments in typst ?

ivory notch
#

there is no such thing as an environment in typst in that sense, so you dont

#

you would more or less create a function

dull prairie
#

a typst equivalent to a latex environment

desert sapphire
#

A function that takes content as an argument

#

?r ```
#let my-env(body) = [
#line(length: 100%)
#body
#line(length: 100%)
]

#my-env[#lorem(50)]

dull prairie
#

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

alpine stag
#

Maybe the ctheorems package, let me get a link

dull prairie
#

if we assume that the question function allows me to do the same as my latex question environment

alpine stag
desert sapphire
#

?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)]

desert sapphire
#

This is how you would use a counter

dull prairie
#

okayy thanks !! Do i need to import ctheorems ?

#

Or is everything you used native ?

minor agate
#

Everything is native. ctheorems seems to do pretty much the same as igidrau described