typst / biblatex

A Rust crate for parsing and writing BibTeX and BibLaTeX files.
Apache License 2.0
120 stars 15 forks source link

Certain LaTeX text accents are incorrectly displayed #37

Closed pjhuxford closed 9 months ago

pjhuxford commented 9 months ago

Consider the following code

use biblatex::Bibliography;

fn main() {
    let src = r"@article {test, author = {L\^{e} D\~{u}ng Tr\'{a}ng}}";
    let bibliography = Bibliography::parse(src).unwrap();
    let entry = bibliography.get("test").unwrap();
    let author = entry.author().unwrap();
    println!("{}", author[0]);
}

When run, this code prints

L^e D~ung Tráng

The correct output should be

Lê Dũng Tráng

pjhuxford commented 9 months ago

The problem is that if a backslash \ proceeds any of LaTeX's reserved characters, then the reserved character is printed literally. This is always correct behavior for many reserved characters, however if either ^ or ~ are preceded by a backslash and given a non-empty argument, then they should be viewed as commands which can modify their argument by adding a circumflex or combining tilde.

I've submitted a pull request here that fixes this, in a rather hacky way.