Subversion Repositories pyptex

Rev

Rev 25 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9 janik 1
# -*- coding: utf-8 -*-
2
 
8 janik 3
# Slovak ISO 690 formating template for PyPTeX system
4
# Copyright (C) 2008  Michal Abaffy <michal_abaffy@transcat-plm.com>
14 janik 5
# Copyright (C) 2010  Jan Janech <jan.janech@kst.uniza.sk>
8 janik 6
#
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 
25 janik 20
from lib import Template, param, noparam, authortype, encodetoascii, insteadOf, useAgain
2 janik 21
from lib.iso_690_2 import ISOFormat, isoentry
22
 
5 janik 23
################################################################################
24
# SlovakBase
25
# ==========
26
#
27
# Sablona pre standardny sposob citovania podla upravenej normy STN ISO 690
28
# Pre citacie podla normy STN ISO 690 systemom "prvy udaj, rok" je nutne pouzit
29
# inu sablonu.
30
#   Pomocou konfiguracnych parametrov je mozne vytvarat pripustne normovane
31
# variacie tejto sablony.
32
#
33
# Poznamka: Podla normy ISO 690 sa tvoria bibliograficke odkazy, t.j. zaznamy
34
#           o tych dokumentoch, ktore sa skutocne pouzili pri pisani prace.
35
#           Skutocne pouzite zaznamy s bibliografickymi odkazmi sa umiestnuju
36
#           na konci hlavnej casti prace s nazvom "Zoznam bibliografickych odkazov".
37
#               Pod nazvom "Bibliografia" sa moze k praci pridat usporiadany zoznam
38
#           zaznamov o literature, ktora sa sice tyka predmetu prace, ale ktora
39
#           sa bezprostredne nepouzila na jej napisanie. V tomto pripade sa odporuca
40
#           pouzit usmernenia ISBD(G) -- General international standard
41
#           bibliographic description.
42
class SlovakBase(Template):
15 janik 43
    _Params = {
44
        'autoothers': (bool, True),
24 janik 45
        'sameauthoremdash': (bool, True),
15 janik 46
    }
47
 
2 janik 48
    _Format = ISOFormat
5 janik 49
 
50
    class Config:
51
        __noentry__ = True
52
 
53
        ########################################################################
54
        # AuthorSeparator = {' -- ' | ', '}
55
        #   Ked sa pouzivaju cele krstne mena, ako separator sa ma pouit pomlcka
56
        #   V pripade ze sa pouzivaju inicialky, ako separator sa ma pouit ciarka
57
        AuthorSeparator     = ' -- '
58
 
59
        ########################################################################
60
        # SurnameStyle        = {'{\\scshape ' | '\\uppercase{'}
61
        #   Norma preferuje styl '\\uppercase{'. Styl '{\\scshape ' je tiez
62
        #   mozne pouzit. No potom je potrebne pouzivat \scshape na pisanie
63
        #   priezvisk v celom dokumente
64
        SurnameStyle        = '\\uppercase{'
65
 
66
        ########################################################################
67
        # MaxAuthorsCount     = { 1 | 2 | 3 | 6 }
68
        #   Norma pripusta maximalne 3 autorov pre jeden zaznam, pricom sa mozeme
69
        #   rozhodnut ci budeme uvadzat 1 alebo 2 alebo 3. Avsak v niektorych
70
        #   vedeckych komunitach sa uvadza az 6 autorov. Tento pristup nema vsak
71
        #   nijake opodstatnenie v ziadnej norme. No ak by sme sa dostali nahodou
72
        #   do takejto komunity, radsej tu neham takuto moznost ;)
73
        MaxAuthorsCount     = 3
74
 
75
        ########################################################################
76
        # etal              = { 'a i.' | 'a in\'{y}' | 'et al.' | 'et alli' }
77
        #   co sa ma napisat ked je v zazname uvedeny vacsi pocet autorov ako
78
        #   je hodnota MaxAuthorsCount
79
        etal                = 'a i.'
80
 
81
        ########################################################################
82
        # others              = 'a kol.'
83
        #   co sa ma napisat ked je v zazname uvedene 'and others'
84
        others              = 'a kol.'
85
 
86
        ########################################################################
87
        # ed                  = 'vyd.'
