Struct curve_sampling::LaTeX

source ·
pub struct LaTeX<'a> { /* private fields */ }
Expand description

LaTeX output, created by Sampling::latex.

Example

use std::fs::File;
use curve_sampling::Sampling;
let s = Sampling::from_iter([[0., 0.], [1., 1.]]);
s.latex().write(&mut File::create("target/sampling.tex")?)?;

Implementations§

source§

impl<'a> LaTeX<'a>

source

pub fn n(&mut self, n: usize) -> &mut Self

Set the maximum number of points of a PGF path to n. If it contains more than n points, the sampling curve is drawn as several PGF paths. Default: 20_000.

source

pub fn color(&mut self, color: RGB8) -> &mut Self

Set the color of the curve to color. If not specified the active LaTeX color will be used.

source

pub fn arrow(&mut self, arrow: &'a str) -> &mut Self

Set the type of arrow to draw to arrow. See the documentation of \pgfsetarrowsend in the TikZ manual.

source

pub fn arrow_pos(&mut self, arrow_pos: f64) -> &mut Self

The position of the arrow as a percent of the curve length (in the interval [0.,1.]). If LaTeX::arrow is specified but not this, it defaults to 0.5.

Examples found in repository?
examples/arrows.rs (line 11)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
fn main() -> Result<(), Box<dyn Error>> {
    let s = Sampling::from_iter([[0., 0.], [1., 1.], [NAN, NAN],
                                 [1., 1.], [3., -1.]]);
    s.latex().arrow_pos(0.3).write(&mut File::create("/tmp/arrow0.tex")?)?;

    let s = Sampling::uniform(|x| -0.7 * (x - 1.).powi(2), 0., 2.5).build();
    s.latex().arrow_pos(0.6).write(&mut File::create("/tmp/arrow1.tex")?)?;


    File::create("/tmp/arrows.tex")?.write_all(
        r"\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=3cm, y=3cm]
  \draw[->] (-1.2, 0) -- (3.2, 0);
  \draw[->] (0, -1.2) -- (0, 1.7);
  \foreach \x in {-1, -0.5, 0.5, 1, 1.5,..., 3}{
    \draw (\x, 3pt) -- (\x, -3pt) node[below]{$\scriptstyle \x$};
  }
  \foreach \y in {-1, -0.5, 0.5, 1, 1.5}{
    \draw (3pt, \y) -- (-3pt, \y) node[left]{$\scriptstyle \y$};
  }
  \begin{scope}[color=blue, line width=1pt]
    \input{arrow0.tex}
  \end{scope}
  \begin{scope}[color=orange, line width=1pt]
    \input{arrow1.tex}
  \end{scope}
\end{tikzpicture}
\end{document}".as_bytes())?;

    std::env::set_current_dir("/tmp")?;
    Command::new("pdflatex")
        .args(["-interaction=batchmode", "arrows.tex"]).output()?;
    Ok(())
}
source

pub fn write(&self, f: &mut impl Write) -> Result<(), Error>

Write the sampling to the formatter as PGF/TikZ commands.

Examples found in repository?
examples/clip.rs (line 11)
6
7
8
9
10
11
12
13
14
15
16
17
18
fn main() -> Result<(), Box<dyn Error>> {
    let s = cs::Sampling::from_iter(
        [[0., -0.5], [1.5, 1.], [0.2, 0.5], [0.3, 1.5], [1., 0.6],
         [NAN, NAN], [-0.5, 0.5], [-1., 0.], [0.5, 0.5]]);
    s.write(&mut File::create("/tmp/clip0.dat")?)?;
    s.latex().write(&mut File::create("/tmp/clip0.tex")?)?;
    let s1 = s.clip(cs::BoundingBox { xmin: 0., xmax: 1.,
                                      ymin: 0., ymax: 1. });
    s1.write(&mut File::create("/tmp/clip1.dat")?)?;
    s1.latex().write(&mut File::create("/tmp/clip1.tex")?)?;

    Ok(())
}
More examples
Hide additional examples
examples/latex_speed.rs (line 17)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() -> Result<(), Box<dyn Error>> {
    let path = "/tmp/latex_speed.tex";
    let mut fh = File::create(path)?;
    write!(fh, "\\documentclass[12pt,a4paper]{{article}}\n\
                \\usepackage{{tikz}}\n\
                \\begin{{document}}\n\
                \\begin{{tikzpicture}}\n")?;
    let n = 40_000;
    println!("Run \"latex {}\" measure LaTeX speed with {} points.\n",
             path, n);
    let s = Sampling::uniform(f64::sin, -6., 6.).n(n).build();
    s.latex().write(&mut fh)?;
    write!(fh, "\\end{{tikzpicture}}\n\
                \\end{{document}}")?;
    Ok(())
}
examples/arrows.rs (line 11)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
fn main() -> Result<(), Box<dyn Error>> {
    let s = Sampling::from_iter([[0., 0.], [1., 1.], [NAN, NAN],
                                 [1., 1.], [3., -1.]]);
    s.latex().arrow_pos(0.3).write(&mut File::create("/tmp/arrow0.tex")?)?;

    let s = Sampling::uniform(|x| -0.7 * (x - 1.).powi(2), 0., 2.5).build();
    s.latex().arrow_pos(0.6).write(&mut File::create("/tmp/arrow1.tex")?)?;


    File::create("/tmp/arrows.tex")?.write_all(
        r"\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=3cm, y=3cm]
  \draw[->] (-1.2, 0) -- (3.2, 0);
  \draw[->] (0, -1.2) -- (0, 1.7);
  \foreach \x in {-1, -0.5, 0.5, 1, 1.5,..., 3}{
    \draw (\x, 3pt) -- (\x, -3pt) node[below]{$\scriptstyle \x$};
  }
  \foreach \y in {-1, -0.5, 0.5, 1, 1.5}{
    \draw (3pt, \y) -- (-3pt, \y) node[left]{$\scriptstyle \y$};
  }
  \begin{scope}[color=blue, line width=1pt]
    \input{arrow0.tex}
  \end{scope}
  \begin{scope}[color=orange, line width=1pt]
    \input{arrow1.tex}
  \end{scope}
\end{tikzpicture}
\end{document}".as_bytes())?;

    std::env::set_current_dir("/tmp")?;
    Command::new("pdflatex")
        .args(["-interaction=batchmode", "arrows.tex"]).output()?;
    Ok(())
}

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for LaTeX<'a>

§

impl<'a> !Send for LaTeX<'a>

§

impl<'a> !Sync for LaTeX<'a>

§

impl<'a> Unpin for LaTeX<'a>

§

impl<'a> !UnwindSafe for LaTeX<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.