Giter Club home page Giter Club logo

Comments (2)

Leedehai avatar Leedehai commented on June 12, 2024 1

I'd prefer not to rename physica's eval because

  • Typst's eval is not that frequently used, and
  • I'd like to keep the name short and memorable, especially eval is the macro name in the LaTeX physics package

As a workaround, you may rename eval while importing if you would also want to keep access to Typst's eval at the same time.

#import "@preview/physica:0.9.2": .., eval as evalat

I understand users like doing wildcard imports (that is, import everything: #import "...": *), so I proposed typst/typst#3068 to optionally hide symbols after discovering they'd like to use some symbols eclipsed by the import (instead of having to delete the * and write out every symbol they have ever used in the doc -- very bad UX), like the Dart language. But that proposal was "not liked at all" and my reasons were deemed "completely unfounded", so it was closed.

Maybe give a bump to Typst's typst/typst#1639, which proposes another way to access the native Typst symbols that are otherwise eclipsed by imports :)

from typst-physics.

linuxrider avatar linuxrider commented on June 12, 2024

I understand. Is this naming conflict documented somewhere?

This is my use case of typst's eval.

#import "@preview/cetz:0.2.0": canvas, plot, draw

#let E-hermitepsi = ((0, "1/(calc.sqrt(calc.sqrt(calc.pi)))*(1 * f)"), (1, "1/(calc.sqrt(calc.sqrt(4*calc.pi)))*(2 * y * f)"), (2, "1/(calc.sqrt(calc.sqrt(64*calc.pi)))*(4 * y * y - 2) * f"), (3, "1/(calc.sqrt(calc.sqrt(2304*calc.pi)))*(8 * y * y * y - 12 * y)*f"))
#figure(
  grid(
    columns: 2,     // 2 means 2 auto-sized columns
    gutter: 2mm,    // space between columns
    canvas(length: 1.2cm, {
      import draw: *
      plot.plot(
        size: (5, 10),
        x-tick-step: 2,
        x-label: [$y$],
        // x-ticks: ( (0, $0$), (1, $a$)),
        y-label: [$V(x)$, #text([$E$], fill:blue), #text([$psi(y)$], fill:red)],
        y-tick-step: none,
        y-ticks: ((0.5, $v=0$), (1.5, $v=1$), (2.5, $v=2$), (3.5, $v=3$)),
        x-min: -4,
        x-max: 4,
        y-min: 0,
        // y-max: 12,
        {  
          plot.add(style: (stroke: (paint:black)),
            domain: (-3, 3), samples: 100, y => 0.5*y*y
          )
          for (v, hermitepsi) in E-hermitepsi {
            let E = v + 1/2
            let psi(y) = eval(hermitepsi, scope: (y:y, f: calc.exp(-y*y/2)))
              plot.add(style: (stroke: (paint:blue)),
                domain: (-4, 4), samples: 10, y => E
              )
              plot.add(style: (stroke: (paint:red)),
               domain: (-4, 4), samples: 100, y => psi(y) + E
              )
          }
        }
      )
      line(style: (stroke: (thickness: 5pt)), (2.5, 0), (2.5, 10))  
    }),
    canvas(length: 1.2cm, {
      import draw: *
      plot.plot(
        size: (5, 10),
        x-tick-step: 2,
        x-label: [$y$],
        y-label: [$V(x)$, #text([$E$], fill:blue), #text([$psi^2(y)$], fill:red)],
        y-tick-step: none,
        y-ticks: ( (0.5, $v=0$), (1.5, $v=1$),(2.5, $v=2$),(3.5, $v=3$)),
        x-min: -4,
        x-max: 4,
        y-min: 0,
        // y-max: 12,
        {  
          plot.add(style: (stroke: (paint:black)),
            domain: (-3, 3), samples: 100, y => 0.5*y*y
          )
          for (v, hermitepsi) in E-hermitepsi {
            let E = v + 1/2
            let psi(y) = eval(hermitepsi, scope: (y:y, f: calc.exp(-y*y/2), E: E))
            plot.add(style: (stroke: (paint:blue)),
              domain: (-4, 4), samples: 10, y => E
            )
            plot.add(style: (stroke: (paint:red)),
             domain: (-4, 4), samples: 100, y => psi(y) * psi(y) +  E
            )
          }
        }
      )
      line(style: (stroke: (thickness: 5pt)), (2.5, 0), (2.5, 10))
    })
  )
)

harmonic_oscillator

from typst-physics.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.