typst icon indicating copy to clipboard operation
typst copied to clipboard

Ending in whitespace breaks smartquotes

Open Enivex opened this issue 2 years ago • 4 comments

Description

"This works"

" This works"

"This does not work "

results in image

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

Enivex avatar May 27 '23 18:05 Enivex

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.

alerque avatar May 27 '23 18:05 alerque

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?

Enivex avatar May 27 '23 18:05 Enivex

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.

alerque avatar May 27 '23 18:05 alerque

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.

lynn avatar May 29 '23 20:05 lynn

Just to note that " " results in:

Screenshot 2023-08-02 at 18 59 50

Can this really be correct?

wlupton avatar Aug 02 '23 18:08 wlupton

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.

alerque avatar Aug 12 '23 17:08 alerque

Based on the conversation, I'm going to close this as can't-fix.

laurmaedje avatar Nov 14 '23 21:11 laurmaedje