# Symbolics.jl and Latexify.jl: customize latex representations?

**URL:** https://discourse.julialang.org/t/symbolics-jl-and-latexify-jl-customize-latex-representations/72180
**Category:** General Usage
**Tags:** latex, symbolics
**Created:** [November 27, 2021, 7:03pm UTC](https://discourse.julialang.org/t/symbolics-jl-and-latexify-jl-customize-latex-representations/72180 "2021-11-27T19:03:43Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![adomasbaliuka](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adomasbaliuka/32/29790_2.png) [@adomasbaliuka](https://discourse.julialang.org/u/adomasbaliuka)
#### Post date: [November 27, 2021, 7:03pm UTC](https://discourse.julialang.org/t/symbolics-jl-and-latexify-jl-customize-latex-representations/72180/1 "2021-11-27T19:03:43Z")

</div>

_(Julia 1.6)_  
I deal with equations from publications and the variables there have lots of subscripts and superscripts. They cannot be represented as Julia variable names and I would prefer not to compromise. For example, I might want something like this:

```julia
using LaTeXStrings,Latexify, Symbolics
@variables x_plus # this is a variable
 # this is what I would like the variable to be written as
repr_map = Dict(x_plus => L"x^{+}_{A,\alpha_{1}}")

```

Now I want to do something like

```julia
@latexify x_plus + x_plus^2 + factorial(x_plus)
 # and also give the macro my `repr_map`, tell it somehow that I want factorial written as !...

```

and get x^{+}\_{A,\alpha\_{1}} + {(x^{+}\_{A,\alpha\_{1}})}^2 + (x^{+}\_{A,\alpha\_{1}})!.

Is there a way to do this? One thing I tried was modifying `Latexify.jl` (this file: [Latexify.jl/…/function2latex.jl](https://github.com/korsbo/Latexify.jl/blob/9416101a443de4895e5f7bce03cc3b4f49cd7e57/src/function2latex.jl)) to add my own symbols. This doesn’t really work for everything and of course having to modify the library isn’t a good solution. Is there a way to add “custom rules” to Latexify?

If there is no way currently, would such an idea be consistent with what Latexify.jl is trying to do? If so, I would be willing to help implement it.

---

<div class="post-metadata">

### Author: ![Lilith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lilith/32/27492_2.png) [@Lilith](https://discourse.julialang.org/u/Lilith)
#### Post date: [November 27, 2021, 7:12pm UTC](https://discourse.julialang.org/t/symbolics-jl-and-latexify-jl-customize-latex-representations/72180/2 "2021-11-27T19:12:37Z")

</div>

Perhaps something like this (does not work) would be a good API:

```julia
x_plus = L"x^{+}_{A,\alpha_{1}}"
@latexify $x_plus + $x_plus^2 + factorial($x_plus)

```

---

<div class="post-metadata">

### Author: ![adomasbaliuka](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adomasbaliuka/32/29790_2.png) [@adomasbaliuka](https://discourse.julialang.org/u/adomasbaliuka)
#### Post date: [November 27, 2021, 7:16pm UTC](https://discourse.julialang.org/t/symbolics-jl-and-latexify-jl-customize-latex-representations/72180/3 "2021-11-27T19:16:21Z")

</div>

Something like this might be possible too

```julia
@variables var"x^{+}_{A,\alpha_{1}}"
x_plus = var"x^{+}_{A,\alpha_{1}}"
# continue to use x_plus.

```

It partially works already. However, when using this, the latex representation crashes (doesn’t use enough parentheses or braces).

```julia
julia> latexify(x_plus + x_plus^2 + factorial(x_plus))
L"\begin{equation}
x^{+}_{{A,\alpha\_{1}}} + x^{+}_{{A,\alpha\_{1}}}^{2} + \mathrm{factorial}\left( x^{+}_{{A,\alpha\_{1}}} \right)
\end{equation}
"

```

(latex rendering error: “Double exponent: use braces to clarify”)

Also, this won’t help with the `factorial` to `!` issue.

---

<div class="post-metadata">

### Author: ![adomasbaliuka](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adomasbaliuka/32/29790_2.png) [@adomasbaliuka](https://discourse.julialang.org/u/adomasbaliuka)
#### Post date: [January 12, 2022, 2:06pm UTC](https://discourse.julialang.org/t/symbolics-jl-and-latexify-jl-customize-latex-representations/72180/4 "2022-01-12T14:06:41Z")

</div>

The problem with the “latex rendering error” in my last post can be partially solved by adding even more brackets to the variable name (symbol). Of course, this does not help with things like `factorial`.

```julia

@variables var"{x^{+}_{A,\alpha_{1}}}"

```

Note that in the output, the second-order-subscript “1” is not represented properly because Latexify escapes the underscore. I don’t think there is a way to mitigate this right now, short of editing `Latexify.jl` sources.

---

<div class="post-metadata">

### Author: ![0xMoritz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/0xmoritz/32/218251_2.png) [@0xMoritz](https://discourse.julialang.org/u/0xMoritz)
#### Post date: [August 15, 2025, 3:00pm UTC](https://discourse.julialang.org/t/symbolics-jl-and-latexify-jl-customize-latex-representations/72180/5 "2025-08-15T15:00:52Z")

</div>

The subscripts drove me insane until I found  
`set_default(snakecase=false)`

For other lost souls out there, see Latexify documentation → List of possible arguments
