The above LaTex string is bad syntax -- here's a simplified illustration of what is needed -- your expression is far more complex; I'm not even going to attempt to encode it. Not that it's not doable, it's just a lot of tedium.
I'll illustrate writing a variable into an output string that will write a fraction --
This results in
Your mission, should you choose to undertake it, is to write the appropriate formatting string into which you can insert the necessary variables' values by use thereof as illustrated.
It can be whatever it needs be, of course, I just illustrated one small piece; depending upon how much of the above equation you intend to make dynamic, it could be a bunch of values must be passed.
NB: The example code you posted is bad syntax -- perhaps you tried to just copy a subsection of a much longer expression, but it has a spurious "(" in the beginning and is missing the closing matching "$$"
Then there's the deal about whether to use "$" or "$$" that has to do with internals of LaTeX beyond what I understand the difference -- other than I note that if use only single "$" here, the font size is much smaller for some reason.
All that is for a LaTeX guru, not i...
Good luck, undoubtedly you'll need it and much patience!!!