Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for derivative at a certain point #28

Open
tobiasdiez opened this issue May 1, 2024 · 5 comments
Open

Add option for derivative at a certain point #28

tobiasdiez opened this issue May 1, 2024 · 5 comments

Comments

@tobiasdiez
Copy link

One sometimes needs to specify the point / time at which one takes the derivative, using a vertical bar.

In typst, this can be approximated using

dv(,t)| _(t=0) f(t)

which kind of works but looks ugly since the bar is too short. It would be nice if one could use something like dv(,t, t=0) or dv(,t, at=(t=0)) which automatically yields a proper rending of the bar.

Looking at the code, typst seems to use the method stretch_vertical to increase the length of lines/bars.

@YDX-2147483647
Copy link
Contributor

YDX-2147483647 commented May 1, 2024

Here's a workaround.

#import "@preview/physica:0.9.3": dv, eval
$ eval(dv(,t))_(t=0) f(t) $

And we can define a quick function:

#let dval(..args, value) = math.attach(eval(dv(..args)), br: value)
$ dval(,t, t=0) f(t) $

#let edv(..args) = eval(dv(..args))
$ edv(,t)_(t=0) f(t) $

@Leedehai
Copy link
Owner

Leedehai commented May 1, 2024

Thanks, the above snippet is not merely a workaround, it's actually the intended usage.

I feel it's better not to couple different semantics together, but I welcome more inputs in this to convince me - no promise:)

@tobiasdiez
Copy link
Author

Not sure if this is possible with typst, but could one declare | after dv to be a shortcut for eval (active character is latex)? The eval method works and the only minor thing I don't like about it is the additional brackets that make it a bit harder to read.

Btw, this example should perhaps also be added in the "derivative" section.

@YDX-2147483647
Copy link
Contributor

Typst v0.8.0 changelog:

Removed support for automatic matching of fences like | and || as there were too many false positives. You can use functions like abs or norm or an explicit lr call instead. (Breaking change)

Therefore I guess the activate character is impossible without changing the typst compiler.


Besides, I've updated #28 (comment) with 2 example functions. Hope they satisfy your need.

@tobiasdiez
Copy link
Author

Thanks!

As another data point, the https://typst.app/universe/package/diverential package has an eval argument for derivatives and the example reads quite nice

dv(f, x, deg: 2, eval: 0)

But I will not argue further if you think the eval method is already sufficient 🦊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants