Skip to main content
added 359 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
f[n] Defer[1/9] // TeXForm
\frac {1} {9} f (n)

Slightly more genearally,

ClearAll[deferRationalsAndPowers]
deferRationalsAndPowers = ReplaceAll[r : (_Rational | Power[_, -1]) :> Defer[r]];


expr = h[n]/9 + w[a]/b 

enter image description here

expr /. r : (_Rational | Power[_, -1])deferRationalsAndPowers :>@ Defer[r]expr

enter image description here

TeXForm[%]TeXForm @ deferRationalsAndPowers @ expr
\frac{1}{b} w(a)+\frac{1}{9} h(n)
expr2 = 1/2 f[a]^6 + 3/4 f[b]^2 + 8/9 f[c]

enter image description here

deferRationalsAndPowers @ expr2

enter image description here

TeXForm @ deferRationalsAndPowers @ expr2
\frac{1}{2} f(a)^6+\frac{3}{4} f(b)^2+\frac{8}{9} f(c)
f[n] Defer[1/9] // TeXForm
\frac {1} {9} f (n)

Slightly more genearally,

expr = h[n]/9 + w[a]/b 

enter image description here

expr /. r : (_Rational | Power[_, -1]) :> Defer[r]

enter image description here

TeXForm[%]
\frac{1}{b} w(a)+\frac{1}{9} h(n)
f[n] Defer[1/9] // TeXForm
\frac {1} {9} f (n)

Slightly more genearally,

ClearAll[deferRationalsAndPowers]
deferRationalsAndPowers = ReplaceAll[r : (_Rational | Power[_, -1]) :> Defer[r]];


expr = h[n]/9 + w[a]/b 

enter image description here

deferRationalsAndPowers @ expr

enter image description here

TeXForm @ deferRationalsAndPowers @ expr
\frac{1}{b} w(a)+\frac{1}{9} h(n)
expr2 = 1/2 f[a]^6 + 3/4 f[b]^2 + 8/9 f[c]

enter image description here

deferRationalsAndPowers @ expr2

enter image description here

TeXForm @ deferRationalsAndPowers @ expr2
\frac{1}{2} f(a)^6+\frac{3}{4} f(b)^2+\frac{8}{9} f(c)
added 359 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
f[n] Defer[1/9] // TeXForm
\frac {1} {9} f (n)

Slightly more genearally,

expr = h[n]/9 + w[a]/b 

enter image description here

expr /. r : (_Rational | Power[_, -1]) :> Defer[r]

enter image description here

TeXForm[%]
\frac{1}{b} w(a)+\frac{1}{9} h(n)
f[n] Defer[1/9] // TeXForm
\frac {1} {9} f (n)
f[n] Defer[1/9] // TeXForm
\frac {1} {9} f (n)

Slightly more genearally,

expr = h[n]/9 + w[a]/b 

enter image description here

expr /. r : (_Rational | Power[_, -1]) :> Defer[r]

enter image description here

TeXForm[%]
\frac{1}{b} w(a)+\frac{1}{9} h(n)
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

f[n] Defer[1/9] // TeXForm
\frac {1} {9} f (n)