ReTeX / ReX

ReX - typesetting mathematics
122 stars 8 forks source link

I'm having trouble compiling this library (proposing a solution) #37

Closed colbyn closed 3 years ago

colbyn commented 3 years ago

I'm having trouble compiling this library.

The issue seems to be with the static_map dependency. Notably,

   Compiling font_types v0.1.0 (/Users/colbyn/Scratch/ReX/fonts/types)
   Compiling stix2 v0.1.0 (/Users/colbyn/Scratch/ReX/fonts/stix2)
error: proc-macro derive panicked
    --> fonts/stix2/src/variants.rs:1660:65
     |
1660 |   pub static HORZ_VARIANTS: static_map::Map<u32, GlyphVariants> = static_map! {
     |  _________________________________________________________________^
1661 | |     Default: GlyphVariants { constructable: None, replacements: &[] },
1662 | |     0x302 => GlyphVariants { // uni0302
1663 | |         constructable: None,
...    |
2864 | |
2865 | | };
     | |_^
     |
     = help: message: assertion failed: input.starts_with(LEADING)
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: proc-macro derive panicked
    --> fonts/stix2/src/variants.rs:5:65
     |
5    |   pub static VERT_VARIANTS: static_map::Map<u32, GlyphVariants> = static_map! {
     |  _________________________________________________________________^
6    | |     Default: GlyphVariants { constructable: None, replacements: &[] },
7    | |     0x2F => GlyphVariants { // slash
8    | |         constructable: None,
...    |
1656 | |
1657 | | };
     | |_^
     |
     = help: message: assertion failed: input.starts_with(LEADING)
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: proc-macro derive panicked
    --> fonts/stix2/src/symbols.rs:12:61
     |
12   |   pub static SYMBOLS: static_map::Map<&'static str, Symbol> = static_map! {
     |  _____________________________________________________________^
13   | |     Default: Symbol { unicode: 0x00, atom_type: AtomType::Accent },
14   | |     // unicode-math.dtx command table
15   | |     "mathexclam" => Symbol { unicode: 0x21, atom_type: AtomType::Close }, // 33
...    |
2537 | |     "|" => Symbol { unicode: 0x2016, atom_type: AtomType::Fence }, // 8214
2538 | | };
     | |_^
     |
     = help: message: assertion failed: input.starts_with(LEADING)
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: proc-macro derive panicked
    --> fonts/stix2/src/glyphs.rs:15:50
     |
15   |   pub static GLYPHS: static_map::Map<u32, Glyph> = static_map! {
     |  __________________________________________________^
16   | |     Default: Glyph { unicode: 0x0000_u32, bbox: BBox(fontunit!(0), fontunit!(0), fontunit!(0), fontunit!(0)), attachment: fontunit!(0), a...
17   | |
18   | |     0x0020_u32 => Glyph { unicode: 0x0020_u32, bbox: BBox(fontunit!(0), fontunit!(0), fontunit!(0), fontunit!(0)), attachment: fontunit!(...
...    |
5290 | |     0x1d455_u32 => Glyph { unicode: 0x210e_u32, bbox: BBox(fontunit!(47), fontunit!(-10), fontunit!(549), fontunit!(706)), attachment: fo...
5291 | | };
     | |_^
     |
     = help: message: assertion failed: input.starts_with(LEADING)
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: cannot find macro `__static_map__construct_map` in this scope
    --> fonts/stix2/src/variants.rs:1660:65
     |
1660 |   pub static HORZ_VARIANTS: static_map::Map<u32, GlyphVariants> = static_map! {
     |  _________________________________________________________________^
1661 | |     Default: GlyphVariants { constructable: None, replacements: &[] },
1662 | |     0x302 => GlyphVariants { // uni0302
1663 | |         constructable: None,
...    |
2864 | |
2865 | | };
     | |_^
     |
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: cannot find macro `__static_map__construct_map` in this scope
    --> fonts/stix2/src/variants.rs:5:65
     |
5    |   pub static VERT_VARIANTS: static_map::Map<u32, GlyphVariants> = static_map! {
     |  _________________________________________________________________^
6    | |     Default: GlyphVariants { constructable: None, replacements: &[] },
7    | |     0x2F => GlyphVariants { // slash
8    | |         constructable: None,
...    |
1656 | |
1657 | | };
     | |_^
     |
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

The library seems to be unmaintained.

Any interest in replacing the library with something simple?

Perhaps something akin to:


macro_rules! indexfor {
    ($keys:expr, $target:expr) => {{
        // let mut index: Option<usize> = None;
        let mut index: usize = 0;
        let mut result: Option<usize> = None;
        for k in $keys {
            if $target == *k {
                result = Some(index);
                break;
            }
            index = index + 1;
        }
        result.unwrap()
    }};
}

macro_rules! hardcoded {
    ($name:ident ($kty:ty, $vty:ty) {$($key:expr => $value:expr),* $(,)?}) => {
        #[allow(non_upper_case_globals)]
        pub static Entries: &'static [($kty, $vty)] = &[
            $(
                ($key, $value),
            )*
        ];

        macro_rules! $name {
            ($id:expr) => {{
                let index = indexfor!(&[$($key),*], $id);
                Entries[index].1
            }};
        }
    };
}

hardcoded!{
    get_symbol(&str, &str) {
        "a" => "lorem",
        "b" => "ipsum",
        "c" => "red",
    }
}

fn main() {
    let x = get_symbol!("a");
    println!("Output: {:#?}", x);
}

Instead of a Map like data structure, we just replace it with a static array, using the getter generated by hardcoded!, i.e. get_symbol!(key).

PS: Awesome library! I can see this replacing libraries like iosMath, that offer math rendering without embedding a browser.

I wish I had known about this library when I started working on Subscript for my school math notes.

colbyn commented 3 years ago

Nvm, I suppose this is unnecessary given the rewrite over here.