Expand TeX letter and symbol commands to Unicode
This commit is contained in:
1 parent
0b2265580f
commit
0200967982
4 files changed
+68
-5
No files matched your search
+64
-1
@@ -4295,6 +4295,21 @@ fn verb_run(rest: &str) -> Option<(String, usize)> {
|
||||
/// Recognise a text command that stands for a printable character.
|
||||
fn text_symbol(rest: &str) -> Option<(&'static str, usize)> {
|
||||
const SYMBOLS: &[(&str, &str)] = &[
|
||||
("\\textthreequarters", "\u{be}"),
|
||||
("\\textonequarter", "\u{bc}"),
|
||||
("\\textonehalf", "\u{bd}"),
|
||||
("\\textperthousand", "\u{2030}"),
|
||||
("\\textregistered", "\u{ae}"),
|
||||
("\\texttrademark", "\u{2122}"),
|
||||
("\\textparagraph", "\u{b6}"),
|
||||
("\\textsection", "\u{a7}"),
|
||||
("\\textsterling", "\u{a3}"),
|
||||
("\\textdegree", "\u{b0}"),
|
||||
("\\textcurrency", "\u{a4}"),
|
||||
("\\texteuro", "\u{20ac}"),
|
||||
("\\textyen", "\u{a5}"),
|
||||
("\\textcent", "\u{a2}"),
|
||||
("\\textmu", "\u{b5}"),
|
||||
("\\textbackslash", "\\"),
|
||||
("\\textasciitilde", "~"),
|
||||
("\\textasciicircum", "^"),
|
||||
@@ -4315,6 +4330,27 @@ fn text_symbol(rest: &str) -> Option<(&'static str, usize)> {
|
||||
("\\ldots", "\u{2026}"),
|
||||
("\\dots", "\u{2026}"),
|
||||
("\\TeX", "TeX"),
|
||||
("\\SS", "SS"),
|
||||
("\\AE", "\u{c6}"),
|
||||
("\\OE", "\u{152}"),
|
||||
("\\AA", "\u{c5}"),
|
||||
("\\DH", "\u{d0}"),
|
||||
("\\TH", "\u{de}"),
|
||||
("\\NG", "\u{14a}"),
|
||||
("\\ae", "\u{e6}"),
|
||||
("\\oe", "\u{153}"),
|
||||
("\\aa", "\u{e5}"),
|
||||
("\\dh", "\u{f0}"),
|
||||
("\\th", "\u{fe}"),
|
||||
("\\ng", "\u{14b}"),
|
||||
("\\ss", "\u{df}"),
|
||||
("\\oe", "\u{153}"),
|
||||
("\\o", "\u{f8}"),
|
||||
("\\O", "\u{d8}"),
|
||||
("\\l", "\u{142}"),
|
||||
("\\L", "\u{141}"),
|
||||
("\\i", "\u{131}"),
|
||||
("\\j", "\u{237}"),
|
||||
("\\S", "\u{a7}"),
|
||||
("\\P", "\u{b6}"),
|
||||
];
|
||||
@@ -4327,7 +4363,10 @@ fn text_symbol(rest: &str) -> Option<(&'static str, usize)> {
|
||||
.next()
|
||||
.map_or(true, |character| !character.is_ascii_alphabetic())
|
||||
{
|
||||
return Some((replacement, command.len()));
|
||||
// TeX swallows the spaces that follow a control word.
|
||||
let trimmed = after.trim_start_matches([' ', '\t', '\n']);
|
||||
let skipped = after.len() - trimmed.len();
|
||||
return Some((replacement, command.len() + skipped));
|
||||
}
|
||||
}
|
||||
None
|
||||
@@ -9195,6 +9234,13 @@ mod inline_tests {
|
||||
assert!(inline_runs("\\LaTeX{}", ParagraphFont::Roman).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn letter_commands_paint_unicode_glyphs() {
|
||||
let svg = preview_json("Stra\\ss e").expect("preview");
|
||||
assert!(svg.contains(">ß</text>"), "missing sharp s: {svg}");
|
||||
assert!(!svg.contains("\\ss"), "command leaked: {svg}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_superscript_paints_smaller_and_higher() {
|
||||
let svg = preview_json("E = mc\\textsuperscript{2}").expect("preview");
|
||||
@@ -9221,6 +9267,23 @@ mod inline_tests {
|
||||
assert!(!json.contains("LaTeX{}"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn letter_and_symbol_commands_render_unicode() {
|
||||
assert_eq!(
|
||||
inline_runs("Stra\\ss e", ParagraphFont::Roman),
|
||||
Some(vec![(ParagraphFont::Roman, "Straße".to_string())])
|
||||
);
|
||||
assert_eq!(
|
||||
inline_runs("\\ae\\oe\\aa", ParagraphFont::Roman),
|
||||
Some(vec![(ParagraphFont::Roman, "æœå".to_string())])
|
||||
);
|
||||
assert_eq!(
|
||||
inline_runs("\\o\\l\\dh\\th", ParagraphFont::Roman),
|
||||
Some(vec![(ParagraphFont::Roman, "øłðþ".to_string())])
|
||||
);
|
||||
assert_eq!(inline_runs("\\in and \\only", ParagraphFont::Roman), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_superscripts_and_subscripts_split_sized_runs() {
|
||||
assert_eq!(
|
||||
|
||||
Reference in new issue
Block a user