Forum Feature requests

straight quotes to smart quotes

bthecss
Hello,
Do you have options for replacing straight quotes on a global scale to smart quotes? I am also testing Prince for Books and this is something that OCD designers, like myself, who enjoy your changes in that would love to see.
Thanks
mn4367
One way would be to use prince-text-replace, the other way is via JavaScript on text nodes. I think there is/was a builtin Prince JavaScript function to replace text, but I forgot its name and I didn't find it in the docs.
mikeday
Quotes can be tricky, for example the ambiguity between single quotes and apostrophes, which makes it difficult to do with a single text-replace or regular expression.

There is a simple JavaScript example showing one way to do it here:

https://gist.github.com/karbassi/6216484

However I suspect that this will not cope with quotes that cross element boundaries, such as quotes containing <br> or <span> or other inline formatting elements.

There are other scripts available as plugins for various blogging systems, although they tend to be significantly more complex.
bthecss
Just checking in to see if there is a chance that Prince for Books will eventually, by default, use smart quotes instead of straight quotes. Smart quotes are preferred—by far—in the publishing world and straight quote usage is limited to measurements.

So having the default of smart quotes makes more sense for something intended for book publishing instead of the other way around. Authors can then search and replace the entities for straight quotes as needed.
pjrm
I'm not sure that you understood mikeday's 9 Sep 2018 comment: that by using javascript such as that he linked to, Prince can already convert ASCII quotation marks to opening & closing curly quotation marks.

However, asking Prince or a javascript program to do this conversion has caveats in that if the ASCII input uses the straightforward scheme that ASCII apostrophe can represent either opening or closing single curly quote, then there isn’t always a unique valid conversion: ASCII « 'and » might represent either the start of a quotation or the word ‘hand’ with an elided ‘h’. Similarly, testing for presence of a matching closing quotation mark is unreliable because of an ambiguity with apostrophe of either another elision or of possession after a word ending in ‘s’, or because of the convention of using an unmatched opening quotation mark for each subsequent paragraph of a multi-paragraph quotation.

Also, as you point out, ASCII quotation marks should sometimes not be converted to curly quotes at all, but to measurement marks (u+2032 &prime; and u+2033 &Prime;), or should occasionally even be retained as ASCII quotation marks, in a passage that's actually discussing something typed.

Some alternative solutions:
  • A lot of the software used by book authors for creating text (Scrivener, Ulysses, most word processors) allow converting typed ASCII quotation marks to curly quotes as one types. Such software still faces the same ambiguities as discussed, so it’s up to the author to notice when the software makes the wrong guess (or to learn the cases where the software gets it wrong, and to type something slightly different accordingly, and later do a global search and replace).
  • Some input methods built into your windowing system can do the job. iOS has a "smart punctuation" option. X11’s built-in simple input engine can replace chosen strings of key presses with chosen corresponding textual strings (man XCompose).
  • Regular expression find-and-replace, using interactive replacement for the ambiguous cases. (This assumes that you have a text editor that allows interactive replacement of regular expressions. Emacs is one such text editor, though it’s somewhat heavy-weight if you haven’t used it before and don’t intend to use it other than for this one task.)
  • Whatever method you used to create those em dashes in your post.
pjrm
Forgot to add:

If this is for text that you enter from now on rather than for existing copy, then consider typing backtick/grave (« ` », top left key on many qwerty keyboards) rather than ASCII apostrophe for opening single quote, to reduce the ambiguity, and because a one-to-one mapping is actually easier for some of the options in that list.

[And a minor correction: I was thinking of the fact that each subsequent para of the multi-paragraph quotation that starts with an opening quotation mark, but it’s all but the last paragraph where the quotation mark is unbalanced.]