LaTeX-Workshop
LaTeX-Workshop copied to clipboard
Snippets For Physics!
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.
@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 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.
@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.
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.
I need physics too! But now the physics
branch has gone.
it would be better if math preview in editor supports physics
and bm
Also see physicx, a rework of physics
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 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 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.
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.
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.
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
- 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 *
- 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.
Resolved in #3576