88
        #   preklad slova edition resp. skratky ed.
89
        ed                  = 'vyd.'
90
 
91
        ########################################################################
92
        # sineloco            = {None, 's.l.' | 'b.m.'}
93
        #   preklad slova sine loco (bez miesta), v pripade ze sa nastavi na None
94
        #   nepouzije sa tento sposob uvedenia neuvedeneho mesta tzn. chybajuce
95
        #   mesto sa jednoducho neuvedie
96
        sineloco            = 's.l.'
97
 
98
        ########################################################################
99
        # sinenomine          = {None, 's.n.' | 'b.v.'}
100
        #   preklad slova sine nomine (bez mena vydavatela), v pripade ze sa nastavi na None
101
        #   nepouzije sa tento sposob uvedenia neuvedeneho vydavatela tzn. chybajuci
102
        #   vydavatel sa jednoducho neuvedie
103
        sinenomine          = 's.n.'
104
 
105
        ########################################################################
106
        # sineanum            = {None, 's.a.' | 'b.r.'}
107
        #   preklad slova sine anum (bez roku), v pripade ze sa nastavi na None
108
        #   nepouzije sa tento sposob uvedenia neuvedeneho roku tzn. chybajuci
109
        #   rok sa jednoducho neuvedie
110
        sineanum            = 's.a.'
111
 
112
        ########################################################################
113
        # p                   = { 's.' | 'p.' }
114
        #   skratka pre stranu. pouzije sa pre pocet stran monografie resp.
115
        #   pre uvedenie strany na ktorej sa nachadza citacia vramci publikacie
116
        p                   = 's.'
117
 
118
        ########################################################################
119
        # p                   = { 's.' | 'p.' }
120
        #   skratka pre stranu. pouzije sa pre pocet stran monografie resp.
121
        #   pre uvedenie strany na ktorej sa nachadza citacia vramci publikacie
122
        p                   = 's.'
123
 
124
        ########################################################################
125
        # no                  = { '\\v{c}.~' | 'n$\\degree$' }
10 janik 126
        #   skratka pre cislo. pouzije sa pre zapisanie cisla casopisu a.p. ak je
5 janik 127
        #   v zazname uvedene len cislo, bez udania typu
128
        no                  = '\\v{c}.~'
129
 
130
        ########################################################################
10 janik 131
        # vol                 = { 'zv.~' | 'vol.~' }
132
        #   skratka pre cislo. pouzije sa pre zapisanie cisla zvazku a.p. ak je
133
        #   v zazname uvedene len cislo, bez udania typu
134
        vol                  = 'zv.~'
135
 
136
        ########################################################################
5 janik 137
        # chap               = { 'kap.' | 'chap.' }
138
        # sec                = { 'odd.' | 'sec.' }
139
        #   skratka pre cislo kapitoly. pouzije sa na specifikaciu umiestnenia
140
        #   prispevku v monografii
141
        chap                = 'kap.'
142
        sec                 = 'odd.'
25 janik 143
 
144
        ########################################################################
145
        # techrepname       = { 'Technick\\\'a spr\\\'ava' }
146
        #   oznacenie pre technicku spravu.
147
        techrepname         = 'Technick\\\'a spr\\\'ava'
26 janik 148
 
149
        ########################################################################
150
        # phdname           = { 'Dizerta\\v{c}n\\\'a pr\\\'aca' }
151
        #   oznacenie pre dizertacnu pracu.
152
        phdname             = 'Dizerta\\v{c}n\\\'a pr\\\'aca'
5 janik 153
 
2 janik 154
    class Labeling:
155
        __noentry__ = True
5 janik 156
 
2 janik 157
        def itemLabel(self):
7 janik 158
            if 'author' in self:
159
                author = self['author']
160
                a = author
161
                if (None, 'others') in a:
162
                    a.remove((None, 'others'))
163
                if len(author) == 1:
164
                    lbl = encodetoascii(author[0][1])[:3].upper()
165
                else:
166
                    lbl = encodetoascii(''.join(
167
                        auth[1][0]
168
                            for auth in author[:4]
169
                                if auth[0] is not None
170
                    ))[:3].upper()
2 janik 171
            else:
7 janik 172
                title = self['title']
