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

feat: Add commonly used physics macros #3700

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Leedehai
Copy link

@Leedehai Leedehai commented Aug 31, 2022

Support commonly used macros from the $\LaTeX$ physics package. Demo.

ops.js ('yarn start' URL):

ops explanation
\rank rank of matrices
\Res residue in complex analysis
\tr, \Tr, \trace trace of matrices

macros.js ('yarn start' URL):

macros explanation
\abs, \Abs absolute value
\norm, \Norm norm
\eval vertical bar of evaluation limits for integrals
\vb, \vectorbold vector, bold font
\vectorarrow vector, with an arrow
\vectorunit unit vector, with a hat
\dotproduct, \crossproduct dot and cross product of vectors
\dd differential
\gradient, \laplacian gradient and laplacian for scalar fields
\divergence, \curl divergence and curl for vector fields
  • Already signed CLA.

@Leedehai
Copy link
Author

Leedehai commented Sep 1, 2022

Hi maintainers, GitHub said I "need a maintainer to approve running workflows". 🙂

@codecov
Copy link

codecov bot commented Sep 1, 2022

Codecov Report

Merging #3700 (de43acc) into main (176552a) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3700      +/-   ##
==========================================
+ Coverage   92.97%   92.99%   +0.01%     
==========================================
  Files          91       91              
  Lines        6765     6781      +16     
  Branches     1571     1571              
==========================================
+ Hits         6290     6306      +16     
  Misses        437      437              
  Partials       38       38              
Impacted Files Coverage Δ
src/functions/op.js 98.97% <ø> (ø)
src/macros.js 97.58% <100.00%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ef49e2b...de43acc. Read the comment docs.

@Leedehai
Copy link
Author

Ping reviewers... 🙂

@Leedehai
Copy link
Author

Leedehai commented Sep 23, 2022

Ping reviewers..🙂 (x2)

@Leedehai
Copy link
Author

Leedehai commented Sep 30, 2022

Ping reviewers...🙂 (x3)

@Leedehai
Copy link
Author

Leedehai commented Oct 7, 2022

Ping reviewers...🙂 (x4)

@Leedehai
Copy link
Author

Ping reviewers...🙂(x5)

@physicslog
Copy link

Any plan to add a derivative shortcut like in the physics package:\dv{f}{x} for $\frac{df}{dx}$?

@Leedehai
Copy link
Author

Nope.. If anyone volunteers, feel free to fork this PR. :)

Copy link
Member

@edemaine edemaine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to take forever to review this. I'm now trying to catch up on old PRs. This one looks like a good start, but there are a lot of small incompatibilities with physics.sty, and we'd rather stick to exact LaTeX behavior. Hope you're still interested in seeing this through. You should probably look at the physics.sty source code if you haven't already.

defineMacro("\\abs", "\\lvert{#1}\\rvert");
defineMacro("\\Abs", "\\Big\\lvert{#1}\\Big\\rvert");
defineMacro("\\norm", "\\lVert{#1}\\rVert");
defineMacro("\\Norm", "\\Big\\lVert{#1}\\Big\\rVert");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see \Abs or \Norm in physics.sty. Also, it seems that \abs and \norm generally use \left and \right, with the ability to customize size via a second argument as in \abs\Big. I could see skipping the latter feature in a first version, but I don't think the current definitions match any partial feature from physics.sty.

defineMacro("\\gradient", "\\mathinner{\\nabla{#1}}");
defineMacro("\\laplacian", "\\mathinner{\\nabla^2{#1}}");
defineMacro("\\divergence", "\\mathinner{\\nabla\\dotproduct{#1}}");
defineMacro("\\curl", "\\mathinner{\\nabla\\crossproduct{#1}}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment that this doesn't support the (...) form of \curl.

defineMacro("\\dotproduct", "\\cdot");
defineMacro("\\crossproduct", "\\times");
defineMacro("\\dd", "\\textnormal{d}");
defineMacro("\\gradient", "\\mathinner{\\nabla{#1}}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add the \grad alias?

defineMacro("\\vectorarrow", "\\overrightarrow{\\vb{#1}}");
defineMacro("\\vectorunit", "\\widehat{\\vb{#1}}");
defineMacro("\\dotproduct", "\\cdot");
defineMacro("\\crossproduct", "\\times");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

physics.sty seems to use \boldsymbol\times.
Also, should we add the \cp and \cross aliases?

defineMacro("\\vectorunit", "\\widehat{\\vb{#1}}");
defineMacro("\\dotproduct", "\\cdot");
defineMacro("\\crossproduct", "\\times");
defineMacro("\\dd", "\\textnormal{d}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment that this does not support the optional power argument.

defineMacro("\\Abs", "\\Big\\lvert{#1}\\Big\\rvert");
defineMacro("\\norm", "\\lVert{#1}\\rVert");
defineMacro("\\Norm", "\\Big\\lVert{#1}\\Big\\rVert");
defineMacro("\\eval", "\\Big\\vert_{#1}^{#2}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this matches physics.sty's \eval at all.

defineMacro("\\norm", "\\lVert{#1}\\rVert");
defineMacro("\\Norm", "\\Big\\lVert{#1}\\Big\\rVert");
defineMacro("\\eval", "\\Big\\vert_{#1}^{#2}");
defineMacro("\\vb", "\\bold{#1}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

physics.sty seems to use \boldsymbol, so we should match that.

defineMacro("\\eval", "\\Big\\vert_{#1}^{#2}");
defineMacro("\\vb", "\\bold{#1}");
defineMacro("\\vectorbold", "\\vb{#1}");
defineMacro("\\vectorarrow", "\\overrightarrow{\\vb{#1}}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

physics.sty seems to use \vec instead of \overrightarrow.

defineMacro("\\vb", "\\bold{#1}");
defineMacro("\\vectorbold", "\\vb{#1}");
defineMacro("\\vectorarrow", "\\overrightarrow{\\vb{#1}}");
defineMacro("\\vectorunit", "\\widehat{\\vb{#1}}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

physics.sty seems to use \hat instead of \widehat.

defineMacro("\\vectorbold", "\\vb{#1}");
defineMacro("\\vectorarrow", "\\overrightarrow{\\vb{#1}}");
defineMacro("\\vectorunit", "\\widehat{\\vb{#1}}");
defineMacro("\\dotproduct", "\\cdot");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

physics.sty seems to use \boldsymbol\cdot.
Also, should we add the \vdot alias?

@Leedehai
Copy link
Author

Hi! Sorry I don't have enough bandwidth at the moment.. but feel free to copy this PR and modify it if anyone (or you) is interested!

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

Successfully merging this pull request may close these issues.

None yet

3 participants