# Specific fractions w/ LaTeXStrings

**URL:** <https://discourse.julialang.org/t/specific-fractions-w-latexstrings/77355>\
**Category:** Visualization\
**Tags:** latex, plots, gr, latexstrings\
**Created:** [March 3, 2022, 1:30pm UTC](https://discourse.julialang.org/t/specific-fractions-w-latexstrings/77355 "2022-03-03T13:30:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![met-j](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/met-j/32/21919_2.png) [@met-j](https://discourse.julialang.org/u/met-j)\
**Post date:** [March 3, 2022, 1:30pm UTC](https://discourse.julialang.org/t/specific-fractions-w-latexstrings/77355/1 "2022-03-03T13:30:03Z")

</div>

I am not fully satisfied with the text I can produce with `LaTeXStrings`.  
Some (/many) commands only produce a question mark.

Which LaTeX commands are available?  
Is it possible to load LaTeX packages?

LaTeX has support for context specific fractions like `\dfrac{}{}` and `\tfrac{}{}` but also `\sfrac{}{}`.

With the `nicefaction` package there is even `\nicefrac{}{}`.

Is any of this available?  
How could I find out the limits of the `LaTeXString` implementation? (Without just crawling through the source code)

---

<div class="post-metadata">

**Author:** ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)\
**Post date:** [March 3, 2022, 1:34pm UTC](https://discourse.julialang.org/t/specific-fractions-w-latexstrings/77355/2 "2022-03-03T13:34:09Z")

</div>

I think this issue: [Support \displaystyle · Issue #36 · JuliaStrings/LaTeXStrings.jl · GitHub](https://github.com/stevengj/LaTeXStrings.jl/issues/36) will answer your question.

Quoting the part I think is relevant:

> LaTeXStrings does not do _any_ formatting. The _only_ thing it does is allow you to easily construct strings containing LaTeX equations without have to do lots of escapes.

In short it’s not LS that limits what you see, it’s what interprets the LS (e.g. MathJax if you use something like Pluto). So to fix your issue, you have to figure out what is rendering the LS in your case and how/if you can pass additional settings to it.

Maybe see also [MathJaxRenderer.jl](https://github.com/MichaelHatherly/MathJaxRenderer.jl) and [Latexify.jl](https://github.com/korsbo/Latexify.jl)

---

<div class="post-metadata">

**Author:** ![met-j](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/met-j/32/21919_2.png) [@met-j](https://discourse.julialang.org/u/met-j)\
**Post date:** [March 3, 2022, 4:07pm UTC](https://discourse.julialang.org/t/specific-fractions-w-latexstrings/77355/3 "2022-03-03T16:07:22Z")

</div>

Thanks. That’s what I was expecting.

Can anyone give me a hint on how `Plots` with the `GR` backend would interpret `LaTeXStrings`? (Sort of a as a direction before I go down into the rabbit hole)

I’d assume this gets either to the GR side or even to the display _terminal_ (in gnuplot terms).  
So would it differ if I view it in a GKS QtTerm or save the figure as PNG or PDF?

---

<div class="post-metadata">

**Author:** ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)\
**Post date:** [March 3, 2022, 4:48pm UTC](https://discourse.julialang.org/t/specific-fractions-w-latexstrings/77355/4 "2022-03-03T16:48:57Z")

</div>

I don’t know enough of Plots/GR to answer satisfactorily.

One note that you _could_ maybe use either the PGF backend or actually just use PGFPlotsX for full latex support (the latter also happens to be very fast btw).

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [March 3, 2022, 7:56pm UTC](https://discourse.julialang.org/t/specific-fractions-w-latexstrings/77355/5 "2022-03-03T19:56:22Z")

</div>

Linking a [related post](https://discourse.julialang.org/t/nice-fonts-with-plots-gr-and-latexstrings/60037/19) and some code to play with below, FWIW.

Not all the LaTeX fraction options you’ve listed seem to be available in `Plots gr()` renderer.

```julia
using LaTeXStrings, Plots; gr(size=(200,100))
plot(lims=(-1,1), framestyle=:none)
annotate!(-1, 0, L"\dfrac{3}{2}")
annotate!(0, 0, L"e^{\frac{1}{2} + c}")
annotate!(1, 0, L"\frac{3}{2}")

```

 ![Plots_gr_MathJax](https://global.discourse-cdn.com/julialang/original/3X/7/7/77b13ecea7ebd52c23b3b6a6308757f9825f98f7.png)

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [March 3, 2022, 8:28pm UTC](https://discourse.julialang.org/t/specific-fractions-w-latexstrings/77355/6 "2022-03-03T20:28:56Z")

</div>

GR uses its own latex-like function in C (?) to do this, basically the backend behind the backend rolls its own TeX.

If it’s important to you to get the full range of TeX I recommend `pgfplots()`.

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [March 3, 2022, 8:32pm UTC](https://discourse.julialang.org/t/specific-fractions-w-latexstrings/77355/7 "2022-03-03T20:32:57Z")

</div>

[https://github.com/sciapp/gr/blob/master/lib/gr/mathtex2.c](https://github.com/sciapp/gr/blob/master/lib/gr/mathtex2.c)

This file and its siblings contain the code for GR’s tex-handling.
