Ending in whitespace breaks smartquotes
Description
"This works"
" This works"
"This does not work "
results in
where the last smart quote is flipped.
Reproduction URL
No response
Operating system
No response
Typst version
- [X] I am using the latest version of Typst
I would suggest this is probably correct behavior. Smart quotes can only be so smart while still being sane. Quotes are not always matching pairs that you can assume the next one is the opposite direction.
If your input is dirty (as this appears to be) expect dirty output. The correct fix for this is to not have extraneous spaces in your input.
I would suggest this is probably correct behavior. Smart quotes can only be so smart while still being sane. Quotes are not always matching pairs that you can assume the next one is the opposite direction.
If your input is dirty (as this appears to be) expect dirty output. The correct fix for this is to not have extraneous spaces in your input.
I believe the spaces are required in French actually (though I do not know French).
It could be a documentation issue then, as it's not exactly intuitive when whitespace isn't significant in other situations.
Edit: Some style guides also say you should have space when nesting quotations, i.e "He said, 'Hello' "
One possibility would be to allow for instance ~ (non breaking space) adjacent to a quotation mark?
French is a whole different kettle of fish and doesn't even typically use the same double quotes English uses. Also the spaces required inside its quotation marks should be thin spaces. You can't write an English string and test in an en locale setting and say it's broken for French.
The nested quotes example is also best typset in English with a thin space between the quotes, so “He said, ‘Hello’ ”. It does seem typst does not recognize the non breaking thin space in that scenario, so that would be something to fix.
I think how this should work is that I input "Hello" or "He said, 'Hello'" without any extra spaces, and typst adds whatever thin spaces etc are appropriate for the locale. In fact this appears to be how it works already: see library/src/text/quotes.rs, or try
#text(lang: "fr")[ J'ai dit "Bonjour, 'monsieur'" ]
I'm inclined to agree with @alerque that smart quotes can't be expected to handle messy spaces on the inside of quotes in the input, and that this isn't really a bug.
Just to note that " " results in:
Can this really be correct?
In isolation without further context of content or previous/following open/close statuses, the string " " is nonsensical and impossible to resolve to anything definitively correct. Smart quote algorithms rely on sequence info and proximity to other character classes and without those extra clues many situations are ambiguous with no way to really define what is correct.
Based on the conversation, I'm going to close this as can't-fix.