Substitution in latex

I’m guessing the answer is no, but…

Is there any way of substituting a pronumeral in a latex expression with a value (and retaining it as latex, not evaluating it).

E.g. if x=2 turning
3x + 7
into
3
2+7

I’d say yes, but it depends on where the pronumeral is being entered. You can insert CL variables into latex using ${ }. You can also use when-otherwise to keep the x. For example, if x is being entered in an input:

myLatex= when not(input.submitted) `3x+7`
otherwise `3(${input.latex})+7`