Conversation
|
I agree that a feature flag is a better way to deal with this (probably 2 features, one for braille and one for language). You are correct that MathCAT currently requires "en". I thought that was also true for "UEB". I suspect that both could be removed as defaults with some effort at the cost of generating errors instead of some sort of speech or braille. You have to be careful about pruning the braille ASCIIMath and LaTeX because they are used for copy. If you don't allow copying in those formats, then it is probably a non issue, but testing is needed. If no braille is needed, it is likely that all or most of braille.rs can be cfg'd out as can a little bit of speech.rs, thus shrinking the size of the binary some more. |
|
Thanks for looking at it, and for the warning about copy, which I had not considered at all. Features rather than environment variables: agreed, and two families is what I had in mind too, one per language and one per braille code. I will rewrite it that way. One design question before I do, because cargo features are additive and "only English" is a subtractive statement. The way to express it is a default feature that carries everything: [features]
default = ["rules-all"]
rules-all = ["lang-all", "braille-all"]
lang-en = []
braille-asciimath = []Then every existing user is unaffected, because they get On the fallbacks: I said something different in an earlier version of this comment and I have changed my mind, so please ignore that. Removing them is the better answer, and my own pull request description already contains the reason. With only So if you are willing to have If you would rather not touch the fallbacks at all, the patch works without it: it force-keeps On ASCIIMath and LaTeX being used for copy: this is the part I am glad you raised. I had only thought about reading, so I would have shipped a feature set that silently broke copying for someone. Two things follow:
On cfg'ing out I will push the features version in the next few days and leave the environment-variable commit in the history for reference rather than in the branch. |
|
It is too bad that cargo features are either on or off and can't take values. So you are right that forces something like It also means keeping thoses lists up-to-date which is error-prone. But I don't see a way around that. As for copying: that is not in MathCAT directly. That is left up to the application. See https://github.com/daisy/MathCATForPython/blob/main/addon/globalPlugins/MathCAT/MathCAT.py#L394C1-L448C1 along with maybe some of the lines after it. |
118b03e to
1878919
Compare
|
Thanks, that copy pointer was exactly what I needed. I've pushed the features version, with the layout you sketched, and updated the description. On the lists being error-prone: Two smaller things came out of testing:
I left the fallbacks themselves alone for now. Cfg'ing out |
…mbeds Every language and braille code has a feature, all on by default through rules-all, so existing builds embed exactly the same rules.zip. A build that turns off default features and names a subset embeds only those directories. en is always kept because the library falls back to it, a subset with no braille code keeps UEB so set_rules_dir still succeeds, and the staged prefs.yaml BrailleCode default is pointed at a kept code when Nemeth was pruned. build.rs fails if a Rules directory has no feature in lang-all or braille-all, so the lists cannot silently fall behind.
1878919 to
e6d1ae9
Compare
Why
I use MathCAT in Paperback, a screen reader friendly document reader, to read MathML in EPUB and HTML as AsciiMath. It works really well, thank you for it.
I only ever ask for one language (
en) and one braille code (ASCIIMath). Withinclude-zip, my binary carries all fifteen languages and all nine braille codes anyway, becausebuild.rsstages the wholeRulestree into onerules.zipandshim_filesystem.rsembeds it. That is 857 KB of the binary, and about 790 KB of it is rules nothing in my program can ask for. The same weight lands in the iOS framework and the Android libraries, where app size is something users notice.What this does
Every
Rules/LanguagesandRules/Brailledirectory gets a feature, and all of them are on by default:A consumer that wants a subset writes:
A default build is unchanged. I checked that the embedded
rules.zipis byte for byte identical to the one frommain. The features only affect whatinclude-zipembeds. Withoutinclude-zip, the Rules directory is read from disk as before.A build that subsets prints a
cargo::warningnaming what it kept, so nobody is surprised later by a missing language.Keeping the lists up to date
build.rscompares theRules/LanguagesandRules/Brailledirectories withlang-allandbraille-allin Cargo.toml. If a directory has no feature listed there, the build fails with:This runs on every build, not only
include-zipones, so whoever adds a language finds out right away instead of it quietly dropping out of every build. The parse handles the one-entry-per-line form thatcargo publishwrites. I built the packaged.crateas a dependency to confirm that.Fallbacks
The library still falls back by name, so the patch works around those fallbacks rather than changing them:
enis always embedded, becausefind_fileandset_style_filefall back to it. It is about 78 KB compressed.UEB. Without any braille directory,set_rules_dirfails withWasn't able to find/read MathCAT default language directory: Rules\Braille\, even for a speech-only caller.BrailleCodedefault inprefs.yaml(Nemeth) was pruned, the staged copy points at a code that was kept. Without this,enplusASCIIMathfails the same way.One known rough edge remains. With only
enembedded,set_preference("Language", "es")returnsOk(())and then speaks English. Turning that into an error means changing the fallbacks themselves, which is better as its own change.Copy as ASCIIMath / LaTeX
Applications that copy math as ASCIIMath or LaTeX, like the NVDA add-on, do it through the braille API. They need
braille-asciimath/braille-latex. The comment above the features in Cargo.toml says so.Tested
A small consumer, built with
include-zip:rules-allesspeech "a partido por b", Nemeth⠹⠁⠌⠃⠼lang-en,braille-asciimatha/blang-esonlycargo clippy --all-targets --features include-zipis clean for the changed files.cargo testpasses exceptshim_filesystem::tests::in_memory_filesystem_shim, which fails on Windows onmaintoo.