5 janik 173
                lbl = encodetoascii(''.join(
7 janik 174
                    t[0]
175
                        for t in title.split()
176
                            if t[0].isalpha()
5 janik 177
                ))[:3].upper()
10 janik 178
            lbl += "%s"%(self['year', ''][-2:])
2 janik 179
 
180
            return lbl
5 janik 181
 
182
    class Misc(Labeling, Config):
6 janik 183
        __falldown__ = True
5 janik 184
 
2 janik 185
        @param(authortype)
186
        @isoentry('author')
187
        def author(self, out, value):
188
            thisauthor = ()
189
            akol = False
190
            for id, (name, surname) in enumerate(value):
191
                if (name, surname) == (None, 'others'):
192
                    akol = True
7 janik 193
                elif name is None:
194
                    thisauthor += (surname, )
2 janik 195
                else:
5 janik 196
                    a  = self.SurnameStyle
2 janik 197
                    a += surname
198
                    a += '}, '
199
                    a += name
200
 
201
                    thisauthor += (a, )
202
            if akol:
5 janik 203
                thisauthor += (self.others, )
204
 
2 janik 205
            if not hasattr(out, 'prevauthor'):
206
                out.prevauthor = ()
5 janik 207
 
24 janik 208
            if thisauthor == out.prevauthor and self._Params.sameauthoremdash:
2 janik 209
                out.write('---')
210
            else:
211
                out.prevauthor = thisauthor
5 janik 212
                count = len(thisauthor)
15 janik 213
                if self._Params.autoothers:
214
                    if (akol and count-1 > self.MaxAuthorsCount) or (not akol and count > self.MaxAuthorsCount):
215
                        thisauthor = thisauthor[:self.MaxAuthorsCount] + (self.etal,)
2 janik 216
                last = len(thisauthor)-1
217
                for id, a in enumerate(thisauthor):
5 janik 218
                    if id < last and thisauthor[id+1] in (self.others, self.etal):
219
                        out.beginEntry('author', ' ')
2 janik 220
                    else:
5 janik 221
                        out.beginEntry('author', self.AuthorSeparator)
222
 
223
                    out.write(a)
3 janik 224
            out.setBlockSeparator(':\n')
5 janik 225
 
2 janik 226
        @param(str)
227
        @isoentry('title')
228
        def title(self, out, value):
12 janik 229
            if 'booktitle' not in self and 'journal' not in self:
5 janik 230
                out.write('\\emph{')
2 janik 231
            out.write(value)
5 janik 232
 
233
            if 'subtitle' in self:
234
                out.setSeparator('~:~')
235
            else:
12 janik 236
                if 'booktitle' not in self and 'journal' not in self:
5 janik 237
                    out.write('}')
238
 
239
        @param(str)
2 janik 240
        @isoentry('title')
5 janik 241
        def subtitle(self, out, value):
242
            if 'title' not in self:
243
                if 'booktitle' not in self:
244
                    out.write('\\emph{')
2 janik 245
            out.write(value)
5 janik 246
            if not self.isin:
247
                out.write('}')
248
 
2 janik 249
        @param(str)
5 janik 250
        @isoentry('booktitle')
251
        def booktitle(self, out, value):
252
            out.write('In:~\\emph{')
253
            out.write(value)
254
 
255
            if 'booksubtitle' in self:
2 janik 256
                out.setSeparator('~:~')
257
            else:
5 janik 258
                out.write('}')
259
 
2 janik 260
        @param(str)
5 janik 261
        @isoentry('booktitle')
262
        def booksubtitle(self, out, value):
263
            if 'booktitle' not in self:
264
                out.write('In:~\\emph{')
2 janik 265
            out.write(value)
5 janik 266
            out.write('}')
7 janik 267
 
5 janik 268
        @param(str)
7 janik 269
        @isoentry('media')
270
        def media(self, out, value):
271
            out.write('['+value+']')
272
 
273
        @param(str)
5 janik 274
        @isoentry('editor')
275
        def editor(self, out, value):
276
            out.write(value)
277
 
278
        @param(str)
279
        @isoentry('edition')
2 janik 280
        def edition(self, out, value):
5 janik 281
            if value == '1':
282
                txtvalue = "Prv\\'{e}"
