Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\text choice in recipes #317

Closed
ChrisRackauckas opened this issue Oct 11, 2024 · 4 comments
Closed

\text choice in recipes #317

ChrisRackauckas opened this issue Oct 11, 2024 · 4 comments

Comments

@ChrisRackauckas
Copy link
Contributor

I'm cleaning up the Symbolics latexify output:

Screenshot 2024-10-11 at 5 29 32 PM

You can see that the compound equations don't look quite right. I am fixing the + stuff manually, but I don't know how to make the symbol names use \text{capacitor.v} instead of just being directly written out. Also an option for \textrm would be nice.

@gustaphe
Copy link
Collaborator

I'm not sure I understand the problem, could you write an mwe?

@ChrisRackauckas
Copy link
Contributor Author

using Symbolics, Latexify
@variables myvariable
latexify(myvariable)

produces myvariable and not \text{myvariable}

@gustaphe
Copy link
Collaborator

gustaphe commented Oct 12, 2024

Something like

diff --git a/src/latexify_recipes.jl b/src/latexify_recipes.jl
index e7c9ac54..296c8c32 100644
--- a/src/latexify_recipes.jl
+++ b/src/latexify_recipes.jl
@@ -47,12 +47,13 @@ end
 
 recipe(n) = latexify_derivatives(cleanup_exprs(_toexpr(n)))
 
-@latexrecipe function f(n::Num)
+@latexrecipe function f(n::Num; variable_style="")
     env --> :equation
     cdot --> false
     fmt --> FancyNumberFormatter(5)
 
-    return recipe(n)
+    isempty(variable_style) && return recipe(n)
+    return LaTeXString(string("\\", variable_style, "{", recipe(n), "}"))
 end
 
 @latexrecipe function f(z::Complex{Num})

would do it if Num was just a single variable. I don't know exactly how to get around the problem that

julia> set_default(; variable_style="text")
julia> @variables x y
julia> latexify(x+y)
L"\begin{equation}
\mathrm{x + y}
\end{equation}
"

, it arises from the fact that x + y is a Num. I don't know the Symbolics internals, is there a type that encapsulates the concept of a single variable?

@ChrisRackauckas
Copy link
Contributor Author

Thanks, that's all I needed to see. I was able to figure out how to add it directly JuliaSymbolics/Symbolics.jl#1305

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants