summaryrefslogtreecommitdiff
path: root/macros/generic/misc/balancedquotes.sty
blob: f280fbeba8cc66545ab3d26b1a3ed20a26c54ba8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% file name: balancedquotes.sty (for plain TeX and LaTeX)
%% Ole Michael Selberg, 25.8.1994
%% E-mail: O.M.Selberg@easteur-orient.uio.no
%%-------------------------------------------------------------------
%% Description:
%%   This file contains macros that simplify the management of quotes.
%%   The input:                    
%%                             "...*....*..." 
%%   will be typeset as:
%%                            <<...<...>...>>     (default)
%%
%%   (or as:                       
%%                           ,,...,...'...''         
%%   etc., depending on your choices.).
%%
%%   TeX keeps track of whether full quotes (written as ") and half
%%   quotes (written as *) are balanced, When a quote has been omitted,
%%   as in:
%%         --- text "text in quotes more text "text in quotes" ---
%%   an error message is written to the screen, and a mark is put in 
%%   the margin to the left of the line in which a final full or half  
%%   quote followed by a letter was discovered.
%%   
%%   The macros can be used both with plain TeX and LaTeX. You can test
%%   them and learn how to use the commands by running the test file 
%%   which is included in this file, after \endinput. 
%%   Just copy all the stuff after \endinput to a new file,
%%   which you should name balancedquotestest.tex, and then delete it 
%%   from this file.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\catcode`\@=11 \catcode`\_=11 \newif\ifapostrophe \newlinechar=`^^J
%
\def\definequotes #1#2#3#4{%
     \def\bquote_char{#1}\def\equote_char{#2}%
     \def\bhquote_char{#3}\def\ehquote_char{#4}}
%     
\def\setquotes{\futurelet\test_token\CheckForOptArg}
\def\CheckForOptArg{\ifx\test_token[
    \let\next\OptArgPresent
       \else \let\next\OptArgAbsent \fi \next}
\def\OptArgPresent[#1]#2{\csname #2#1q\endcsname}
\def\OptArgAbsent #1{\csname #1q\endcsname}
  %---------------------------------------
  % Norwegian:
  %
\def\Nq{% Output: <<...<...>...>>
     \def\bquote_char {\char"13 }\def\equote_char {\char"14 }%
     \def\bhquote_char {\char"0E}\def\ehquote_char {\char"0F}%
     }
\def\NCq{% Output: ,,...,...'...''
     \def\bquote_char {\char"12 \apostrophe_check}%
                             \def\equote_char {\char"11 }%
     \def\bhquote_char {\char"0D}\def\ehquote_char {\char"27}%
     \apostrophetrue}
\let\NGq=\Nq \let\norwegianquotes=\Nq \let\norwegianguillemetsq=\Nq
\let\norwegiancommasq=\NCq
  %-----------------------------------------    
  % German:
  %
\def\DGq{% Output: >>...>...<...<<
     \def\bquote_char {\char"14 }\def\equote_char {\char"13 }%
     \def\bhquote_char {\char"0F}\def\ehquote_char {\char"0E}%
     }
\def\DCq{% Output: ,,...,...`...``
     \def\bquote_char{\char"12  \apostrophe_check}%
                             \def\equote_char {\char"10 }%
     \def\bhquote_char {\char"0D}\def\ehquote_char {\char"60}%
     \apostrophetrue}
\let\Dq=\DCq \let\germanquotes=\DCq \let\germanguillemetsq=\DGq
\let\germancommasq=\DCq 
  %------------------------------------------
  % French:
  %
\def\Fq{% Output: <<...<<...>>...>>
     \def\bquote_char {\char"13\ }%
                       \def\equote_char {\thinspace\char"14 }%
     \def\bhquote_char {\char"13\thinspace }%
                       \def\ehquote_char { \char"14 }%
     }
\def\FCq{\message{French doesn't use comma quotes!
        I shall choose guillemets instead.}}
\let\frenchquotes=\Fq \let\FGq=\Fq \let\frenchguillemetsq=\Fq
\let\frenchcommasq=\FCq
  %------------------------------------------
  % English:
  %
\def\GBq{% Output: `...``...''...'
     \def\bquote_char {\char"60 }\def\equote_char {\char"27 }%
     \def\bhquote_char {\char"10 }\def\ehquote_char {\char"11 }%
     }
\def\USq{% Output: ``...`...'...''
     \def\bquote_char {\char"10 }\def\equote_char {\char"11 }%
     \def\bhquote_char {\char"60 }\def\ehquote_char {\char"27 }%
     }
\def\EQM{\message{English doesn't use guillmets!
        I shall choose normal English quotes instead.}}     
\let\USquotes=\USq  \let\GBquotes=\GBq \let\USCq=\USq \let\GBCq=\GBq
\def\GBguillemetsq{\EQM\GBq} \def\USguillemetsq{\EQM\USq}
\let\englishquotes=\USq \let\englishcommasq=\USq \let\Eq=\USq \let\ECq=\USq
\let\englishguillemetsq=\USguillemetsq
%------------------------------------------- 
\def\bquote{\global\advance\quotecount by1 \bquote_char}%
\def\equote{\penalty 10000 {\equote_char }\global\advance\quotecount by1 }% 
\def\bhquote{\bhquote_char \global\advance\hquotecount by1 }%
\def\ehquote{\penalty 10000 \ehquote_char \global\advance\hquotecount by1 }%

\newcount\quoteflag \newcount\quotecount 
\newcount\hquoteflag  \newcount\hquotecount
\def\hex{"} \let\star=* 
\catcode`\"=\active \catcode`\*=\active
\def"{\begingroup\ifnum\quoteflag=0
         \aftergroup\bquote\global\quoteflag=1
       \else \equote\global\quoteflag=0 
	   \aftergroup\equote_check \fi \endgroup}
\def*{\begingroup\ifmmode \else\ifnum\hquoteflag=0 \bhquote\global\hquoteflag=1
       \else \ehquote\global\hquoteflag=0 
	   \aftergroup\ehquote_check \fi \fi \endgroup}
\def\equote_check{\futurelet\next\equote_test}
\def\ehquote_check{\futurelet\next\ehquote_test}
\def\equote_test{\ifcat\noexpand\next a%
	     \immediate\write16{^^J--->> Final full quote followed by a
          letter!!}\equote_warning\fi}
\def\ehquote_test{\ifcat\noexpand\next a%
	     \immediate\write16{^^J--->  Final half quote followed by a
          letter!!}\ehquote_warning\fi}
\def\quotesnumbertest{\ifodd\quotecount\immediate\write16{!! Odd number
                 of full quotes.}\fi
     \ifodd\hquotecount\immediate\write16{!! Odd number
	             of half quotes.}\fi}
\def\apostrophe_check{\futurelet\next\apostrophe_test}
\def\apostrophe_test{\if\next j\thinspace\fi}

\def\l_note{\strut\vadjust{\kern-\dp\strutbox
                   \vtop to 0pt{%
				       \vss\llap{{\box0}\ 
					       \quad}}
	 \dimen0=-\prevdepth\advance\dimen0by\dp\strutbox
     \penalty0\kern\dimen0
}}
\def\equote_warning{{\setbox0=\hbox{\equote_char\thinspace !\quad}\l_note}}
\def\ehquote_warning{{\setbox0=\hbox{\ehquote_char\thinspace !\quad}\l_note}}
%
%\catcode`\@=12 \catcode`\_=8
\Nq
\endinput

% Copy this to a new file:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% file name: balancedquotestest.tex
%% Ole Michael Selberg, 25.8.1994
%% E-mail: O.M.Selberg@easteur-orient.uio.no
%%-------------------------------------------------------------------
%% Description:
%%   This file inputs the file balancedquotes.sty and tests 
%%   the quote macros defined there.
%%   It works with both plain TeX and LaTeX.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newif\ifLaTeX
  % Is this LaTeX?
\ifx\protect\undefined \else \LaTeXtrue \fi
 % We presuppose Cork-encoding:
\def\"{\accent4}\def\\{$\backslash$}\def\<{$\lbrace$}
\def\>{$\rbrace$}
\overfullrule=0pt


\ifLaTeX
   \documentstyle [balancedquotes] {article}
   \begin{document}
\else \input balancedquotes.sty
\fi

\message{^^JType the name of a font with Cork encoding,
    ^^Je.g. dcr10:}
\read16 to \dvifontname
\font\dvifont=\dvifontname at 10pt
\message{^^J}
\dvifont

\hsize=10cm
\hoffset=2cm
\parindent=0pt

\hyphenation{Af-ten-pos-ten}        
\centerline{Test of {\tt balancedquotes.sty}\hfill
     Date:\enspace \the\month/\the\day/\the\year} 

\vglue 1cm
%\Nq
\definequotes{\char19}{\char20}{\char14}{\char15}
    
\moveleft 10pt\vbox{\bf The command {\tt \\Nq} (\dvifont Norwegian: "...*...*..."):}
\smallskip
"Det er sant," sa han, "jeg har nettopp avbestilt *Aftenposten*!"

"Har du det?" svarte hun forbauset. "Hvorfor spurte du ikke meg f{\o}rst?"

\medskip
{\leftskip20pt
Equivalent commands:
\smallskip
\tt
\\norwegianquotes ({\dvifont This is the default for Norwegian.})

\\NGq

\\setquotes \<norwegian\> 
 
\\setquotes \<N\>

\\setquotes [guillemets]\<norwegian\> 

\\setquotes [G]\<N\>

\\norwegianguillemetsq

\\definequotes \<\\char19\>\<\\char20\>\<\\char14\>\<\\char15\>

}

\bigskip

\setquotes [commas]{norwegian}


\moveleft 10pt\vbox{\bf The command {\tt \\NCq} \dvifont (Norwegian: "...*...*..."):} 
\smallskip
"Det er sant," sa han, "jeg har nettopp avbestilt *Aftenposten*!"

"Har du det?" svarte hun forbauset. "Hvorfor spurte du ikke meg f{\o}rst?"
\medskip

{\leftskip20pt
Equivalent commands:
\tt
\smallskip

\\setquotes [commas]\<norwegian\> 
 
\\setquotes [C]\<N\>

\\norwegiancommasq 

\\definequotes \<\\char18\>\<\\char17\>\<\\char13\>\<\\char39\>

}
\bigskip
\Dq

\moveleft 10pt\vbox{\bf The command {\tt \\Dq} \dvifont (German: "...*...*..."):} 
\smallskip
Goethe schrieb: "Wielands *Oberon* wird als ein Meisterst\"uck angesehen."

\medskip
{\leftskip20pt
Equivalent commands:
\smallskip
\tt

\\germanquotes ({\dvifont This is the default for German})

\\DCq

\\setquotes [commas]\<german\> 
 
\\setquotes [C]\<D\>

\\germancommasq

\\definequotes \<\\char18\>\<\\char17\>\<\\char13\>\<\\char39\>

}

\bigskip
\DGq

\moveleft 10pt\vbox{\bf The command {\tt \\DGq} \dvifont (German: "...*...*..."):} 
\smallskip
Goethe schrieb: "Wielands *Oberon* wird als ein Meisterst\"uck angesehen."

\medskip
{\leftskip20pt
Equivalent commands:
\smallskip
\tt

\\setquotes [guillemets]\<german\> 
 
\\setquotes [G]\<D\>

\\germanguillmetsq

\\definequotes \<\\char20\>\<\\char19\>\<\\char15\>\<\\char14\>

}

\ifLaTeX \else\filbreak\fi

\USq

\moveleft 10pt\vbox{\bf The command {\tt \\USq} \dvifont  (US English: "...*...*..."):} 
\smallskip
Goethe wrote: "Wieland's *Oberon* is considered a masterpiece."

\medskip
{\leftskip20pt
Equivalent commands:
\smallskip
\tt

\\setquotes \<US\>

\\setquotes [commas]\<US\> 
 
\\setquotes [C]\<US\>

\\UScommasq

\\definequotes \<\\char16\>\<\\char17\>\<\\char96\>\<\\char39\>

\\setquotes [guillmets]\<US\> {\dvifont etc.\  will generate an error message
and call} \\USq

}

\bigskip
\GBq

\moveleft 10pt\vbox{\bf The command {\tt \\GBq} \dvifont (GB English: "...*...*..."):}
\smallskip
Goethe wrote: "Wieland's *Oberon* is considered a masterpiece."

\medskip
{\leftskip20pt
Equivalent commands:
\smallskip
\tt

\\setquotes \<GB\>

\\setquotes [commas]\<GB\> 
 
\\setquotes [C]\<GB\>

\\GBcommasq

\\definequotes \<\\char96\>\<\\char39\>\<\\char16\>\<\\char17\>

\\setquotes [guillmets]\<GB\> {\dvifont etc.\  will generate an error message
and call} \\GBq

}


\bigskip
\Fq

\moveleft 10pt\vbox{\bf The command {\tt \\Fq} \dvifont  (French: "...*...*..."):} 
\smallskip
On dit couramment {\it nic nie wiem\/} "je ne sais rien".

\medskip
{\leftskip20pt
Equivalent commands:
\smallskip
\tt

\\frenchquotes {\dvifont This is the default.}
\\setquotes \<GB\>

\\setquotes [guillemets]\<F\> 
 
\\setquotes [G]\<F\>

\\frenchguillemetsq

\\definequotes \<\\char19\ \>\<\\ \\char20\>\<\\char19\ \>\<\\ \\char20\>

\\setquotes [commas]\<french\> {\dvifont etc.\  will generate an error message
and call} \\Fq

}

\bigskip

\NCq

\moveleft 10pt\vbox{\bf Test of error detection when quotes are unbalanced:}
\smallskip
"Det er sant," sa han, "jeg har nettopp avbestilt *Aftenposten*!"

"Har du det? svarte hun forbauset. "Hvorfor spurte du ikke meg f{\o}rst?"


\bigskip


\moveleft 10pt\vbox{\bf Test of {\tt \\hex} og {\tt \\star}}
\smallskip
The command {\tt \\hex} is used instead of {\tt
\\char\hex22} whenever {\tt \\char\hex22} does not denote
a quote sign. For instance, we can write: {\tt
\\char\hex41} in order to get an `A'. Here we
test that the macro {\tt \\hex} works as it should: `{\tt
\\char\\hex4F\\char\\hex4B}'
is output as `\char\hex4F\char\hex4B'. 

\smallskip 
Instead of {\char \hex2A} we write {\tt \\star}.

\def\slutt{\end{document}}
{\ifLaTeX
  \aftergroup\slutt
\fi}

\bye