Programmatically creating parameters in ModelingToolkit.jl leads to unexpected outcome

I am trying to create programmatically a parameter (with @parameter) with ModelingToolkit.jl. While I am succeeding, the outcome is not exactly what I wish for. Here are the two examples:

@variables t            # independent variable (time)
dDt = Differential(t)   # define an operator for the differentiation w.r.t. time
@variables T(t) = 300.0 # dependent

function lhs1(timescale)
    pars = @parameters τ_T = timescale
    τvar = first(pars)
    return τvar*dDt(T)

function lhs2(variable, timescale)
    varsymbol = Symbol(:τ_, Symbol(variable))
    pars = (@parameters $(varsymbol) = timescale)
    τvar = first(pars)
    return τvar*dDt(variable)

lhs2(T, 5.0)

which give:

julia> lhs1(5.0)

julia> lhs2(T, 5.0)

as you can see, in the second case the created parameter is first not displayed correctly, and second, it is not a parameter at all, it is presented as a function of time. What do I have to do to make lhs2 give exactly the same expression as lhs1?

EDIT: The second problem, that T(t) is displayed, happens because of casting the variable T into a symbol, which includes the (t). So I know how to fix that. The first problem of being displayed as var"..." I don’t know how to fix.


Interestingly, solving the second issue also solved the first. Simply doing

    varsymbol = Symbol(:τ_, Symbol(string(variable)[1:end-3]))

solves the problem!

Thanks @ChrisRackauckas but this function doesn’t seem to exist, and I just updated:

  [961ee093] ModelingToolkit v8.69.1

ERROR: UndefVarError: `name` not defined
 [1] getproperty(x::Module, f::Symbol)
   @ Base .\Base.jl:31
 [2] top-level scope
   @ REPL[2]:1

oh sorry, ModelingToolkit.getname