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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/support_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ $\gdef\VERT{|}$
|\aa|$\text{\aa}$|`\text{\aa}`|
|\above|${a \above{2pt} b+1}$|`{a \above{2pt} b+1}`|
|\abovewithdelims|<span style="color:firebrick;">Not supported</span>||
|\abs|$\abs{a}$|`\abs{a}`|
|\Abs|$\Abs{\frac{a}{b}}$|`\Abs{\frac{a}{b}}`|
|\acute|$\acute e$|`\acute e`|
|\AE|$\text{\AE}$|`\text{\AE}`|
|\ae|$\text{\ae}$|`\text{\ae}`|
Expand Down Expand Up @@ -281,12 +283,14 @@ use `\ce` instead|
|\cotg|$\cotg$||
|\coth|$\coth$||
|\cr|$\begin{matrix} a & b\cr c & d \end{matrix}$|`\begin{matrix}`<br>&nbsp;&nbsp;&nbsp;`a & b \cr`<br>&nbsp;&nbsp;&nbsp;`c & d`<br>`\end{matrix}`|
|\crossproduct|$\crossproduct$||
|\csc|$\csc$||
|\cssId|<span style="color:firebrick;">Not supported</span>|A PR is pending.
|\ctg|$\ctg$||
|\cth|$\cth$||
|\Cup|$\Cup$||
|\cup|$\cup$||
|\curl|$\curl{E}$|`\curl{E}`|
|\curlyeqprec|$\curlyeqprec$||
|\curlyeqsucc|$\curlyeqsucc$||
|\curlyvee|$\curlyvee$||
Expand All @@ -312,6 +316,7 @@ use `\ce` instead|
|\dbinom|$\dbinom n k$|`\dbinom n k`|
|\dblcolon|$\dblcolon$||
|{dcases}|$\begin{dcases}a&\text{if }b\\c&\text{if }d\end{dcases}$|`\begin{dcases}`<br>&nbsp;&nbsp;&nbsp;`a &\text{if } b \\`<br>&nbsp;&nbsp;&nbsp;`c &\text{if } d`<br>`\end{dcases}`|
|\dd|$\dd$||
|\ddag|$\ddag$||
|\ddagger|$\ddagger$||
|\ddddot|<span style="color:firebrick;">Not supported</span>||
Expand Down Expand Up @@ -339,12 +344,14 @@ use `\ce` instead|
|\displaylines|<span style="color:firebrick;">Not supported</span>||
|\displaystyle|$\displaystyle\sum_0^n$|`\displaystyle\sum_0^n`|
|\div|$\div$||
|\divergence|$\divergence{B}$|`\divergence{B}`|
|\divideontimes|$\divideontimes$||
|\dot|$\dot x$|`\dot x`|
|\Doteq|$\Doteq$||
|\doteq|$\doteq$||
|\doteqdot|$\doteqdot$||
|\dotplus|$\dotplus$||
|\dotproduct|$\dotproduct$||
|\dots|$x_1 + \dots + x_n$|`x_1 + \dots + x_n`|
|\dotsb|$x_1 +\dotsb + x_n$|`x_1 +\dotsb + x_n`|
|\dotsc|$x,\dotsc,y$|`x,\dotsc,y`|
Expand Down Expand Up @@ -399,6 +406,7 @@ use `\ce` instead|
|\eta|$\eta$||
|\eth|$\eth$||
|\euro|<span style="color:firebrick;">Not supported</span>||
|\eval|$f(x)\eval{0}{1}$|`f(x)\eval{0}{1}`|
|\exist|$\exist$||
|\exists|$\exists$||
|\exp|$\exp$||
Expand Down Expand Up @@ -446,6 +454,7 @@ use `\ce` instead|
|\gggtr|$\gggtr$||
|\gimel|$\gimel$||
|\global|$\global\def\add#1#2{#1+#2} \add 2 3$|`\global\def\add#1#2{#1+#2} \add 2 3`|
|\gradient|$\gradient{\psi}$|`\gradient{\psi}`|
|\gnapprox|$\gnapprox$||
|\gneq|$\gneq$||
|\gneqq|$\gneqq$||
Expand Down Expand Up @@ -557,6 +566,7 @@ use `\ce` instead|
|\land|$\land$||
|\lang|$\lang A\rangle$|`\lang A\rangle`|
|\langle|$\langle A\rangle$|`\langle A\rangle`|
|\laplacian|$\laplacian{\psi}$|`\laplacian{\psi}`|
|\Larr|$\Larr$||
|\lArr|$\lArr$||
|\larr|$\larr$||
Expand Down Expand Up @@ -752,6 +762,8 @@ use `\ce` instead|
|\noexpand|||
|\nolimits|$\lim\nolimits_x$|`\lim\nolimits_x`|
|\nonumber|$$\begin{align}a&=b+c\nonumber\\d+e&=f\end{align}$$|`\begin{align}`<br>&nbsp;&nbsp;&nbsp;`a&=b+c \nonumber\\`<br>&nbsp;&nbsp;&nbsp;`d+e&=f`<br>`\end{align}`|
|\norm|$\norm{a}$|`\norm{a}`|
|\Norm|$\Norm{\frac{a}{b}}$|`\Norm{\frac{a}{b}}`|
|\normalfont|<span style="color:firebrick;">Not supported</span>||
|\normalsize|$\normalsize normalsize$|`\normalsize normalsize`|
|\not|$\not =$|`\not =`|
Expand Down Expand Up @@ -888,6 +900,7 @@ use `\ce` instead|
|\rang|$\langle A\rang$|`\langle A\rang`|
|\rangle|$\langle A\rangle$|`\langle A\rangle`|
|\Rarr|$\Rarr$||
|\rank|$\rank$||
|\rArr|$\rArr$||
|\rarr|$\rarr$||
|\ratio|$\ratio$||
Expand All @@ -897,6 +910,7 @@ use `\ce` instead|
|{rcases}|$\begin{rcases}a&\text{if }b\\c&\text{if }d\end{rcases}$|`\begin{rcases}`<br>&nbsp;&nbsp;&nbsp;`a &\text{if } b \\`<br>&nbsp;&nbsp;&nbsp;`c &\text{if } d`<br>`\end{rcases}`|
|\rceil|$\rceil$||
|\Re|$\Re$||
|\Res|$\Res||
|\real|$\real$||
|\Reals|$\Reals$||
|\reals|$\reals$||
Expand Down Expand Up @@ -1110,6 +1124,9 @@ use `\ce` instead|
|\to|$\to$||
|\toggle|<span style="color:firebrick;">Not supported</span>||
|\top|$\top$||
|\tr|$\tr$||
|\Tr|$\Tr$||
|\trace|$\trace$||
|\triangle|$\triangle$||
|\triangledown|$\triangledown$||
|\triangleleft|$\triangleleft$||
Expand Down Expand Up @@ -1201,6 +1218,7 @@ use `\ce` instead|
|\vartriangleright|$\vartriangleright$||
|\varUpsilon|$\varUpsilon$||
|\varXi|$\varXi$||
|\vb|$\vb{a}$|`\vb{a}`|
|\vcentcolon|$\mathrel{\vcentcolon =}$|`\mathrel{\vcentcolon =}`|
|\vcenter|$a+\left(\vcenter{\frac{\frac a b}c}\right)$|`a+\left(\vcenter{\hbox{$\frac{\frac a b}c$}}\right)`<br>TeX (strict) syntax|
|\vcenter|$a+\left(\vcenter{\frac{\frac a b}c}\right)$|`a+\left(\vcenter{\frac{\frac a b}c}\right)`<br>non-strict syntax|
Expand All @@ -1209,6 +1227,9 @@ use `\ce` instead|
|\vdash|$\vdash$||
|\vdots|$\vdots$||
|\vec|$\vec{F}$|`\vec{F}`|
|\vectorarrow|$\vectorarrow{a}$|`\vectorarrow{a}`|
|\vectorbold|$\vectorbold{a}$|`\vectorbold{a}`|
|\vectorunit|$\vectorunit{a}$|`\vectorunit{a}`|
|\vee|$\vee$||
|\veebar|$\veebar$||
|\verb|$\verb!\frac a b!$|`\verb!\frac a b!`|
Expand Down
29 changes: 21 additions & 8 deletions docs/supported.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,17 @@ Direct Input: $+ - / * ⋅ ∘ ∙ ± × ÷ ∓ ∔ ∧ ∨ ∩ ∪ ≀ ⊎ ⊓

