pub struct LaTeX<'a, D> { /* 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, D> LaTeX<'a, D>
impl<'a, D> LaTeX<'a, D>
Sourcepub fn n(&mut self, n: usize) -> &mut Self
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.
Sourcepub fn color(&mut self, color: RGB8) -> &mut Self
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.
Sourcepub fn arrow(&mut self, arrow: &'a str) -> &mut Self
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.
Sourcepub fn arrow_pos(&mut self, arrow_pos: f64) -> &mut Self
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 10)
7fn main() -> Result<(), Box<dyn Error>> {
8 let s = Sampling::from_iter([[0., 0.], [1., 1.], [f64::NAN, f64::NAN],
9 [1., 1.], [3., -1.]]);
10 s.latex().arrow_pos(0.3).write(&mut File::create("/tmp/arrow0.tex")?)?;
11
12 let s = Sampling::uniform(|x| -0.7 * (x - 1.).powi(2), 0., 2.5).build();
13 s.latex().arrow_pos(0.6).write(&mut File::create("/tmp/arrow1.tex")?)?;
14
15
16 File::create("/tmp/arrows.tex")?.write_all(
17 r"\documentclass{article}
18\usepackage{tikz}
19\begin{document}
20\begin{tikzpicture}[x=3cm, y=3cm]
21 \draw[->] (-1.2, 0) -- (3.2, 0);
22 \draw[->] (0, -1.2) -- (0, 1.7);
23 \foreach \x in {-1, -0.5, 0.5, 1, 1.5,..., 3}{
24 \draw (\x, 3pt) -- (\x, -3pt) node[below]{$\scriptstyle \x$};
25 }
26 \foreach \y in {-1, -0.5, 0.5, 1, 1.5}{
27 \draw (3pt, \y) -- (-3pt, \y) node[left]{$\scriptstyle \y$};
28 }
29 \begin{scope}[color=blue, line width=1pt]
30 \input{arrow0.tex}
31 \end{scope}
32 \begin{scope}[color=orange, line width=1pt]
33 \input{arrow1.tex}
34 \end{scope}
35\end{tikzpicture}
36\end{document}".as_bytes())?;
37
38 std::env::set_current_dir("/tmp")?;
39 Command::new("pdflatex")
40 .args(["-interaction=batchmode", "arrows.tex"]).output()?;
41 Ok(())
42}Sourcepub fn write(&self, f: &mut impl Write) -> Result<(), Error>
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 10)
5fn main() -> Result<(), Box<dyn Error>> {
6 let s = cs::Sampling::from_iter(
7 [[0., -0.5], [1.5, 1.], [0.2, 0.5], [0.3, 1.5], [1., 0.6],
8 [f64::NAN, f64::NAN], [-0.5, 0.5], [-1., 0.], [0.5, 0.5]]);
9 s.write(&mut File::create("/tmp/clip0.dat")?)?;
10 s.latex().write(&mut File::create("/tmp/clip0.tex")?)?;
11 let s1 = s.clip(cs::BoundingBox { xmin: 0., xmax: 1.,
12 ymin: 0., ymax: 1. });
13 s1.write(&mut File::create("/tmp/clip1.dat")?)?;
14 s1.latex().write(&mut File::create("/tmp/clip1.tex")?)?;
15
16 Ok(())
17}More 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 10)
7fn main() -> Result<(), Box<dyn Error>> {
8 let s = Sampling::from_iter([[0., 0.], [1., 1.], [f64::NAN, f64::NAN],
9 [1., 1.], [3., -1.]]);
10 s.latex().arrow_pos(0.3).write(&mut File::create("/tmp/arrow0.tex")?)?;
11
12 let s = Sampling::uniform(|x| -0.7 * (x - 1.).powi(2), 0., 2.5).build();
13 s.latex().arrow_pos(0.6).write(&mut File::create("/tmp/arrow1.tex")?)?;
14
15
16 File::create("/tmp/arrows.tex")?.write_all(
17 r"\documentclass{article}
18\usepackage{tikz}
19\begin{document}
20\begin{tikzpicture}[x=3cm, y=3cm]
21 \draw[->] (-1.2, 0) -- (3.2, 0);
22 \draw[->] (0, -1.2) -- (0, 1.7);
23 \foreach \x in {-1, -0.5, 0.5, 1, 1.5,..., 3}{
24 \draw (\x, 3pt) -- (\x, -3pt) node[below]{$\scriptstyle \x$};
25 }
26 \foreach \y in {-1, -0.5, 0.5, 1, 1.5}{
27 \draw (3pt, \y) -- (-3pt, \y) node[left]{$\scriptstyle \y$};
28 }
29 \begin{scope}[color=blue, line width=1pt]
30 \input{arrow0.tex}
31 \end{scope}
32 \begin{scope}[color=orange, line width=1pt]
33 \input{arrow1.tex}
34 \end{scope}
35\end{tikzpicture}
36\end{document}".as_bytes())?;
37
38 std::env::set_current_dir("/tmp")?;
39 Command::new("pdflatex")
40 .args(["-interaction=batchmode", "arrows.tex"]).output()?;
41 Ok(())
42}Auto Trait Implementations§
impl<'a, D> !RefUnwindSafe for LaTeX<'a, D>
impl<'a, D> !Send for LaTeX<'a, D>
impl<'a, D> !Sync for LaTeX<'a, D>
impl<'a, D> !UnwindSafe for LaTeX<'a, D>
impl<'a, D> Freeze for LaTeX<'a, D>
impl<'a, D> Unpin for LaTeX<'a, D>
impl<'a, D> UnsafeUnpin for LaTeX<'a, D>where
&'a Sampling<D>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more