Giter Club home page Giter Club logo

typst-physics's Introduction

๐Ÿ“— The manual.

logo

The physica package for Typst (v0.9.3)

CI Latest release

Available in the collection of Typst packages: #import "@preview/physica:0.9.3": *

physica noun.

  • Latin, study of nature

This Typst package provides handy typesetting utilities for natural sciences, including:

  • Braces,
  • Vectors and vector fields,
  • Matrices, including Jacobian and Hessian,
  • Smartly render ..^T as transpose and ..^+ as dagger (conjugate transpose),
  • Dirac braket notations,
  • Common math functions,
  • Differentials and derivatives, including partial derivatives of mixed orders with automatic order summation,
  • Familiar "h-bar", tensor abstract index notations, isotopes, Taylor series term,
  • Signal sequences i.e. digital timing diagrams.

A quick look

See the manual for more details and examples.

demo-quick

A larger demo.typ:

demo-larger

Using physica in your Typst document

With typst package management (recommended)

See https://github.com/typst/packages. If you are using the Typst's web app, packages listed there are readily available; if you are using the Typst compiler locally, it downloads packages on-demand and caches them on-disk, see here for details.

effect

// Style 1
#import "@preview/physica:0.9.3": *

$ curl (grad f), tensor(T, -mu, +nu), pdv(f,x,y,[1,2]) $
// Style 2
#import "@preview/physica:0.9.3": curl, grad, tensor, pdv

$ curl (grad f), tensor(T, -mu, +nu), pdv(f,x,y,[1,2]) $
// Style 3
#import "@preview/physica:0.9.3"

$ physica.curl (physica.grad f), physica.tensor(T, -mu, +nu), physica.pdv(f,x,y,[1,2]) $

Without typst package management

Similar to examples above, but import with the undecorated file path like "physica.typ".

Typst version

The version requirement for the compiler is in typst.toml's compiler field. If you are using an unsupported Typst version, the compiler will throw an error. You may want to update your compiler with typst update, or choose an earlier version of the physica package.

Developed with compiler version:

$ typst --version
typst 0.10.0 (70ca0d25)

Manual

See the manual for a more comprehensive coverage, a PDF file generated directly with the Typst binary.

To regenerate the manual, use command

typst watch physica-manual.typ

Contribution

  • Bug fixes are welcome!

  • New features: welcome as well. If it is small, feel free to create a pull request. If it is large, the best first step is creating an issue and let us explore the design together. Some features might warrant a package on its own.

  • Testing: currently testing is done by closely inspecting the generated manual. This does not scale well. I plan to add programmatic testing by comparing rendered pictures with golden images.

Change log

changelog.md.

License

typst-physics's People

Contributors

cgmossa avatar dedekindcut avatar leedehai avatar ruben-hude avatar sinthoras7 avatar supercilex avatar t-rapp avatar ydx-2147483647 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

typst-physics's Issues

Improve braket

Current implementation gives inconsistent height of angles and vertical bars in braket. Until typst/typst#641 have merged, I propose to use following workaround to make the formula more pleasant.

#let braket(bra, ket) = style(styles => {
  let height = measure($ bra ket $, styles).height;
  let phantom = box(height: height, width: 0pt, inset: 0pt, stroke: none);
  $ lr(angle.l bra lr(|phantom#h(0pt)) ket angle.r) $
})

Result:
image

Wrong upright style and spacing for vecrow() and Greek letters

When the first element in vecrow() is a Greek letter, there are unexpected spacing and upright style issues, like the first three lines in the following. The last three lines are how the output is supposed to be.

I found a temporary solution that is to use italic(alpha) instead of just alpha in the first element, though.

$
& vecrow(alpha, beta) \
& vecrow(alpha, italic(beta)) \
& vecrow(alpha, b) \
& vecrow(a, beta) \
& vecrow(italic(alpha), beta) \
& (alpha, beta) \
$
image

Add option to make vectors upright (non-italicized)

Currently, typing in vb(u) or vu(u) makes the vector u appear bold and italicized. However, in some style guides it is customary to make vectors only appear bold without being italics. It would be nice if an option was added to support this.

Unexpected output of iprod()

As per the latest manual of physica, the behaviour of iprod() should be the one shown in the first line. However, the actual output is the one in the second line.

$
& angle.l u, v angle.r \
& iprod(u, v) \
& braket(u, v)
$
image

CI for releases and manual generation?

As mentioned in #7 (comment), the PDF manual is not automatically generated now.

Do you want a CI for that? Say, when you click some buttom on GitHub or git push --follow-tags, a workflow will run and create a new release with the PDF manual.

