summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/texlive/texlive-cz/csquote.sty
blob: 3644143647b7da0c4d87f13aba1b5911569797db (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
%%%%%%%%%%%%%%%%%%%%%%   cut here   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  File:        CSQUOTE.TEX/STY
%  Version:     1.1
%
%  Authors:     Hunter Goatley <goathunter@wkuvx1.bitnet>
%                    (parts from QUOTE.TEX/STY)
%               Petr Sojka <sojka@ics.muni.cs>
%
%  Warranty:
%
%  Copyright (c) 1992 by Hunter Goatley, Petr Sojka
%  Permission to copy all or part of this work is granted, provided
%  that the copies are not made or distributed for resale, and that
%  the copyright notice and this notice are retained.
%
%  THIS WORK IS PROVIDED ON AN "AS IS" BASIS.  THE AUTHOR PROVIDES NO
%  WARRANTY WHATSOEVER, EITHER EXPRESS OR IMPLIED, REGARDING THE WORK,
%  INCLUDING WARRANTIES WITH RESPECT TO ITS MERCHANTABILITY OR FITNESS
%  FOR ANY PARTICULAR PURPOSE.
%
%  If you make any improvements, I'd like to hear about them.
%
%  History:
%
%  Oct 26, 92 - V1.0 first release
%  Dec 14, 92 - V1.1 \uv added
%
%  Abstract:
%
%       This file defines the macros \csdoublequoteson and \csdoublequotesoff.
%       These macros allows switching between standard and following behaviour:
%       TeX replace the double-quote character (") with Czech
%       left and right double-quotes.  For example:
%
%               "This is a test."     --->    ,,This is a test.''
%
%       The double-quote character is still available via \dq.
%       \" is still treated as the umlaut accent.
%
%       This macro makes a couple of assumptions about the double-quotes:
%
%       1.  Double-quotes are assumed to come in pairs.  When replacing
%           double-quotes, the macro alternates between ,, and ''.  The only
%           exception to this is noted in (2) below.
%       2.  A double-quote at the beginning of a paragraph is always treated
%           as ,,.  This correctly handles the case where a quotation is
%           continued into a second paragraph:
%
%               "This is the first paragraph.\par
%               "This is the second paragraph of the same quote."
%
%       Normal TeX spacing after ,, and '' is maintained by saving and
%       restoring the \spacefactor.
%
%       Macros work both with plainTex and LaTeX.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  HOW IT WORKS:
%
%       The double-quote character (") is made active by \csdoublequoteson.
%       The " macro keeps track of left-quote/right-quote pairs and inserts
%       the appropriate ,, and '' in its place.
%
%       Each character has a \spacefactor associated with it, which specifies
%       the amount of stretch or shrink that a space following the character
%       can have.  Most characters have a factor of 1000, but some punctuation
%       marks have higher spacefactors, most notably the period, which has a
%       \spacefactor of 3000.  This means the space following a period can
%       stretch up to 3 times more than the space after a regular character,
%       accounting for the increased space at the end of sentences.
%
%       The ,, and '' ligatures are assigned \spacefactor's of 0, so that the
%       \spacefactor that is applied to the next character is the same as that
%       of the character preceding the quotes.  Because " has been redefined as
%       a macro, any spaces following " are swallowed by TeX.  It was necessary
%       to have this macro re-insert any needed space so that the following
%       cases worked correctly:
%
%               "This is a test," she said. --> ,,This is a test,'' she said.
%               "This is in a list"; etc.   --> ,,This is in a list''; etc.
%
%       Without the added space, the first example becomes:
%
%               ,,This is a test,''she said.
%
%       The solution was to save the current \spacefactor before inserting a
%       right double-quote, then resetting the \spacefactor after the
%       insertion.  The net effect was that the " macro has a \spacefactor
%       of 0, which matches the way TeX treats ,, and ''.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
{%                                      % Begin a group for which " is active
\catcode`\"=\active                     % Make " an active character
\catcode`\@=11                          % Make @ an active character
%
%  \csdoublequoteson
%
%       This macro makes " an active character, resets the control sequence
%       \dblqu@te to L (left), and defines \dq as a replacement for ".
%
\gdef\csdoublequoteson{%                % \csdoublequoteson enables "
    \gdef"{\czechquotes}%               % Define " as \czechquotes
    \global\catcode`\"=\active%         % Make " an active character
    \global\chardef\dq=`\"%             % Double-quote char. via \dq
    \global\let\dblqu@te=L%             % Always start with a left double-quote
    }                                   % End of macro
%
%  \bq, \eq
%
%      These macros define default characters for czech left and right
%      double quotes. Czech opening quote is created from two commas with
%      kerning depending on fontdimen four parameter of current font.
%      Better solution should be specially designed character with
%      proper kernings; if you have such characters in fonts
%      (e.g. in DC-fonts), use it instead. (e.g. define
%      macros \bq and \eq e.g. \def\bq{\char"130 }
%      in your document/style file-- not in csquote.sty!)
%      Similar solution is used for czech right quote.
%
%      \cs existence test, stolen from TeXbook exercise 7.7
\def\ifundefined#1{\expandafter\ifx\csname#1\endcsname\relax }%
%
%      another macro to be more efficient in time and space
\global\chardef\f@@r=4
%
\ifundefined{bq}%
\gdef\bq{\kern-.25\fontdimen\f@@r\font,\kern-.8\fontdimen\f@@r\font,%
                \kern-.35\fontdimen\f@@r\font}%
\fi
\ifundefined{eq}%
\gdef\eq{\kern-.35\fontdimen\f@@r\font`\kern-.8\fontdimen\f@@r\font`%
                \kern-.25\fontdimen\f@@r\font}
\fi
%
% Macro \uv for other usage of \bq and \eq.
%
\ifundefined{uv}%
        \gdef\uv#1{\bq #1\eq}
\fi
%
%  Define the macro that will be executed whenever " is encountered.
%
\gdef\czechquotes{%
        %  If the double-quote is the first character in a new paragraph,
        %  make sure it becomes a left double-quote.  This case can be
        %  detected by checking to see if TeX is currently in vertical mode.
        %  If so, the double-quote is at the beginning of the paragraph
        %  (since " hasn't actually generated any horizontal mode tokens
        %  yet, TeX is still in vertical mode).  If the mode is vertical,
        %  set \dblqu@te equal to L.
        %
        \ifinner\else\ifvmode\let\dblqu@te=L\fi\fi%
        %
        %  Now insert the appropriate left or right double-quote.
        %
        %  If \dblqu@te is L, insert an opening quote and set \dblqu@te to R.
        %
        \if L\dblqu@te\bq\global\let\dblqu@te=R%
        %
        %  Otherwise, save the current \spacefactor, insert '', set \dblqu@te
        %  to L, and reset the original \spacefactor.
        %
        \else%
           \let\xxx=\spacefactor%               % Save the \spacefactor
           \eq%                                 % Insert ending quote
           \global\let\dblqu@te=L%              % and reset \dblqu@te
           \spacefactor\xxx%                    % Reset the \spacefactor
        \fi%                                    % End of \if L\dblqu@te...
        }                                       % End of " macro
}                                               % End of group

\gdef\csdoublequotesoff{%
        \catcode`\"=12%                         % Set " back to other
        }
%
% Czech quotes are default
%
\csdoublequoteson