Rewrite Rulesphysics/named-fn-to-operatorname

physics/named-fn-to-operatorname

Rewrite physics-only named functions to operatorname and expand their auto-sized arguments.

Rewrite patterns#

  1. bare\asin\operatorname{asin}
  2. trig-paren\asin(#1)\operatorname{asin}\left(#1\right)
  3. trig-power-paren\asin[#1](#2)\operatorname{asin}^{#1}\left(#2\right)
  4. trig-literal-power\asin[#1]\operatorname{asin}[#1]
  5. operator-brace\tr{#1}\operatorname{tr}\left\{#1\right\}
  6. operator-bracket\tr[#1]\operatorname{tr}\left[#1\right]
  7. operator-paren\tr(#1)\operatorname{tr}\left(#1\right)
  8. plain-operator\erf\operatorname{erf}
  9. trace-alias\trace\operatorname{tr}
  10. long-name-argument\sine(#1)\operatorname{sin}(#1)

Examples#

Each example shows this rule applied in isolation. A complete normalization profile may make additional changes.

Trig power paren nested#

Before

\asin[2](x(y+z)\frac{a}{b})

After this rule

\operatorname{asin}^{2}\left(x(y+z)\frac{a}{b}\right)

The rendered result has pixel differences from the input.

Trig paren#

Before

\sech(\frac{x}{y})

After this rule

\operatorname{sech}\left(\frac{x}{y}\right)

The rendered result has pixel differences from the input.

Trig paren ordinary after#

Before

\csch(x)y

After this rule

\operatorname{csch}\left(x\right)y

The rendered result has pixel differences from the input.

Trig literal power#

Before

\asin[2]x

After this rule

\operatorname{asin}[2]x

The rendered result has pixel differences from the input.

Trig bare#

Before

\csch x

After this rule

\operatorname{csch} x

Rendering verified with the declared packages.

Operator brace#

Before

\tr{\frac{A}{2}}

After this rule

\operatorname{tr}\left\{\frac{A}{2}\right\}

The rendered result has pixel differences from the input.

Remaining 9 examples#

Listed as LaTeX source. Hover over, focus, or tap a row to preview the rendering before and after. 4 render with pixel differences from the input.

ExampleBeforeAfter this rule
Operator bracket literal paren
Pixel differences
\Tr[\frac{A}{2}](t)\operatorname{Tr}\left[\frac{A}{2}\right](t)
Operator paren
Pixel differences
\tr(\frac{A}{2})\operatorname{tr}\left(\frac{A}{2}\right)
Operator subscript literal paren\tr_A(\rho)\operatorname{tr}_A(\rho)
erf literal paren
Pixel differences
\erf(\frac{x}{y})\operatorname{erf}(\frac{x}{y})
trace literal paren
Pixel differences
\trace(\frac{x}{y})\operatorname{tr}(\frac{x}{y})
trace literal brace\trace{\frac{x}{y}}\operatorname{tr}{\frac{x}{y}}
trace capital bare\Trace\rho\operatorname{Tr}\rho
Long name literal paren\sine(\frac{x}{y})\operatorname{sin}(\frac{x}{y})
Long name literal brace\Probability{\frac{A}{2}}\operatorname{Pr}{\frac{A}{2}}

Upstream rules#

Downstream rules#

Same family#

Notes#

Semantics follow LaTeX physics.sty 1.3. None of the short names here has a base command, so each one becomes \operatorname with its printed name (\trace and \Trace print tr and Tr). Trig-family names use \trigbraces (o d()): \asin[n](...), \acos[n](...), \atan[n](...), \csch[n](...), \arccsc[n](...), \acsc[n](...), \sech[n](...), \arcsec[n](...), \asec[n](...), \arccot[n](...), \acot[n](...) get a power and an auto-sized parenthesis fence, and \asin[n] without following parentheses keeps [n] as literal text. \tr{...}, \tr[...], \tr(...), \Tr{...}, \Tr[...], and \Tr(...) use \opbraces (g o d()): only the first group becomes an auto-sized fence. The physics records hold the grabbed group as a d() or paired d<(,)><[,]><{,}> slot, so the parser attaches it. \erf, \trace, and \Trace are plain \DeclareMathOperator commands, so following delimiters stay literal. A command that carries scripts (\tr_A(\rho)) is renamed without grabbing an argument. The long names \sine, \cosine, \naturallogarithm, and \Probability are the original operators saved with \let, so they grab nothing either; the rule rewrites them to \operatorname{sin}, \operatorname{cos}, \operatorname{ln}, and \operatorname{Pr} only when (, [, or a brace group follows, where the short command would grab it. Bare long names are left to the authoring aliases (sine-to-sin, cosine-to-cos, naturallogarithm-to-ln, probability-to-pr), so the long names are touches: every Applied on them removes one long name followed by an argument opener, and bare long names return Skipped. Fidelity is reading: physics closes the fence inside \mathopen{}\mathclose\bgroup...\egroup, which acts as a closing atom, while an explicit \left...\right fence is an inner atom. The explicit fence therefore adds about 1/6 em before the opening delimiter and another 1/6 em after the fence when an ordinary atom or an opening delimiter follows, about 1/3 em in the worst case; script styles show no difference. No compensating space is inserted. MathJax differs: MathJax physics treats \asin[2]x as a power, auto-sizes \erf(...) and \trace(...), hides the braces of \tr{...}, and prints \tr[...] literally.

Disable this rule#

TransformEngine(profile="corpus", disable_rules=["physics/named-fn-to-operatorname"])
new TransformEngine({ profile: 'corpus', disableRules: ['physics/named-fn-to-operatorname'] })

Open in Playground