arrows/
arrows.rs

1use std::{error::Error,
2          fs::File,
3          f64::NAN,
4          io::Write,
5          process::Command};
6use curve_sampling::Sampling;
7
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}