Pros:

  • Easier for maintenance and PR.
  • Reduce the repo size in future. (because PDF will be stored in releases)

Cons:

  • Setting up a CI from scratch is complicated.
  • Being too dependent on GitHub.

More information:

If you like it but are busy, I can make a PR in one or two weeks.

mel needs beautify

This code snippet
$ mel(phi_n^0, sqrt((2 hbar) / (m omega))(a^dagger + a), phi_n^0) $
gives
image
in which the vertical bar is too bold and slightly higher than my braket. Besides, the space between alphabet and bar is too tight.

Potential error when evaluating pdv

Hi, I am encountering an error when using the pdv function, for example $ pdv(,t,2) $ and am trying to find the cause. In an empty document it works fine:

#import "@preview/physica:0.8.1": *
$pdv(x,y)$

But in my document:
typst 0.7.0 (bcab7705)

#import "template.typ": *
#import "@preview/metro:0.1.0": qty
#import "@preview/truthfy:0.2.0": generate-table, generate-empty 
#import "@preview/codelst:1.0.0": sourcecode
#import "@preview/physica:0.8.1": *
#import "@preview/big-todo:0.2.0": todo
// ...
$ pdv(,t, 2) $

the following error occurs:
error: unknown variable: content
โ”Œโ”€ @preview/physica:0.8.1\physica.typ:549:19
โ”‚
549 โ”‚ if type(last) == content {
โ”‚ ^^^^^^^

help: error occurred in this call of function partialderivative

Where my template contains no variable called content.

This could of course just be a conflict with other includes, but I did not find the cause and am wondering if it could be an error in the library. Thank you for a response.

Actually it seems to be specific to my compiler or version of typst.

Derivative delimiter matching

When writing out a formula, I would want to achieve something like (3).
Only (1),(2) and (4) are easily feasible in typst (with physica), without the manual size adjustment in (3) and (5), which is still not exactly the same as automatic typesetting would have it (compare the size of the parentheses in (5)).

I know little about typesetting (and typst), but I thought it might be an improvement upon things when one doesn't have to manually 'guess' the size for these parentheses, but let it be done automatically by the dv function?
image

// No aligment, see e.g. https://github.com/typst/typst/pull/1849
$ &dv(          (f(x) plus.minus g(x)) ,x, s:#none)  &= ... $
$ &dv(          (f(x) plus.minus g(x)) ,x, s:slash)  &= ... $
$ &dv(,x)   lr( (f(x) plus.minus g(x)) ,size: #200%) &= ... $
$ &(dv(,x))     (f(x) plus.minus g(x))               &= ... $
$ &(dv(,x)) lr( (f(x) plus.minus g(x)) ,size: #200%) &= ... $
  1. What is your opinion on this? Should this be supported by physica, or is my way (lr(... ,size: #200%)) the 'best' way (I'd like to think not...)?
  2. If this could be supported by physica, how would one do this?
    • I would suggest to have another option in the s: argument of dv (and similar commands).
      This option would ask that the function is pretty large and thus needs this particular typesetting.
      How would we call this option? large_function, ...
    • The implementation could look something like the following pseudo-code?
      size = maximum(height of the content box, height of the d/dx box)
      where size is the height of the parentheses.

Hessian Matrix formula is wrong

From the manual:

Screenshot 2023-10-24 at 10 07 27โ€ฏPM

The Hessian is the matrix of second order partial derivatives, so for 3x3 matrices and higher the matrix should still consist of $\dfrac{\partial^2}{\partial x_i \partial x_j}$. Currently for 3x3 hmat generates a matrix with elements such as $\dfrac{\partial^3}{\partial x \partial z}$, which is incorrect. The superscript in the numerator should always be 2 no matter the dimension.

From the wikipedia page:

Screenshot 2023-10-24 at 10 11 46โ€ฏPM

Thanks for all your hard work on this package! It's now a must have for me when using Typst.

`pdv` with single argument

Hi! Thank you for this amazing package, it's a huge help to the whole Typst community :)

I wanted to ask, should there be a single-argument form of pdv? Intuitively I'd expect pdv(x) to give diff / (diff x).

More attractive README needed

This is a great package! But people may miss it if they don't dive into the demo (physics-manual.pdf)โ€ฆ

How about add a screenshot to README?

Additional information

Typst, KaTeX, MathJax and all of them have screenshots.

typst
katex
mathjax

Euler symbol

Does it make sense to add an abbreviation for the Euler constant upright(e) e.g. eu?
Background: elementary charge e and Euler number e in nearby or same equation

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.