|||||
|:--------------------|:--------------------|:----------------|:--------------|
| $\arcsin$ `\arcsin` | $\cosec$ `\cosec` | $\deg$ `\deg` | $\sec$ `\sec` |
| $\arccos$ `\arccos` | $\cosh$ `\cosh` | $\dim$ `\dim` | $\sin$ `\sin` |
| $\arctan$ `\arctan` | $\cot$ `\cot` | $\exp$ `\exp` | $\sinh$ `\sinh` |
| $\arctg$ `\arctg` | $\cotg$ `\cotg` | $\hom$ `\hom` | $\sh$ `\sh` |
| $\arcctg$ `\arcctg` | $\coth$ `\coth` | $\ker$ `\ker` | $\tan$ `\tan` |
| $\arg$ `\arg` | $\csc$ `\csc` | $\lg$ `\lg` | $\tanh$ `\tanh` |
| $\ch$ `\ch` | $\ctg$ `\ctg` | $\ln$ `\ln` | $\tg$ `\tg` |
| $\cos$ `\cos` | $\cth$ `\cth` | $\log$ `\log` | $\th$ `\th` |
| $\abs{a}$ `\abs{a}` | $\cosh$ `\cosh` | $f\eval{0}{1}$ `f\eval{0}{1}` | $\sin$ `\sin` |
| $\Abs{a}$ `\Abs{a}` | $\cot$ `\cot` | $\hom$ `\hom` | $\sinh$ `\sinh` |
| $\arcsin$ `\arcsin` | $\cotg$ `\cotg` | $\ker$ `\ker` | $\sh$ `\sh` |
| $\arccos$ `\arccos` | $\coth$ `\coth` | $\lg$ `\lg` | $\tan$ `\tan` |
| $\arctan$ `\arctan` | $\csc$ `\csc` | $\ln$ `\ln` | $\tanh$ `\tanh` |
| $\arctg$ `\arctg` | $\ctg$ `\ctg` | $\log$ `\log` | $\tg$ `\tg` |
| $\arcctg$ `\arcctg` | $\cth$ `\cth` | $\norm{a}$ `\norm{a}` | $\th$ `\th` |
| $\arg$ `\arg` | $\deg$ `\deg` | $\Norm{a}$ `\Norm{a}` | $\tr$ `\tr` |
| $\ch$ `\ch` | $\dim$ `\dim` | $\rank$ `\rank` | $\Tr$ `\Tr` |
| $\cos$ `\cos` | $\dd$ `\dd` | $\Res$ `\Res` | $\trace$ `\trace` |
| $\cosec$ `\cosec` | $\exp$ `\exp` | $\sec$ `\sec` ||
| $\operatorname{f}$ `\operatorname{f}` | |||
| $\argmax$ `\argmax` | $\injlim$ `\injlim` | $\min$ `\min` | $\varinjlim$ `\varinjlim` |
| $\argmin$ `\argmin` | $\lim$ `\lim` | $\plim$ `\plim` | $\varliminf$ `\varliminf` |
Expand Down Expand Up @@ -568,6 +571,16 @@ Extensible arrows all can take an optional argument in the same manner<br>as `\x
|$\bra{\phi}$ `\bra{\phi}` |$\ket{\psi}$ `\ket{\psi}` |$\braket{\phi\VERT\psi}$ <code>\braket{\phi&#124;\psi}</code> |
|$\Bra{\phi}$ `\Bra{\phi}` |$\Ket{\psi}$ `\Ket{\psi}` |$\Braket{ ϕ \VERT \frac{∂^2}{∂ t^2} \VERT ψ }$ <code>\Braket{ ϕ &#124; \frac{∂^2}{∂ t^2} &#124; ψ }</code>|

**Physics Notation**

|||
|:----------------|:----------------|
|$\vb{a}$ `\vb{a}`|$\vectorbold{a}$ `\vectorbold{a}`|
|$\vectorarrow{a}$ `\vectorarrow{a}`|$\vectorunit{a}$ `\vectorunit{a}`|
|$a \dotproduct b$ `a \dotproduct b`|$a \crossproduct b$ `a \crossproduct b`|
|$\gradient{\psi}$ `\gradient{\psi}`|$\laplacian{\psi}$ `\laplacian{\psi}`|
|$\divergence{B}$ `\divergence{B}`|$\curl{E}$ `\curl{E}`|

## Style, Color, Size, and Font

**Class Assignment**
Expand Down
5 changes: 3 additions & 2 deletions src/functions/op.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ defineFunction({
"\\arcsin", "\\arccos", "\\arctan", "\\arctg", "\\arcctg",
"\\arg", "\\ch", "\\cos", "\\cosec", "\\cosh", "\\cot", "\\cotg",
"\\coth", "\\csc", "\\ctg", "\\cth", "\\deg", "\\dim", "\\exp",
"\\hom", "\\ker", "\\lg", "\\ln", "\\log", "\\sec", "\\sin",
"\\sinh", "\\sh", "\\tan", "\\tanh", "\\tg", "\\th",
"\\hom", "\\ker", "\\lg", "\\ln", "\\log", "\\rank", "\\Res",
"\\sec", "\\sin", "\\sinh", "\\sh", "\\tan", "\\tanh", "\\tr", "\\Tr",
"\\trace", "\\tg", "\\th",
],
props: {
numArgs: 0,
Expand Down
23 changes: 23 additions & 0 deletions src/macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,29 @@ defineMacro("\\set", "\\bra@set{\\{\\,}{\\mid}{}{\\,\\}}");
// actuarialangle.dtx
defineMacro("\\angln", "{\\angl n}");

//////////////////////////////////////////////////////////////////////
// physics.sty

// This package contains some macros widely useful in physics.
// https://ctan.math.washington.edu/tex-archive/macros/latex/contrib/physics/physics.pdf

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("\\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("\\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("\\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("\\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("\\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?

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("\\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("\\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("\\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.


// Custom Khan Academy colors, should be moved to an optional package
defineMacro("\\blue", "\\textcolor{##6495ed}{#1}");
defineMacro("\\orange", "\\textcolor{##ffa500}{#1}");
Expand Down