1
2
3
4
5
6
7
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#![doc = include_str!("../README.md")]
#![cfg_attr(not(any(doc, test, doctest, feature = "lin_sys")), no_std)]
#![cfg_attr(feature = "adt_const_params", feature(adt_const_params))]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
pub mod env;
pub mod fmt;
pub mod latex_modes;
pub mod latex_flavors;
#[cfg(feature = "lin_sys")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "lin_sys")))]
pub mod lin_sys;
#[cfg(feature = "hyperref")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "hyperref")))]
pub mod hyperref;
mod macros {
/// A macro for relatively convenient writing of LaTeX code.
///
/// # Example
///
/// ```
/// use core::fmt::Write;
/// use nalgebra_latex::inplace_format;
/// use partial_application::partial;
///
/// let mut s = String::new();
/// inplace_format!(s +=
/// "It works with string literals.\n" ;
/// let (q, a) = ("Does it work with weird let statements?\n", "It does!\n");
/// |s: &mut String| s.write_str(q).unwrap() ;
/// |s: &mut String| s.write_str(a).unwrap() ;
/// partial!(Write::write_str => _, "It also supports functional style.")
/// => |res: Result::<_,_>| res.unwrap() ;
/// );
/// let mut lines = s.lines();
///
/// assert_eq!(lines.next(), Some("It works with string literals."));
/// assert_eq!(lines.next(), Some("Does it work with weird let statements?"));
/// assert_eq!(lines.next(), Some("It does!"));
/// assert_eq!(lines.next(), Some("It also supports functional style."));
/// assert_eq!(lines.next(), None);
/// ```
#[macro_export]
macro_rules! inplace_format {
($buf:ident += $str:literal ; $($tail:tt)*) => {
$buf += $str;
inplace_format!($buf += $($tail)*);
};
($buf:ident += let $p:pat = $expr:expr ; $($tail:tt)*) => {
let $p = $expr;
inplace_format!($buf += $($tail)*);
};
($buf:ident += $closure_or_macro:expr ; $($tail:tt)*) => {
($closure_or_macro)(&mut $buf);
inplace_format!($buf += $($tail)*);
};
($buf:ident += $closure_or_macro:expr $(=> $nxt_closure_or_macro:expr)+ ; $($tail:tt)*) => {
let _inplace_tmp = ($closure_or_macro)(&mut $buf);
$(
let _inplace_tmp = ($nxt_closure_or_macro)(_inplace_tmp);
)+
inplace_format!($buf += $($tail)*);
};
($buf:ident += ) => {};
}
}