283
            elif value == '2':
2 janik 284
                txtvalue = "Druh\\'{e}"
5 janik 285
            elif value == '3':
2 janik 286
                txtvalue = "Tretie"
5 janik 287
            elif value == '4':
2 janik 288
                txtvalue = "\\v{S}tvr\\'{e}"
5 janik 289
            elif value == '5':
2 janik 290
                txtvalue = "Piate"
5 janik 291
            elif value == '6':
2 janik 292
                txtvalue = "\\v{S}ieste"
5 janik 293
            elif value == '7':
2 janik 294
                txtvalue = "Siedme"
5 janik 295
            elif value == '8':
2 janik 296
                txtvalue = "\\^{O}sme"
297
            else:
5 janik 298
                if value.isdigit():
299
                    txtvalue = "%s."%value
300
                else:
301
                    txtvalue = value
302
 
2 janik 303
            out.write(txtvalue)
5 janik 304
            out.write(' ')
305
            out.write(self.ed)
306
 
2 janik 307
        @param(str)
5 janik 308
        @isoentry('publisher')
309
        def address(self, out, value):
310
            if 'publisher' in self:
311
                out.write(value)
312
                out.setSeparator('~:~')
313
            else:
314
                if self.sinenomine is None:
315
                    out.write(value)
316
                    out.setSeparator('~:~')
317
                    out.beginEntry('published')
318
                    out.write(self.sinenomine)
319
                else:
320
                    out.write(value)
321
 
322
        @param(str)
323
        @isoentry('publisher')
324
        def location(self, out, value):
325
            if 'publisher' in self:
326
                out.write(value)
327
                out.setSeparator('~:~')
328
            else:
329
                if self.sinenomine is None:
330
                    out.write(value)
331
                    out.setSeparator('~:~')
332
                    out.beginEntry('published')
333
                    out.write(self.sinenomine)
334
                else:
335
                    out.write(value)
336
 
337
        @param(str)
338
        @isoentry('publisher')
339
        def publisher(self, out, value):
340
            if 'address' not in self and 'location' not in self and self.sineloco is not None:
341
                out.write('[')
342
                out.write(self.sineloco)
343
                out.write(']')
344
                out.setSeparator('~:~')
345
                out.beginEntry('published')
346
            out.write(value)
347
 
348
        @param(str)
349
        @isoentry('publisher')
2 janik 350
        def month(self, out, value):
351
            out.write(value)
352
            if 'year' in self:
353
                out.setSeparator('~')
5 janik 354
 
355
        @param(str)
356
        @isoentry('publisher')
357
        def year(self, out, value):
358
            if value == 's.a.':
359
                if self.sineanum is not None:
360
                    out.write(self.sineanum)
361
            else:
362
                out.write('\\oldstylenums{')
363
                out.write(value)
364
                out.write('}')
365
 
2 janik 366
        @param(int)
5 janik 367
        @isoentry('size')
368
        def pagescount(self, out, value):
2 janik 369
            out.write(value)
5 janik 370
            out.write('~')
371
            out.write(self.p)
372
 
2 janik 373
        @param(str)
5 janik 374
        @isoentry('edition', separator='; ')
375
        def series(self, out, value):
2 janik 376
            out.write(value)
5 janik 377
 
378
        @param(str)
379
        @isoentry('edition')
380
        def volume(self, out, value):
381
            if value.isdigit():
10 janik 382
                out.write(self.vol)
383
            out.write(value)
384
 
385
        @param(str)
386
        @isoentry('edition')
387
        def number(self, out, value):
388
            if value.isdigit():
5 janik 389
                out.write(self.no)
2 janik 390
            out.write(value)
5 janik 391
 
2 janik 392
        @param(str)
5 janik 393
        @isoentry('note')
394
        def note(self, out, value):
395
            out.write(value)
396
 
397
        @param(str)
398
        @isoentry('standardnumber')
2 janik 399
        def isbn(self, out, value):
400
            out.write('ISBN~')
401
            out.write(value)
7 janik 402
 
403
        @param(str)
404
        @isoentry('url')
405
        def url(self, out, value):
10 janik 406
            out.write(u'\\\\Dostupné online: $<$')
22 janik 407
            out.write(u'\\url{')
