Smart Quotes for Docutils¶
- Author
Günter Milde, based on SmartyPants by John Gruber, Brad Choate, and Chad Miller
- Contact
- Revision
$Revision$
- Date
$Date$
- License
Released under the terms of the 2-Clause BSD license
- Abstract
This document describes the Docutils smartquotes module.
目录
Description¶
The “smart_quotes” configuration setting triggers the SmartQuotes transformation on Text nodes that includes the following steps:
Straight quotes (
"
and'
) into “curly” quote charactersdashes (
--
and---
) into en- and em-dash entitiesthree consecutive dots (
...
or. . .
) into an ellipsis entity.
This means you can write, edit, and save your documents using plain old ASCII – straight quotes, plain dashes, and plain dots – while Docutils generates documents with typographical quotes, dashes, and ellipses.
Advantages:
Typing speed (especially when blind-typing).
The possibility to change the quoting style of the complete document with just one configuration option.
Typographical quotes with just 7-bit ASCII characters in the source.
However, there are algorithmic shortcomings for 2 reasons:
Dual use of the “ASCII-apostrophe” (’) as single quote and apostrophe.
Languages that do not use whitespace around words.
So, please consider also Why You Might Not Want to Use “Smart” Quotes in Your Documents.
Escaping¶
The SmartQuotes transform does not modify characters in literal text such as source code, maths, or literal blocks.
If you need literal straight quotes (or plain hyphens and periods) in normal text, you can backslash escape the characters to preserve ASCII-punctuation.
- class booktabs¶
Input |
Output |
Input |
Output |
|
---|---|---|---|---|
|
\ |
|
... |
|
|
" |
|
-- |
|
|
' |
|
` |
This is useful, for example, when you want to use straight quotes as foot and inch marks:
6'2" tall; a 17" monitor.
Localization¶
Quotation marks have a variety of forms in different languages and media.
SmartQuotes inserts quotation marks depending on the language of the current block element and the value of the “smart_quotes” setting.1 There is built-in support for the following languages:2
- run-in
- af
- language-af
“‘Afrikaans’ quotes”
- af-x-altquot
- language-af-x-altquot
“‘Afrikaans’ alternative quotes”
- ca
- language-ca
“‘Catalan’ quotes”
- ca-x-altquot
- language-ca-x-altquot
“‘Catalan’ alternative quotes”
- cs
- language-cs
“‘Czech’ quotes”
- cs-x-altquot
- language-cs-x-altquot
“‘Czech’ alternative quotes”
- da
- language-da
“‘Danish’ quotes”
- da-x-altquot
- language-da-x-altquot
“‘Danish’ alternative quotes”
- de
- language-de
“‘German’ quotes”
- de-x-altquot
- language-de-x-altquot
“‘German’ alternative quotes”
- de-ch
- language-de-ch
“‘Swiss-German’ quotes”
- el
- language-el
“‘Greek’ quotes”
- en
- language-en
“‘English’ quotes”
- en-uk-x-altquot
- language-en-uk-x-altquot
“‘British’ alternative quotes” (swaps single and double quotes)
- eo
- language-eo
“‘Esperanto’ quotes”
- es
- language-es
“‘Spanish’ quotes”
- es-x-altquot
- language-es-x-altquot
“‘Spanish’ alternative quotes”
- et
- language-et
“‘Estonian’ quotes” (no secondary quote listed in Wikipedia)
- et-x-altquot
- language-et-x-altquot
“‘Estonian’ alternative quotes”
- eu
- language-eu
“‘Basque’ quotes”
- fi
- language-fi
“‘Finnish’ quotes”
- fi-x-altquot
- language-fi-x-altquot
“‘Finnish’ alternative quotes”
- fr
- language-fr
“‘French’ quotes”
- fr-x-altquot
- language-fr-x-altquot
“‘French’ alternative quotes”
- fr-ch
- language-fr-ch
“‘Swiss-French’ quotes”
- fr-ch-x-altquot
- language-fr-ch-x-altquot
“‘Swiss-French’ alternative quotes” (narrow no-break space, see http://typoguide.ch/)
- gl
- language-gl
“‘Galician’ quotes”
- he
- language-he
“‘Hebrew’ quotes”
- he-x-altquot
- language-he-x-altquot
“‘Hebrew’ alternative quotes”
- hr
- language-hr
“‘Croatian’ quotes”
- hr-x-altquot
- language-hr-x-altquot
“‘Croatian’ alternative quotes”
- hsb
- language-hsb
“‘Upper Sorbian’ quotes”
- hsb-x-altquot
- language-hsb-x-altquot
“‘Upper Sorbian’ alternative quotes”
- hu
- language-hu
“‘Hungarian’ quotes”
- is
- language-is
“‘Icelandic’ quotes”
- it
- language-it
“‘Italian’ quotes”
- it-ch
- language-it-ch
“‘Swiss-Italian’ quotes”
- it-x-altquot
- language-it-x-altquot
“‘Italian’ alternative quotes”
- ja
- language-ja
“‘Japanese’ quotes”
- lt
- language-lt
“‘Lithuanian’ quotes”
- lv
- language-lv
“‘Latvian’ quotes”
- nl
- language-nl
“‘Dutch’ quotes”
- nl-x-altquot
- language-nl-x-altquot
“‘Dutch’ alternative quotes”
- pl
- language-pl
“‘Polish’ quotes”
- pl-x-altquot
- language-pl-x-altquot
“‘Polish’ alternative quotes”
- pt
- language-pt
“‘Portuguese’ quotes”
- pt-br
- language-pt-br
“‘Portuguese (Brazil)’ quotes”
- ro
- language-ro
“‘Romanian’ quotes”
- ru
- language-ru
“‘Russian’ quotes”
- sh
- language-sh
“‘Serbo-Croatian’ quotes”
- sh-x-altquot
- language-sh-x-altquot
“‘Serbo-Croatian’ alternative quotes”
- sk
- language-sk
“‘Slovak’ quotes”
- sk-x-altquot
- language-sk-x-altquot
“‘Slovak’ alternative quotes”
- sl
- language-sl
“‘Slovenian’ quotes”
- sl-x-altquot
- language-sl-x-altquot
“‘Slovenian’ alternative quotes”
- sr
- language-sr
“‘Serbian’ quotes”
- sr-x-altquot
- language-sr-x-altquot
“‘Serbian’ alternative quotes”
- sv
- language-sv
“‘Swedish’ quotes”
- sv-x-altquot
- language-sv-x-altquot
“‘Swedish’ alternative quotes”
- tr
- language-tr
“‘Turkish’ quotes”
- tr-x-altquot
- language-tr-x-altquot
“‘Turkish’ alternative quotes”
- uk
- language-uk
“‘Ukrainian’ quotes”
- uk-x-altquot
- language-uk-x-altquot
“‘Ukrainian’ alternative quotes”
- zh-cn
- language-zh-cn
“‘Chinese (China)’ quotes”
- zh-tw
- language-zh-tw
“‘Chinese (Taiwan)’ quotes”
Quotes in text blocks in a non-configured language are kept as plain quotes:
- undefined
- language-undefined-example
“‘Undefined’ quotes”
- 1
Tags with the non-standard extension
-x-altquot
define the quote set used with the “smart_quotes” setting value"alt"
.- 2
The definitions for language-dependend typographical quotes can be extended or overwritten using the “smartquotes_locales” setting.
The following example ensures a correct leading apostrophe in
's Gravenhage
(at the cost of incorrect leading single quotes) in Dutch and sets French quotes to double and single guillemets with inner spacing:smartquote-locales: nl: „”’’ fr: « : »:‹ : ›
Caveats¶
Why You Might Not Want to Use “Smart” Quotes in Your Documents¶
For one thing, you might not care.
Most normal, mentally stable individuals do not take notice of proper typographic punctuation. Many design and typography nerds, however, break out in a nasty rash when they encounter, say, a restaurant sign that uses a straight apostrophe to spell “Joe’s”.
If you’re the sort of person who just doesn’t care, you might well want to continue not caring. Using straight quotes – and sticking to the 7-bit ASCII character set in general – is certainly a simpler way to live.
Even if you do care about accurate typography, you still might want to think twice before “auto-educating” the quote characters in your documents. As there is always a chance that the algorithm gets it wrong, you may instead prefer to use the compose key or some other means to insert the correct Unicode characters into the source.
Algorithmic Shortcomings¶
The ASCII character (u0027 APOSTROPHE) is used for apostrophe and single quotes. If used inside a word, it is converted into an apostrophe:
- language-fr
Il dit : “C’est ‘super’ !”
At the beginning or end of a word, it cannot be distinguished from a single quote by the algorithm.
The right single quotation mark character – used to close a secondary (inner) quote in English – is also “the preferred character to use for apostrophe” (Unicode). Therefore, “educating” works as expected for apostrophes at the end of a word, e.g.,
Mr. Hastings’ pen; three days’ leave; my two cents’ worth.
However, when apostrophes are used at the start of leading contractions,
“educating” will turn the apostrophe into an opening secondary quote. In
English, this is not the apostrophe character, e.g., 'Twas brillig
is “miseducated” to
‘Twas brillig.
In other locales (French, Italian, German, …), secondary closing quotes differ from the apostrophe. A text like:
.. class:: language-de-CH
"Er sagt: 'Ich fass' es nicht.'"
becomes
«Er sagt: ‹Ich fass› es nicht.›»
with a single closing guillemet in place of the apostrophe.
In such cases, it’s best to use the recommended apostrophe character (’) in the source:
’Twas brillig, and the slithy tovesDid gyre and gimble in the wabe;All mimsy were the borogoves,And the mome raths outgrabe.
History¶
The smartquotes module is an adaption of “SmartyPants” to Docutils.
John Gruber did all of the hard work of writing this software in Perl for Movable Type and almost all of this useful documentation. Chad Miller ported it to Python to use with Pyblosxom.
Portions of the SmartyPants original work are based on Brad Choate’s nifty MTRegex plug-in. Brad Choate also contributed a few bits of source code to this plug-in. Brad Choate is a fine hacker indeed. Jeremy Hedley and Charles Wiltgen deserve mention for exemplary beta testing of the original SmartyPants.
Internationalization and adaption to Docutils by Günter Milde.