RustGnuplot icon indicating copy to clipboard operation
RustGnuplot copied to clipboard

Latex support in labels.

Open dineshadepu opened this issue 6 years ago • 1 comments

Hello,

First, thank you for the crate. Very helpful.

I am trying to add symbols in the labels, like, nano, or $\lambda$ symbols.

Is this supported currently?

I tried doing this,

    let mut fg = Figure::new();
    fg.axes2d()
        .set_x_label("Normal contact displacement ($$\lambda$$ nano m)", &[])
        .set_y_label("Normal contact force (kN)", &[])
        .set_x_range(Fix(0.), Fix(400.))
        .set_y_range(Fix(0.), Fix(12.));

But it fails.

dineshadepu avatar Nov 29 '19 14:11 dineshadepu

So the story for this is pretty bad on gnuplot's side. The only "official" way I could find for now is to use the "epslatex" terminal (ideally with the 'standalone' option), which lets you write code like this:

use gnuplot::*;

fn main()
{
  let mut fg = Figure::new();
  fg.axes2d().set_title(r"$\\lambda$", &[]);
  fg.set_terminal("epslatex standalone", "output.tex");
  fg.show().unwrap();
}

Then, you run that program you get a .ps and .tex files that you can pass through pdflatex to get the final pdf output. It's hardly ideal.

If all you need is some symbols and super- and sub-scripts, then at least as of https://github.com/SiegeLord/RustGnuplot/commit/1d9866d99d628aa3bf10734e0c735db7c408b2e3 it should work to do things like "λ^2", i.e. use unicode + caret/underscores.

I'll see what I can do to make this better.

SiegeLord avatar Dec 02 '19 01:12 SiegeLord