LaTeX-Workshop icon indicating copy to clipboard operation
LaTeX-Workshop copied to clipboard

Snippets For Physics!

Open orbitoo opened this issue 2 years ago • 5 comments

A couple of days ago, snippets for math package physics were removed but I'm sure it is useful and I NEED IT, so I am here to complain about this. DYM)~88V$Z~2@ZOF(IVVS32

orbitoo avatar Apr 23 '22 10:04 orbitoo

@jlelong Is it worth to add a new config to provide extended autocompletion items such as this one? Also if so, we may need to determine which ones belong to this category.

James-Yu avatar Apr 25 '22 07:04 James-Yu

@James-Yu I do not think adding an extra setting will help here. We are discussing completions for specific packages, which are only made available once the package is actually included. So, we can be reassured that they will not pollute the usage experience of users not interesting in the package.

See https://github.com/James-Yu/LaTeX-Workshop/tree/master/dev#pkgcommandpy for an explanation of how the completion data for every package is computed. We rely on a home made Python script.

Let us come back to the physics package. The commands generated by the package have very complicated signature using {}, [], () or || to delimit arguments. I am afraid that these separators break the current duplication detector, see #3192.

  • I can resurrect the completion data for the physics, once and for all. Further updates would require a dedicated PR by users as the complexity of the command signatures breaks my Python script and handling all the cases is far too complicated.
  • Yet, be aware that loading the physics might seriously affect user experience with intellisense because of the duplication detection mechanism.

All this needs careful thought.

jlelong avatar Apr 25 '22 14:04 jlelong

@orbitoo If you are still interesting in seeing completion for physics back, I need your help. I have resurrected the completion file in a separate branch physics. You can fork it from https://github.com/jlelong/LaTeX-Workshop/ The completion file is in https://github.com/jlelong/LaTeX-Workshop/physics/data/packages/physics_cmd.json bu in it cannot be used in its current state. Entries are of the form

"name": {
    "command": "mqty(\\diagonalmatrix{matrix element 1,matrix element 2,matrix element 3,...})",
    "package": "physics",
    "snippet": "mqty(\\diagonalmatrix{${1:matrix element 1,matrix element 2,matrix element 3,...}})"
  },

The name field and command content can only contain letters, {, }, [, ] and *. Could you make the appropriate changes to make the file acceptable? When done, I will add it back to LW.

jlelong avatar May 26 '22 16:05 jlelong

I think an intermediate solution here can provide great relief for those of us who regularly use the physics package. I rarely try to use the less standard "non-latex" style commands. The majority of the commands have a more robust and latex-friendly option such as \pqty{} \bqty{} \vqty{} \abs{a} \norm{a} \eval{x}_0^\infty \comm{A}{B} \pb{A}{B} \grad \div \curl \cross, \Re{z} \Im{z} One page I'm not so sure on would be the "trig" options on page 4 of the documentation.

The derivatives in section 2.5 on page 5 should be mandatory, along with the documentation's latex-compatible parts from section 2.6.

https://mirror.las.iastate.edu/tex-archive/macros/latex/contrib/physics/physics.pdf

A good chunk of the matrix macros from section 2.7 are also compatible with standard latex.

Either way, I think we can get working snippets that are latex compatible for most of the commands from the documentation without too much trouble in the interim if a complete or longer-term solution is needed to be explored in the background.

ja-gooding avatar Sep 13 '22 21:09 ja-gooding

I need physics too! But now the physics branch has gone.

it would be better if math preview in editor supports physics and bm

image

Also see physicx, a rework of physics

Firestar-Reimu avatar Oct 07 '22 07:10 Firestar-Reimu

This issue only deals with snippets for the physics package. Maths preview is provided by mathjax and to the best of my knowledge there is no mathjax support for the physics package.

jlelong avatar Nov 15 '22 18:11 jlelong

This issue only deals with snippets for the physics package. Maths preview is provided by mathjax and to the best of my knowledge there is no mathjax support for the physics package.

This is the official mathjax support for the physics package: https://docs.mathjax.org/en/latest/input/tex/extensions/physics.html

ja-gooding avatar Nov 15 '22 18:11 ja-gooding

@ja-gooding very good news. Then, it is sufficient to add physics to latex-workshop.hover.preview.mathjax.extensions for math preview to support the physics package.

jlelong avatar Nov 15 '22 19:11 jlelong

Manually closing this issue as it seems to have a nice solution now.

--

edit: my bad, did not notice this one in fact concerns with auto-completion.

James-Yu avatar Dec 08 '22 13:12 James-Yu

As we now maintains our own cwl repo, what about I manually remove the incompatible commands from https://github.com/jlelong/LaTeX-cwl/blob/master/physics.cwl and only intellisense those with only letters, {, }, [, ] and *? @jlelong At least a bare minimum working solution for physics users.

James-Yu avatar Dec 08 '22 13:12 James-Yu

Even I maintain our own fork of LaTeX-cwl because there does not seem to be much activity on the original one, I would prefer to avoid changes because of LW issues. I would prefer to solve the issue inside LW. I can think two solutions

  1. Take https://github.com/jlelong/LaTeX-Workshop/physics/data/packages/physics_cmd.json and clean the file to make sure command names only contain letters, {, }, [, ] and *
  2. Slightly modify the Python script to drop an entry with command names containing other characters that letters, {, }, [, ] and *

Approach 2 has the advantage that new regular LaTeX commands added to physics.cwl will be handled automatically.

jlelong avatar Dec 08 '22 18:12 jlelong

Resolved in #3576

James-Yu avatar Dec 12 '22 02:12 James-Yu