# Pgfplotsx with \\mathbb

**URL:** https://discourse.julialang.org/t/pgfplotsx-with-mathbb/92747
**Category:** Visualization
**Tags:** latex, pgfplotsx
**Created:** [January 10, 2023, 9:00am UTC](https://discourse.julialang.org/t/pgfplotsx-with-mathbb/92747 "2023-01-10T09:00:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Elyco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elyco/32/18418_2.png) [@Elyco](https://discourse.julialang.org/u/Elyco)
#### Post date: [January 10, 2023, 9:00am UTC](https://discourse.julialang.org/t/pgfplotsx-with-mathbb/92747/1 "2023-01-10T09:00:38Z")

</div>

Hi,  
I’m trying to put a latex label `\mathbb{R}` with `pgfplotsx()` backend.  
But I get an error:

```julia
using Plots
using LaTeXStrings
pgfplotsx()
plot(rand(10), label=L"\mathcal{R}^{2N}") |> display # works!
plot(rand(10), label=L"\mathbb{R}^{2N}") |> display # not works :(

```

result:

```julia
! Undefined control sequence.
<recently read> \mathbb 
        
l.55 \end{axis}
             
ERROR: The latex command `lualatex jl_v6JARqh6hq.tex` failed
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] savepdf(filename::String, td::PGFPlotsX.TikzDocument; latex_engine::PGFPlotsX.LaTeXEngine, buildflags::Vector{String}, run_count::Int64, tmp::String)
    @ PGFPlotsX ~/.julia/packages/PGFPlotsX/qpAgV/src/tikzdocument.jl:202
  [3] savesvg(filename::String, td::PGFPlotsX.TikzDocument; latex_engine::PGFPlotsX.LaTeXEngine, buildflags::Vector{String}, keep_pdf::Bool)
    @ PGFPlotsX ~/.julia/packages/PGFPlotsX/qpAgV/src/tikzdocument.jl:272
  [4] save(filename::String, td::PGFPlotsX.TikzDocument; include_preamble::Bool, latex_engine::PGFPlotsX.LaTeXEngine, buildflags::Vector{String}, dpi::Int64, showing_ide::Bool)
    @ PGFPlotsX ~/.julia/packages/PGFPlotsX/qpAgV/src/tikzdocument.jl:84
  [5] show(f::IOBuffer, #unused#::MIME{Symbol("image/svg+xml")}, td::PGFPlotsX.TikzDocument)
    @ PGFPlotsX ~/.julia/packages/PGFPlotsX/qpAgV/src/tikzdocument.jl:294
  [6] _show(io::IOBuffer, mime::MIME{Symbol("image/svg+xml")}, plt::Plots.Plot{Plots.PGFPlotsXBackend})
    @ Plots ~/.julia/packages/Plots/gzYVM/src/backends/pgfplotsx.jl:1315
  [7] #invokelatest#2
    @ ./essentials.jl:729 [inlined]
  [8] invokelatest
    @ ./essentials.jl:726 [inlined]
  [9] show
    @ ~/.julia/packages/Plots/gzYVM/src/output.jl:237 [inlined]
 [10] __binrepr(m::MIME{Symbol("image/svg+xml")}, x::Plots.Plot{Plots.PGFPlotsXBackend}, context::Nothing)
    @ Base.Multimedia ./multimedia.jl:159
 [11] display(d::VSCodeServer.InlineDisplay, m::MIME{Symbol("image/svg+xml")}, x::Plots.Plot{Plots.PGFPlotsXBackend})
    @ VSCodeServer ./strings/string.jl:0
 [12] display(d::VSCodeServer.InlineDisplay, mime::String, x::Any)
    @ Base.Multimedia ./multimedia.jl:216
 [13] display(d::VSCodeServer.InlineDisplay, x::Plots.Plot{Plots.PGFPlotsXBackend})
    @ VSCodeServer ~/.vscode-server/extensions/julialang.language-julia-1.38.2/scripts/packages/VSCodeServer/src/display.jl:165
 [14] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:328
 [15] |>(x::Plots.Plot{Plots.PGFPlotsXBackend}, f::typeof(display))
    @ Base ./operators.jl:911
 [16] top-level scope
    @ Untitled-1:5

```

Can `pushPGFPlotsPreamble` helps in some way?  
Elyasaf

---

<div class="post-metadata">

### Author: ![tamasgal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamasgal/32/27946_2.png) [@tamasgal](https://discourse.julialang.org/u/tamasgal)
#### Post date: [January 10, 2023, 10:17am UTC](https://discourse.julialang.org/t/pgfplotsx-with-mathbb/92747/2 "2023-01-10T10:17:20Z")

</div>

I don’t use `Plots.jl` but `PGFPlotsX.jl` directly but I think the preamble should be picked up anyways, try this above the call to `plot()`:

```julia
import PGFPlotsX
push!(PGFPlotsX.CUSTOM_PREAMBLE, "\\usepackage{amsfonts}")

```

---

<div class="post-metadata">

### Author: ![Elyco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elyco/32/18418_2.png) [@Elyco](https://discourse.julialang.org/u/Elyco)
#### Post date: [January 10, 2023, 10:21am UTC](https://discourse.julialang.org/t/pgfplotsx-with-mathbb/92747/3 "2023-01-10T10:21:10Z")

</div>

Thanks! Works like a magic!
