3
$\begingroup$
In[1]:=f[n]/9 // TeXForm
Out[1]//TeXForm=\frac{f(n)}{9}

but I need \frac{1}{9}f(n) instead.

$\endgroup$
0

1 Answer 1

5
$\begingroup$
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)
$\endgroup$
3
  • $\begingroup$ If the input is an expression, how can I add 'defer' to the coefficients. $\endgroup$ Feb 10, 2022 at 7:07
  • $\begingroup$ For example, the input is 1/2 f[a]^6 + 3/4 f[b]^2 + 8/9 f[c] , how to add 'defer' before each 'f[]' o(TωT)o $\endgroup$ Feb 10, 2022 at 7:15
  • 1
    $\begingroup$ @Patchouli, please see the update. $\endgroup$
    – kglr
    Feb 10, 2022 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.