Rewrite Rulesphysics/named-fn-paren-expand

physics/named-fn-paren-expand

Expand physics power and auto-sized parenthesis arguments of standard named functions.

Rewrite patterns#

  1. trig-paren\sin(#1)\sin\left(#1\right)
  2. trig-power-paren\sin[#1](#2)\sin^{#1}\left(#2\right)

Examples#

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

Trig paren nested#

Before

\sin(x+(y-z)\frac{a}{b})

After this rule

\sin\left(x+(y-z)\frac{a}{b}\right)

The rendered result has pixel differences from the input.

Trig power paren#

Before

\sin[2](\frac{x}{y})

After this rule

\sin^{2}\left(\frac{x}{y}\right)

The rendered result has pixel differences from the input.

Trig paren scripted close#

Before

\cos(\frac{x}{y})^2

After this rule

\cos\left(\frac{x}{y}\right)^2

Rendering verified with the declared packages.

Trig paren ordinary after#

Before

\ln(x)y

After this rule

\ln\left(x\right)y

The rendered result has pixel differences from the input.

Upstream rules#

Same family#

Notes#

Semantics follow LaTeX physics.sty 1.3. These names use \trigbraces (o d()): \sin[n](...), \sinh[n](...), \arcsin[n](...), \cos[n](...), \cosh[n](...), \arccos[n](...), \tan[n](...), \tanh[n](...), \arctan[n](...), \csc[n](...), \sec[n](...), \cot[n](...), \coth[n](...), \log[n](...), \ln[n](...) get a power and an auto-sized parenthesis fence, while \sin{...} grabs nothing. The physics records hold the parentheses as a d() slot, so the parser attaches them, matching nested parentheses as xparse does, and a group that separates the name from the parenthesis, as in {\sin}(x) or \sin{}(x), keeps it literal. The rule leaves unchanged a bare name, a command that carries scripts (\sin^2(x)), and \sin[n] without following parentheses, which LaTeX prints as a literal [n] and MathJax reads as a power. Touches-only convergence: every Applied removes one physics named function with an attached parenthesis argument (the group becomes a \left(...\right) fence and any power moves into a superscript); non-matching nodes return Skipped. enabled_by_packages is pinned to physics because the base records of these names have a different structure signature (no optional power or parenthesis slot), and the active record must come from physics at runtime. 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.

Disable this rule#

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

Open in Playground