julialatexplots.jl# Change which font package Plots.jl is using for latex strings?

I am trying to make a plot with the math symbol:

in the ylabel, which appears in latex as "\mathcal{I}", but this specific symbol cannot be made in Plots.jl. When entering "\mathcal{I}", you instead get:

Here is a MWE:

```
using Plots
using LaTeXStrings
plot([1],[1],ylabel=L"\mathcal{I}")
```

Which produces:

The wrong symbol on the y-axis. I have gathered that this is because Plots.jl is using a different font package. Is there any way to change which font package it uses?

I have many many plots, entire libraries really, written using Julia Plots. The convention in my field is to use "\mathcal{I}" and so it would be a great pain for me to change everything in my paper to use "\mathcal{J}" just because this one library cannot print the right symbol.

Any help would be appreciated.

Edit: Thanks to advice from @BallpointBen, I have tried the following code:

```
default(;fontfamily="Bookman"); plot([1],[1],ylabel=L"\mathcal{I}")
```

Unfortunately, for me this produces the error:

I should point out that it works fine if one renders empty latex or not latex at all. For example, the following code works:

```
default(;fontfamily="Bookman"); plot([1],[1],xlabel="",ylabel=L"")
```

It is only when at least one character in the latex string is asked for (e.g. L"1") that there is a problem. I further realised that the following actually works to get the right symbol:

```
default(;fontfamily="Times Roman");plot([1],[1],ylabel="𝓘")
```

Which produces:

Quite a few font families work by just inserting this literal character, but alas, if one tries to include latex as well, one gets the same error. That is, I try

```
default(;fontfamily="Times Roman"); plot([1],[1],ylabel=string("𝓘",L"1"))
```

And obtain:

One final idea that does not work is trying to make the 𝓘 character normal text within the latex string as follows:

```
default(;fontfamily="Times Roman"); plot([1],[1],ylabel=L"\textrm{𝓘}")
```

Which produces the same output as the first picture that I sent showing the error.

I am looking into solving this error.

Solution

When using the GR backend, you can find the list of available fonts here. You can set the default font of Plots.jl using `default`

. You have a lot of fonts to choose from, but one that (sort of) works is Bookman.

```
julia> default(; fontfamily="Bookman"); plot([1],[1],ylabel=L"\mathcal{I}")
```

Or you can set the font directly:

```
julia> plot([1],[1], ylabel=L"\mathcal{I}", yguidefont=font("Bookman"))
```

Result:

Unfortunately this results the LateX being pixelated — not sure why.

Also unfortunate is that the Unicode character `U+2110`

Script Capital I, which might've been a suitable substitute, is rendered as something like ℐ in basically every font.

Of course, you do not need to use the GR backend. The PGFPlotsX backend uses LaTeX natively (how? not sure, I think it writes tikx and renders it). You will need to `]add PGFPlotsX`

.

```
julia> pgfplotsx()
Plots.PGFPlotsXBackend()
julia> plot([1],[1],ylabel=L"\mathcal{I}")
julia> savefig("fig.pdf")
```

This produces a (high-res) PDF, which I've converted to an image below:

- Julia: is there a function to obtain the version number of a package?
- Get permutation of one array based on the size ordering of the other array
- Making Julia show different plots in different windows
- How to get equally scaled axes with Plots in Julia
- Scatter plot of two rows of a DataFrame in Julia using Plotly
- Adding constraints to jump model from dict
- Non-iterable argument to a function called by Julia `map`?
- Compute row sums and column sums efficiently in Julia
- Julia copying folder into an existing folder
- How to replace a function in Julia?
- How to force Julia to use multiple threads for matrix multiplication?
- Can Revise.jl handle `ERROR: LoadError: invalid redefinition of constant`?
- Define piecewise function with automatic broadcasting in Julia
- julia Handling time difference in dataframe
- Fast tensor-dot on sparse arrays with GPU in any programming language?
- Why do allocations occur during broadcasting assignment to a preallocated array?
- Comparing RK4 to Euler method
- How to put even numbers from matrix in separate vector in Julia?
- Number of iterations performed by a for-loop in Julia
- Can I redefine a function, but still use the old definition within the new definition?
- how do I use analytical form as gradient with ! function?
- Julia equivalent to R `as.numeric()`
- Why does Float16(1.1)-Float16(1)=Float16(0.0996)?
- Julia manual and defining an infix operator
- In Julia, how to convert a unsigned number to a signed number like in C?
- Julia Package DataFrames 1.6.1 doesn't recognize old version DataFrames 1.3.4 file
- Convert Julia DataFrame to an array of bytes for compression
- How to suppress svg output by IJulia in Jupyter notebooks
- how to get the documentation of a julia function in a vscode notebook?
- Passing command-line arguments to a Pluto Notebook