I don’t think you can get greater control over the LaTeX output, because you can’t control the order of the terms in Symbolics’ internal representation. But I hope someone who knows more than I do about it will correct me.
function symbol(s::String)
x = Symbol(s)
x, = @variables $x
return x
end
r,th,phi = symbols(raw"r \theta \phi")
println(latexify(th))
and output -
\begin{equation}
\theta
\end{equation}
If I use -
function symbol(s::String)
x = Symbol(s)
x, = @variables $x::LiteralReal
return x
end
I get the error -
ERROR: LoadError: AssertionError: @variables expects a tuple of expressions or an expression of a tuple (@variables x y z(t) v[1:3] w[1:2,1:4] or @variables x y z(t) v[1:3] w[1:2,1:4] k=1.0)
Stacktrace:
[1] _parse_vars(macroname::Symbol, type::Type, x::Tuple{Expr}, transform::Function)
@ Symbolics ~/.julia/packages/Symbolics/sITWZ/src/variable.jl:134
[2] _parse_vars(macroname::Symbol, type::Type, x::Tuple{Expr})
@ Symbolics ~/.julia/packages/Symbolics/sITWZ/src/variable.jl:94
[3] var"@variables"(source::LineNumberNode, module::Module, xs::Vararg{Any})
@ Symbolics ~/.julia/packages/Symbolics/sITWZ/src/variable.jl:286
in expression starting at /home/brombo/MyJulia/Bases.jl:12
in expression starting at /home/brombo/MyJulia/Bases.jl:10