Struct 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)
8fn main() -> Result<(), Box<dyn Error>> {
9    let s = Sampling::from_iter([[0., 0.], [1., 1.], [NAN, NAN],
10                                 [1., 1.], [3., -1.]]);
11    s.latex().arrow_pos(0.3).write(&mut File::create("/tmp/arrow0.tex")?)?;
12
13    let s = Sampling::uniform(|x| -0.7 * (x - 1.).powi(2), 0., 2.5).build();
14    s.latex().arrow_pos(0.6).write(&mut File::create("/tmp/arrow1.tex")?)?;
15
16
17    File::create("/tmp/arrows.tex")?.write_all(
18        r"\documentclass{article}
19\usepackage{tikz}
20\begin{document}
21\begin{tikzpicture}[x=3cm, y=3cm]
22  \draw[->] (-1.2, 0) -- (3.2, 0);
23  \draw[->] (0, -1.2) -- (0, 1.7);
24  \foreach \x in {-1, -0.5, 0.5, 1, 1.5,..., 3}{
25    \draw (\x, 3pt) -- (\x, -3pt) node[below]{$\scriptstyle \x$};
26  }
27  \foreach \y in {-1, -0.5, 0.5, 1, 1.5}{
28    \draw (3pt, \y) -- (-3pt, \y) node[left]{$\scriptstyle \y$};
29  }
30  \begin{scope}[color=blue, line width=1pt]
31    \input{arrow0.tex}
32  \end{scope}
33  \begin{scope}[color=orange, line width=1pt]
34    \input{arrow1.tex}
35  \end{scope}
36\end{tikzpicture}
37\end{document}".as_bytes())?;
38
39    std::env::set_current_dir("/tmp")?;
40    Command::new("pdflatex")
41        .args(["-interaction=batchmode", "arrows.tex"]).output()?;
42    Ok(())
43}
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)
6fn main() -> Result<(), Box<dyn Error>> {
7    let s = cs::Sampling::from_iter(
8        [[0., -0.5], [1.5, 1.], [0.2, 0.5], [0.3, 1.5], [1., 0.6],
9         [NAN, NAN], [-0.5, 0.5], [-1., 0.], [0.5, 0.5]]);
10    s.write(&mut File::create("/tmp/clip0.dat")?)?;
11    s.latex().write(&mut File::create("/tmp/clip0.tex")?)?;
12    let s1 = s.clip(cs::BoundingBox { xmin: 0., xmax: 1.,
13                                      ymin: 0., ymax: 1. });
14    s1.write(&mut File::create("/tmp/clip1.dat")?)?;
15    s1.latex().write(&mut File::create("/tmp/clip1.tex")?)?;
16
17    Ok(())
18}
More examples
Hide additional examples
examples/latex_speed.rs (line 17)
6fn main() -> Result<(), Box<dyn Error>> {
7    let path = "/tmp/latex_speed.tex";
8    let mut fh = File::create(path)?;
9    write!(fh, "\\documentclass[12pt,a4paper]{{article}}\n\
10                \\usepackage{{tikz}}\n\
11                \\begin{{document}}\n\
12                \\begin{{tikzpicture}}\n")?;
13    let n = 40_000;
14    println!("Run \"latex {}\" measure LaTeX speed with {} points.\n",
15             path, n);
16    let s = Sampling::uniform(f64::sin, -6., 6.).n(n).build();
17    s.latex().write(&mut fh)?;
18    write!(fh, "\\end{{tikzpicture}}\n\
19                \\end{{document}}")?;
20    Ok(())
21}
examples/arrows.rs (line 11)
8fn main() -> Result<(), Box<dyn Error>> {
9    let s = Sampling::from_iter([[0., 0.], [1., 1.], [NAN, NAN],
10                                 [1., 1.], [3., -1.]]);
11    s.latex().arrow_pos(0.3).write(&mut File::create("/tmp/arrow0.tex")?)?;
12
13    let s = Sampling::uniform(|x| -0.7 * (x - 1.).powi(2), 0., 2.5).build();
14    s.latex().arrow_pos(0.6).write(&mut File::create("/tmp/arrow1.tex")?)?;
15
16
17    File::create("/tmp/arrows.tex")?.write_all(
18        r"\documentclass{article}
19\usepackage{tikz}
20\begin{document}
21\begin{tikzpicture}[x=3cm, y=3cm]
22  \draw[->] (-1.2, 0) -- (3.2, 0);
23  \draw[->] (0, -1.2) -- (0, 1.7);
24  \foreach \x in {-1, -0.5, 0.5, 1, 1.5,..., 3}{
25    \draw (\x, 3pt) -- (\x, -3pt) node[below]{$\scriptstyle \x$};
26  }
27  \foreach \y in {-1, -0.5, 0.5, 1, 1.5}{
28    \draw (3pt, \y) -- (-3pt, \y) node[left]{$\scriptstyle \y$};
29  }
30  \begin{scope}[color=blue, line width=1pt]
31    \input{arrow0.tex}
32  \end{scope}
33  \begin{scope}[color=orange, line width=1pt]
34    \input{arrow1.tex}
35  \end{scope}
36\end{tikzpicture}
37\end{document}".as_bytes())?;
38
39    std::env::set_current_dir("/tmp")?;
40    Command::new("pdflatex")
41        .args(["-interaction=batchmode", "arrows.tex"]).output()?;
42    Ok(())
43}

Auto Trait Implementations§

§

impl<'a> Freeze for LaTeX<'a>

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.