Debian Codegraph @

docs/user/smartquotes.rst

raw
1 .. include:: ../header.rst
2
3 =========================
4 Smart Quotes for Docutils
5 =========================
6
7 :Author: Günter Milde,
8 based on SmartyPants by John Gruber, Brad Choate, and Chad Miller
9 :Contact: [email protected]
10 :Revision: $Revision: 9906 $
11 :Date: $Date: 2024-08-15 10:43:38 +0200 (Do, 15. Aug 2024) $
12 :License: Released under the terms of the `2-Clause BSD license`_
13 :Abstract: This document describes the Docutils `smartquotes` module.
14
15 .. _2-Clause BSD license: http://opensource.org/licenses/BSD-2-Clause
16
17 .. contents::
18
19 Description
20 ===========
21
22 The `"smart_quotes" configuration setting`_ triggers the SmartQuotes
23 transformation on Text nodes that includes the following steps:
24
25 - Straight quotes (``"`` and ``'``) into "curly" quote characters
26 - dashes (``--`` and ``---``) into en- and em-dash entities
27 - three consecutive dots (``...`` or ``. . .``) into an ellipsis entity.
28
29 This means you can write, edit, and save your documents using plain old
30 ASCII -- straight quotes, plain dashes, and plain dots -- while Docutils
31 generates documents with typographical quotes, dashes, and ellipses.
32
33 Advantages:
34
35 * Typing speed (especially when blind-typing).
36 * The possibility to change the quoting style of the
37 complete document with just one configuration option.
38 * Typographical quotes with just 7-bit ASCII characters in the source.
39
40 However, there are `algorithmic shortcomings`_ for 2 reasons:
41
42 * Dual use of the "ASCII-apostrophe" (') as single quote and apostrophe.
43 * Languages that do not use whitespace around words.
44
45 So, please consider also
46 `Why You Might Not Want to Use "Smart" Quotes in Your Documents`_.
47
48 .. _"smart_quotes" configuration setting:
49 .. _"smart_quotes" setting: config.html#smart-quotes
50
51
52 Escaping
53 ========
54
55 The `SmartQuotes` transform does not modify characters in literal text
56 such as source code, maths, or literal blocks.
57
58 If you need literal straight quotes (or plain hyphens and periods) in normal
59 text, you can `backslash escape`_ the characters to preserve
60 ASCII-punctuation.
61
62 .. class:: booktabs
63
64 ========= ========= == ======== ==========
65 Input Output Input Output
66 ========= ========= == ======== ==========
67 ``\\`` \\ ``\...`` \...
68 ``\"`` \" ``\--`` \--
69 ``\'`` \' ``\``` \`
70 ========= ========= == ======== ==========
71
72 This is useful, for example, when you want to use straight quotes as
73 foot and inch marks:
74
75 6\'2\" tall; a 17\" monitor.
76
77 .. _backslash escape: ../ref/rst/restructuredtext.html#escaping-mechanism
78
79
80 Localization
81 ============
82
83 Quotation marks have a `variety of forms`__ in different languages and
84 media.
85
86 __ https://en.wikipedia.org/wiki/Quotation_mark#Summary_table
87
88 `SmartQuotes` inserts quotation marks depending on the language of the
89 current block element and the value of the `"smart_quotes" setting`_.\
90 [#x-altquot]_
91 There is built-in support for the following languages:\ [#smartquotes-locales]_
92
93 .. class:: run-in
94
95 :af: .. class:: language-af
96
97 "'Afrikaans' quotes"
98
99 :af-x-altquot: .. class:: language-af-x-altquot
100
101 "'Afrikaans' alternative quotes"
102
103 :ca: .. class:: language-ca
104
105 "'Catalan' quotes"
106
107 :ca-x-altquot: .. class:: language-ca-x-altquot
108
109 "'Catalan' alternative quotes"
110
111 :cs: .. class:: language-cs
112
113 "'Czech' quotes"
114
115 :cs-x-altquot: .. class:: language-cs-x-altquot
116
117 "'Czech' alternative quotes"
118
119 :da: .. class:: language-da
120
121 "'Danish' quotes"
122
123 :da-x-altquot: .. class:: language-da-x-altquot
124
125 "'Danish' alternative quotes"
126
127 :de: .. class:: language-de
128
129 "'German' quotes"
130
131 :de-x-altquot: .. class:: language-de-x-altquot
132
133 "'German' alternative quotes"
134
135 :de-ch: .. class:: language-de-ch
136
137 "'Swiss-German' quotes"
138
139 :el: .. class:: language-el
140
141 "'Greek' quotes"
142
143 :en: .. class:: language-en
144
145 "'English' quotes"
146
147 :en-uk-x-altquot: .. class:: language-en-uk-x-altquot
148
149 "'British' alternative quotes" (swaps single and double quotes)
150
151 :eo: .. class:: language-eo
152
153 "'Esperanto' quotes"
154
155 :es: .. class:: language-es
156
157 "'Spanish' quotes"
158
159 :es-x-altquot: .. class:: language-es-x-altquot
160
161 "'Spanish' alternative quotes"
162
163 :et: .. class:: language-et
164
165 "'Estonian' quotes" (no secondary quote listed in Wikipedia)
166
167 :et-x-altquot: .. class:: language-et-x-altquot
168
169 "'Estonian' alternative quotes"
170
171 :eu: .. class:: language-eu
172
173 "'Basque' quotes"
174
175 :fi: .. class:: language-fi
176
177 "'Finnish' quotes"
178
179 :fi-x-altquot: .. class:: language-fi-x-altquot
180
181 "'Finnish' alternative quotes"
182
183 :fr: .. class:: language-fr
184
185 "'French' quotes"
186
187 :fr-x-altquot: .. class:: language-fr-x-altquot
188
189 "'French' alternative quotes"
190
191 :fr-ch: .. class:: language-fr-ch
192
193 "'Swiss-French' quotes"
194
195 :fr-ch-x-altquot: .. class:: language-fr-ch-x-altquot
196
197 "'Swiss-French' alternative quotes" (narrow no-break space, see
198 http://typoguide.ch/)
199
200 :gl: .. class:: language-gl
201
202 "'Galician' quotes"
203
204 :he: .. class:: language-he
205
206 "'Hebrew' quotes"
207
208 :he-x-altquot: .. class:: language-he-x-altquot
209
210 "'Hebrew' alternative quotes"
211
212 :hr: .. class:: language-hr
213
214 "'Croatian' quotes"
215
216 :hr-x-altquot: .. class:: language-hr-x-altquot
217
218 "'Croatian' alternative quotes"
219
220 :hsb: .. class:: language-hsb
221
222 "'Upper Sorbian' quotes"
223
224 :hsb-x-altquot: .. class:: language-hsb-x-altquot
225
226 "'Upper Sorbian' alternative quotes"
227
228 :hu: .. class:: language-hu
229
230 "'Hungarian' quotes"
231
232 :is: .. class:: language-is
233
234 "'Icelandic' quotes"
235
236 :it: .. class:: language-it
237
238 "'Italian' quotes"
239
240 :it-ch: .. class:: language-it-ch
241
242 "'Swiss-Italian' quotes"
243
244 :it-x-altquot: .. class:: language-it-x-altquot
245
246 "'Italian' alternative quotes"
247
248 :ja: .. class:: language-ja
249
250 "'Japanese' quotes"
251
252 :lt: .. class:: language-lt
253
254 "'Lithuanian' quotes"
255
256 :lv: .. class:: language-lv
257
258 "'Latvian' quotes"
259
260 :nl: .. class:: language-nl
261
262 "'Dutch' quotes"
263
264 :nl-x-altquot: .. class:: language-nl-x-altquot
265
266 "'Dutch' alternative quotes"
267
268 .. # 'nl-x-altquot2': '””’’',
269
270 :pl: .. class:: language-pl
271
272 "'Polish' quotes"
273
274 :pl-x-altquot: .. class:: language-pl-x-altquot
275
276 "'Polish' alternative quotes"
277
278 :pt: .. class:: language-pt
279
280 "'Portuguese' quotes"
281
282 :pt-br: .. class:: language-pt-br
283
284 "'Portuguese (Brazil)' quotes"
285
286 :ro: .. class:: language-ro
287
288 "'Romanian' quotes"
289
290 :ru: .. class:: language-ru
291
292 "'Russian' quotes"
293
294 :sh: .. class:: language-sh
295
296 "'Serbo-Croatian' quotes"
297
298 :sh-x-altquot: .. class:: language-sh-x-altquot
299
300 "'Serbo-Croatian' alternative quotes"
301
302 :sk: .. class:: language-sk
303
304 "'Slovak' quotes"
305
306 :sk-x-altquot: .. class:: language-sk-x-altquot
307
308 "'Slovak' alternative quotes"
309
310 :sl: .. class:: language-sl
311
312 "'Slovenian' quotes"
313
314 :sl-x-altquot: .. class:: language-sl-x-altquot
315
316 "'Slovenian' alternative quotes"
317
318 :sr: .. class:: language-sr
319
320 "'Serbian' quotes"
321
322 :sr-x-altquot: .. class:: language-sr-x-altquot
323
324 "'Serbian' alternative quotes"
325
326 :sv: .. class:: language-sv
327
328 "'Swedish' quotes"
329
330 :sv-x-altquot: .. class:: language-sv-x-altquot
331
332 "'Swedish' alternative quotes"
333
334 :tr: .. class:: language-tr
335
336 "'Turkish' quotes"
337
338 :tr-x-altquot: .. class:: language-tr-x-altquot
339
340 "'Turkish' alternative quotes"
341
342 .. 'tr-x-altquot2': '“„‘‚', # antiquated?
343
344 :uk: .. class:: language-uk
345
346 "'Ukrainian' quotes"
347
348 :uk-x-altquot: .. class:: language-uk-x-altquot
349
350 "'Ukrainian' alternative quotes"
351
352 :zh-cn: .. class:: language-zh-cn
353
354 "'Chinese (China)' quotes"
355
356 :zh-tw: .. class:: language-zh-tw
357
358 "'Chinese (Taiwan)' quotes"
359
360 Quotes in text blocks in a non-configured language are kept as plain quotes:
361
362 :undefined: .. class:: language-undefined-example
363
364 "'Undefined' quotes"
365
366 .. [#x-altquot] Tags with the non-standard extension ``-x-altquot`` define
367 the quote set used with the `"smart_quotes" setting`_ value ``"alt"``.
368
369 .. [#smartquotes-locales] The definitions for language-dependend
370 typographical quotes can be extended or overwritten using the
371 `"smartquotes_locales" setting`_.
372
373 The following example ensures a correct leading apostrophe in ``'s
374 Gravenhage`` (at the cost of incorrect leading single quotes) in Dutch
375 and sets French quotes to double and single guillemets with inner
376 spacing::
377
378 smartquote-locales: nl: „”’’
379 fr: « : »:‹ : ›
380
381 .. _"smartquotes_locales" setting: config.html#smartquotes-locales
382
383
384 Caveats
385 =======
386
387 Why You Might Not Want to Use "Smart" Quotes in Your Documents
388 --------------------------------------------------------------
389
390 For one thing, you might not care.
391
392 Most normal, mentally stable individuals do not take notice of proper
393 typographic punctuation. Many design and typography nerds, however, break
394 out in a nasty rash when they encounter, say, a restaurant sign that uses
395 a straight apostrophe to spell "Joe's".
396
397 If you're the sort of person who just doesn't care, you might well want to
398 continue not caring. Using straight quotes -- and sticking to the 7-bit
399 ASCII character set in general -- is certainly a simpler way to live.
400
401 Even if you *do* care about accurate typography, you still might want to
402 think twice before "auto-educating" the quote characters in your documents.
403 As there is always a chance that the algorithm gets it wrong, you may
404 instead prefer to use the compose key or some other means to insert the
405 correct Unicode characters into the source.
406
407
408 Algorithmic Shortcomings
409 ------------------------
410
411 The ASCII character (u0027 APOSTROPHE) is used for apostrophe and single
412 quotes. If used inside a word, it is converted into an apostrophe:
413
414 .. class:: language-fr
415
416 Il dit : "C'est 'super' !"
417
418 At the beginning or end of a word, it cannot be distinguished from a single
419 quote by the algorithm.
420
421 The `right single quotation mark`_ character -- used to close a secondary
422 (inner) quote in English -- is also "the preferred character to use for
423 apostrophe" (Unicode_). Therefore, "educating" works as expected for
424 apostrophes at the end of a word, e.g.,
425
426 Mr. Hastings' pen; three days' leave; my two cents' worth.
427
428 However, when apostrophes are used at the start of leading contractions,
429 "educating" will turn the apostrophe into an *opening* secondary quote. In
430 English, this is *not* the apostrophe character, e.g., ``'Twas brillig``
431 is "miseducated" to
432
433 'Twas brillig.
434
435 In other locales (French, Italian, German, ...), secondary closing quotes
436 differ from the apostrophe. A text like::
437
438 .. class:: language-de-CH
439
440 "Er sagt: 'Ich fass' es nicht.'"
441
442 becomes
443
444 «Er sagt: ‹Ich fass› es nicht.›»
445
446 with a single closing guillemet in place of the apostrophe.
447
448 In such cases, it's best to use the recommended apostrophe character (’) in
449 the source:
450
451 | ’Twas brillig, and the slithy toves
452 | Did gyre and gimble in the wabe;
453 | All mimsy were the borogoves,
454 | And the mome raths outgrabe.
455
456 .. _right single quotation mark:
457 http://www.fileformat.info/info/unicode/char/2019/index.htm
458 .. _Unicode: https://www.unicode.org/charts/PDF/U2000.pdf
459
460 History
461 =======
462
463 The smartquotes module is an adaption of "SmartyPants_" to Docutils.
464
465 `John Gruber`_ did all of the hard work of writing this software in Perl for
466 `Movable Type`_ and almost all of this useful documentation. `Chad Miller`_
467 ported it to Python to use with Pyblosxom_.
468
469 Portions of the SmartyPants original work are based on Brad Choate's nifty
470 MTRegex plug-in. `Brad Choate`_ also contributed a few bits of source code to
471 this plug-in. Brad Choate is a fine hacker indeed.
472 `Jeremy Hedley`_ and `Charles Wiltgen`_ deserve mention for exemplary beta
473 testing of the original SmartyPants.
474
475 Internationalization and adaption to Docutils by Günter Milde.
476
477 .. _SmartyPants: http://daringfireball.net/projects/smartypants/
478 .. _Pyblosxom: http://pyblosxom.bluesock.org/
479 .. _Movable Type: http://www.movabletype.org/
480 .. _John Gruber: http://daringfireball.net/
481 .. _Chad Miller: http://web.chad.org/
482 .. _Brad Choate: http://bradchoate.com/
483 .. _Jeremy Hedley: http://antipixel.com/
484 .. _Charles Wiltgen: http://playbacktime.com/
485 .. _Rael Dornfest: http://raelity.org/