7 janik 408
            out.write(value)
22 janik 409
            out.write(u'}')
10 janik 410
            out.write('$>$')
7 janik 411
 
2 janik 412
        ##########################
5 janik 413
 
2 janik 414
        def compareBy(self):
7 janik 415
            if 'author' in self:
10 janik 416
                return ''.join(i[1] for i in self['author']) + "%s"%self['year', '0000'] + self['title']
7 janik 417
            else:
10 janik 418
                return ''.join(i[0] for i in self['title'].split() if i[0].isalpha()) + "%s"%self['year', '0000'] + self['title']
2 janik 419
 
5 janik 420
    class Book(Misc):
421
        pass
422
 
423
    class InBook(Misc):
424
        @param(str)
425
        @isoentry('part')
426
        def chapter(self, out, value):
427
            out.write(self.chap)
428
            out.write('~')
429
            out.write(value)
430
 
431
        @isoentry('part')
432
        def section(self, out, value):
433
            out.write(self.sec)
434
            out.write('~')
435
            out.write(value)
436
 
437
        @param(str)
438
        @isoentry('part')
439
        def pages(self, out, value):
440
            out.write(self.p)
441
            out.write('~')
442
            out.write(value)
443
 
444
    class InProceedings(Misc):
445
        pass
446
 
7 janik 447
    class Article(Misc):
448
        @param(str, insteadOf('booktitle'))
449
        @isoentry('booktitle')
450
        def journal(self, out, value):
451
            out.write('In:~\\emph{')
452
            out.write(value)
453
 
454
            if 'booksubtitle' in self:
455
                out.setSeparator('~:~')
456
            else:
457
                out.write('}')
458
 
10 janik 459
        @param(str, insteadOf('isbn'))
460
        @isoentry('standardnumber')
461
        def issn(self, out, value):
462
            out.write('ISSN~')
463
            out.write(value)
464
 
14 janik 465
    class PhdThesis(Misc):
466
        @param(str, insteadOf('publisher'))
467
        @isoentry('publisher')
468
        def school(self, out, value):
469
            out.write(value)
26 janik 470
 
471
        @noparam(insteadOf('note'))
472
        @isoentry('note')
473
        def typenote(self, out):
474
            out.write(self.phdname)
14 janik 475
 
25 janik 476
    class TechReport(Misc):
477
        @param(str, insteadOf('publisher'))
478
        @isoentry('publisher')
479
        def institution(self, out, value):
480
            out.write(value)
481
 
482
        @noparam(insteadOf('note'))
483
        @isoentry('note')
484
        def typenote(self, out):
485
            out.write(self.techrepname)
486
 
10 janik 487
class SlovakBaseNum(SlovakBase):
2 janik 488
    class Labeling:
489
        __noentry__ = True
5 janik 490
 
2 janik 491
        def itemLabel(self):
492
            pass
5 janik 493
 
7 janik 494
        def compareBy(self):
495
            if 'author' in self:
10 janik 496
                return ''.join(i[1] for i in self['author']) + "%s"%self['year', '0000'] + self['title']
7 janik 497
            else:
10 janik 498
                return '\xFF' + "%s"%self['year', '0000'] + self['title']
7 janik 499
 
5 janik 500
class Slovak(SlovakBase):
501
    class Config:
502
        __noentry__ = True
503
 
504
        AuthorSeparator     = ' -- '
505
        SurnameStyle        = '{\\scshape '
506
        MaxAuthorsCount     = 3
507
        etal                = 'a i.'
508
        others              = 'a kol.'
509
        ed                  = 'vyd.'
510
        sineloco            = 's.l.'
511
        sinenomine          = 's.n.'
512
        sineanum            = 's.a.'
513
        p                   = 's.'
12 janik 514
        no                  = 'n$^\\circ$'
10 janik 515
        vol                 = 'vol.'
5 janik 516
        chap                = 'kap.'
517
        sec                 = 'odd.'
25 janik 518
        techrepname         = 'Technick\\\'a spr\\\'ava'
5 janik 519
 
10 janik 520
class SlovakNum(SlovakBase):
521
    Labeling = useAgain(SlovakBaseNum.Labeling)
522
    Config = useAgain(Slovak.Config)