Julia, 76 73 bytes
n->("\$\$\\varphi=1+"*"\\cfrac1{1+"^n*"\\"*"d"^(n>0)*"dots"*"}"^n*"\$\$")
This creates a lambda function that takes a single integer as input and returns the MathJax as a string. To call it, give it a name, e.g. f=n->...
.
Unfortunately both backslashes and dollar signs have to be escaped in Julia strings because they both have special meaning. String concatenation is performed using *
and string repetition with ^
.
Examples:
julia> f(0)
"$$\varphi=1+\dots$$"
julia> f(4)
"$$\varphi=1+\cfrac1{1+\cfrac1{1+\cfrac1{1+\cfrac1{1+\ddots}}}}$$"
And proof that the output is valid MathJax:
$$\varphi=1+\cfrac1{1+\cfrac1{1+\cfrac1{1+\cfrac1{1+\ddots}}}}$$
Suggestions are welcome as always!
Edit: Saved 3 bytes thanks to plannapus!