/
csquotes.sty.ltxml
280 lines (248 loc) · 10.1 KB
/
csquotes.sty.ltxml
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
# -*- mode: Perl -*-
# /=====================================================================\ #
# | csquotes.sty | #
# | Implementation for LaTeXML | #
# |=====================================================================| #
# | Part of LaTeXML: | #
# | Public domain software, produced as part of work done by the | #
# | United States Government & not subject to copyright in the US. | #
# |---------------------------------------------------------------------| #
# | Thanks to Tom Wiesing <tom.wiesing@gmail.com> | #
# | of the arXMLiv group for initial implementation | #
# | http://arxmliv.kwarc.info/ | #
# | Released under the Gnu Public License | #
# | Released to the Public Domain | #
# |---------------------------------------------------------------------| #
# | Bruce Miller <bruce.miller@nist.gov> #_# | #
# | http://dlmf.nist.gov/LaTeXML/ (o o) | #
# \=========================================================ooo==U==ooo=/ #
package LaTeXML::Package::Pool;
use strict;
use warnings;
use LaTeXML::Package;
# Load the style filke
InputDefinitions('csquotes', type => 'sty', noltxml => 1);
###########################################################################
# Compatibility fixes
RawTeX(<<'EoTeX');
% the unicode check does not work properly in LaTeXML
% furthermore, package version <= 2018/04/06 v1.3b contain
% a known bug, but might still be around.
% therfore we skip the check here.
\def\csq@ifutfchar#1{%
\ifundef\@inpenc@undefined
{\@secondoftwo}
{\csq@ifutfenc}%
{\csq@ifsingle{#1}
{\ifnum`#1<128\relax
\expandafter\@secondoftwo
\else% <-- skip this else here
\expandafter\@secondoftwo
\fi}
{\@firstoftwo}}
{\csq@ifsingle{#1}
{\@secondoftwo}
{\csq@err@char
\@gobbletwo}}}
% work around \cl@@ckpt not being defied by LaTeXML
\let\blockquote@prehook\relax
\newcommand*{\blockquote@prehook}{%
\def\@elt##1{\global\value{##1}\the\value{##1}\relax}%
\edef\csq@tempa{\@elt{page}}% <-- work around it here
\let\@elt\relax
\@fileswfalse}
EoTeX
###########################################################################
# Typesettable quotes
###########################################################################
RawTeX(<<'EoTeX');
% outer quotation mark
\def\csq@qopen{%
\ifnum\csq@qlevel>\csq@maxlvl
\csq@mismatch{%
Level \number\csq@qlevel\space quote invalid at this point.
The maximum level is \number\csq@maxlvl}%
\else
\csq@resetstyle
\csq@init
\csq@addkern@open
\ifodd\csq@qlevel
\let\csq@kernchar@i\csq@thequote@oopen
\ltxml@oqmark@open\csq@thequote@oopen
\else
\let\csq@kernchar@i\csq@thequote@iopen
\ltxml@iqmark@open\csq@thequote@iopen
\fi
\csq@setmarker@open
\expandafter\csq@fixkern
\fi}
% inner quotation mark
\protected\def\csq@iqmark{%
\csq@bqgroup
\ifnum\csq@qlevel>\@ne
\csq@mismatch{%
Level 2 quote invalid at this point.
The current level is \number\csq@qlevel}%
\advance\csq@qlevel\@ne
\let\csq@iqmark\csq@eqerror
\else
\csq@qlevel\tw@
\let\csq@iqmark{\csq@qclose\ltxml@iqmark@close}
\ltxml@iqmark@open\expandafter\csq@qopen
\fi}
% closing mark
\def\csq@qclose@ii#1{%
\ifdim\lastkern=\csq@omitmarker
#1\csq@eqgroup
\else
\csq@addkern@close
\ifodd\csq@qlevel
\csq@thequote@oclose
\ltxml@oqmark@close
\let\csq@kernchar@i\csq@thequote@oclose
\else
\csq@thequote@iclose
\ltxml@iqmark@close
\let\csq@kernchar@i\csq@thequote@iclose
\fi
\ifnum\csq@qlevel>\@ne
\csq@setmarker@close
\fi
\ifblank{#1}{}{\expandafter#1}%
\expandafter\csq@eqgroup
\expandafter\def
\expandafter\csq@kernchar@i
\expandafter{\csq@kernchar@i}%
\expandafter\csq@fixkern
\fi}
EoTeX
DefConstructor('\ltxml@oqmark@open', '<ltx:text class="ltx_quote ltx_outerquote" _noautoclose="1">');
DefConstructor('\ltxml@oqmark@close', '</ltx:text>');
DefConstructor('\ltxml@iqmark@open', '<ltx:text class="ltx_quote ltx_innerquote" _noautoclose="1">');
DefConstructor('\ltxml@iqmark@close', '</ltx:text>');
###########################################################################
# Normal Citation (\mkcitation)
###########################################################################
RawTeX(<<'EoTeX');
\long\def\csq@getcargs@ii#1#2[#3]{%
#1{\ltxml@mkcitation}{#2}{#3}}
\let\MakeBlockQuote\relax
\newrobustcmd*{\MakeBlockQuote}[3]{%
\csq@addbspecial{#1}{#2}{#3}{\csq@bquote{}{}{\ltxml@mkcitation}}}
\let\MakeForeignBlockQuote\relax
\newrobustcmd*{\MakeForeignBlockQuote}[4]{%
\csq@addbspecial{#2}{#3}{#4}%
{\csq@bquote{\csq@lang{#1}}{\csq@endlang}{\ltxml@mkcitation}}}
\let\MakeHyphenBlockQuote\relax
\newrobustcmd*{\MakeHyphenBlockQuote}[4]{%
\csq@addbspecial{#2}{#3}{#4}%
{\csq@bquote{\csq@hyph{#1}}{\csq@endhyph}{\ltxml@mkcitation}}}
\let\MakeHybridBlockQuote\relax
\newrobustcmd*{\MakeHybridBlockQuote}[4]{%
\csq@addbspecial{#2}{#3}{#4}%
{\csq@bquote
{\iftoggle{csq@block}{\csq@lang}{\csq@hyph}{#1}}
{\iftoggle{csq@block}{\csq@endlang}{\csq@endhyph}}
{\ltxml@mkcitation}}}
EoTeX
DefMacro('\ltxml@mkcitation{}', '\ltxml@citation@open\mkcitation{#1}\ltxml@citation@close');
DefConstructor('\ltxml@citation@open', '<ltx:text class="ltx_citation" _noautoclose="1">');
DefConstructor('\ltxml@citation@close', '</ltx:text>');
###########################################################################
# Integrated Citation (\mkccitation)
###########################################################################
RawTeX(<<'EoTeX');
\long\def\csq@getccargs@iii#1#2#3[#4]{%
#1{\ltxml@mkccitation}{\csq@cite#2{#3}}{#4}}
EoTeX
DefMacro('\ltxml@mkccitation{}', '\ltxml@ccitation@open\mkccitation{#1}\ltxml@ccitation@close');
DefConstructor('\ltxml@ccitation@open', '<ltx:text class="ltx_ccitation" _noautoclose="1">');
DefConstructor('\ltxml@ccitation@close', '</ltx:text>');
###########################################################################
# Text Quotes (\mktextquote)
###########################################################################
RawTeX(<<'EoTeX');
\long\def\csq@tquote@i#1#2#3#4#5#6#7#8#9{%
\begingroup
\csq@setsfcodes
\edef\csq@tempa{%
\unexpanded{%
\ltxml@mktextquote
{#3}%
{#7}%
{\csq@qclose@i{#2}}%
{#6}{#8}}%
{\ifblank{#5}
{}
{\unexpanded{\csq@switchlang{#4{#5}}}}}}%
\csq@bqgroup#1\csq@tempa#9%
\endgroup}
EoTeX
DefMacro('\ltxml@mktextquote{}{}{}{}{}{}', '\ltxml@mktextquote@open\mktextquote{#1}{#2}{#3}{#4}{#5}{#6}\ltxml@mktextquote@close');
DefConstructor('\ltxml@mktextquote@open', '<ltx:text class="ltx_textquote" _noautoclose="1">');
DefConstructor('\ltxml@mktextquote@close', '</ltx:text>');
###########################################################################
# Block Quotes (\mkblockquote)
###########################################################################
RawTeX(<<'EoTeX');
\long\def\csq@bquote@iii#1#2#3#4#5#6#7#8{%
\ltxml@mkblockquote@open\begin{\csq@blockenvironment}%
\toggletrue{csq@block}%
\csq@setsfcodes
\edef\csq@tempa{%
\unexpanded{%
\mkblockquote
{\ltxml@mkblockquote@aopen#6\ltxml@mkblockquote@aclose}%
{#5}{#7}}%
{\ifblank{#4}
{}
{\unexpanded{\csq@switchlang{#3{#4}}}}}}%
#1\csq@tempa#8#2%
\end{\csq@blockenvironment}\ltxml@mkblockquote@close}
% Because detection of word length does not work properly in LaTeXML
% always use a proper block-quote environment
\let\csq@bquote@ii\csq@bquote@iii
EoTeX
# update the 'quote' environment to be <ltx:quote class="ltx_blockquote">
DefMacro('\ltxml@mkblockquote@open', '\begingroup\ltxml@mkblockquote@open@i');
DefPrimitive('\ltxml@mkblockquote@open@i', sub {
DefEnvironment('{quote}', '<ltx:quote class="ltx_blockquote">#body</ltx:quote>',
beforeDigest => sub { Let('\\\\', '\@block@cr'); Let('\par', '\@block@cr') },
mode => 'text'); });
DefMacro('\ltxml@mkblockquote@close', '\endgroup');
DefConstructor('\ltxml@mkblockquote@aopen', '<ltx:text class="ltx_quote" _noautoclose="1">');
DefConstructor('\ltxml@mkblockquote@aclose', '</ltx:text>');
###########################################################################
# Display Quote (\mkbegdispquote, \mkenddispquote)
###########################################################################
RawTeX(<<'EoTeX');
\def\csq@bdquote#1#2#3#4#5{%
\ltxml@blockenvironment@open\csuse{\csq@blockenvironment}%
\toggletrue{csq@block}%
\csq@setsfcodes
#1\ifblank{#4}
{\def\csq@tempb{\ltxml@mkenddispquote{#5}{}#2}%
\ltxml@mkbegdispquote{#5}{}}
{\def\csq@tempb{\ltxml@mkenddispquote{#5}{\csq@switchlang{#3{#4}}}#2}%
\ltxml@mkbegdispquote{#5}{\csq@switchlang{#3{#4}}}}%
\ignorespaces}
\def\csq@edquote{%
\unspace\csq@tempb
\csuse{end\csq@blockenvironment}\ltxml@blockenvironment@close}
EoTeX
# update the 'quote' environment to be <ltx:quote class="ltx_displayquote">
DefMacro('\ltxml@blockenvironment@open', '\begingroup\ltxml@blockenvironment@open@i');
DefPrimitive('\ltxml@blockenvironment@open@i', sub {
DefEnvironment('{quote}', '<ltx:quote class="ltx_displayquote">#body</ltx:quote>',
beforeDigest => sub { Let('\\\\', '\@block@cr'); Let('\par', '\@block@cr') },
mode => 'text'); });
DefMacro('\ltxml@blockenvironment@close', '\endgroup');
DefMacro('\ltxml@mkbegdispquote{}{}', '\ltxml@mkbegdispquote@aopen\mkbegdispquote{#1}{#2}');
DefConstructor('\ltxml@mkbegdispquote@aopen', '<ltx:text class="ltx_quote" _noautoclose="1">');
DefMacro('\ltxml@mkenddispquote{}{}', '\mkenddispquote{#1}{#2}\ltxml@mkenddispquote@aclose');
DefConstructor('\ltxml@mkenddispquote@aclose', '</ltx:text>');
###########################################################################
# TODO
###########################################################################
# \MakeForeignQuote does not seem to work
1;