]> git.lyx.org Git - lyx.git/blob - src/BiblioInfo.cpp
Remove it for real now.
[lyx.git] / src / BiblioInfo.cpp
1 /**
2  * \file BiblioInfo.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author Herbert Voß
8  * \author Richard Heck
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "BiblioInfo.h"
16 #include "Buffer.h"
17 #include "BufferParams.h"
18 #include "buffer_funcs.h"
19 #include "Encoding.h"
20 #include "InsetIterator.h"
21 #include "Paragraph.h"
22 #include "TocBackend.h"
23
24 #include "insets/Inset.h"
25 #include "insets/InsetBibitem.h"
26 #include "insets/InsetBibtex.h"
27 #include "insets/InsetInclude.h"
28
29 #include "support/convert.h"
30 #include "support/docstream.h"
31 #include "support/gettext.h"
32 #include "support/lassert.h"
33 #include "support/lstrings.h"
34 #include "support/textutils.h"
35
36 #include "boost/regex.hpp"
37
38 #include <set>
39
40 using namespace std;
41 using namespace lyx::support;
42
43
44 namespace lyx {
45
46 namespace {
47
48 // gets the "family name" from an author-type string
49 docstring familyName(docstring const & name)
50 {
51         if (name.empty())
52                 return docstring();
53
54         // first we look for a comma, and take the last name to be everything
55         // preceding the right-most one, so that we also get the "jr" part.
56         docstring::size_type idx = name.rfind(',');
57         if (idx != docstring::npos)
58                 return ltrim(name.substr(0, idx));
59
60         // OK, so now we want to look for the last name. We're going to
61         // include the "von" part. This isn't perfect.
62         // Split on spaces, to get various tokens.
63         vector<docstring> pieces = getVectorFromString(name, from_ascii(" "));
64         // If we only get two, assume the last one is the last name
65         if (pieces.size() <= 2)
66                 return pieces.back();
67
68         // Now we look for the first token that begins with a lower case letter.
69         vector<docstring>::const_iterator it = pieces.begin();
70         vector<docstring>::const_iterator en = pieces.end();
71         for (; it != en; ++it) {
72                 if ((*it).size() == 0)
73                         continue;
74                 char_type const c = (*it)[0];
75                 if (isLower(c))
76                         break;
77         }
78
79         if (it == en) // we never found a "von"
80                 return pieces.back();
81
82         // reconstruct what we need to return
83         docstring retval;
84         bool first = true;
85         for (; it != en; ++it) {
86                 if (!first)
87                         retval += " ";
88                 else 
89                         first = false;
90                 retval += *it;
91         }
92         return retval;
93 }
94
95 // converts a string containing LaTeX commands into unicode
96 // for display.
97 docstring convertLaTeXCommands(docstring const & str)
98 {
99         docstring val = str;
100         docstring ret;
101
102         bool scanning_cmd = false;
103         bool scanning_math = false;
104         bool escaped = false; // used to catch \$, etc.
105         while (val.size()) {
106                 char_type const ch = val[0];
107
108                 // if we're scanning math, we output everything until we
109                 // find an unescaped $, at which point we break out.
110                 if (scanning_math) {
111                         if (escaped)
112                                 escaped = false;
113                         else if (ch == '\\')
114                                 escaped = true;
115                         else if (ch == '$') 
116                                 scanning_math = false;
117                         ret += ch;
118                         val = val.substr(1);
119                         continue;
120                 }
121
122                 // if we're scanning a command name, then we just
123                 // discard characters until we hit something that
124                 // isn't alpha.
125                 if (scanning_cmd) {
126                         if (isAlphaASCII(ch)) {
127                                 val = val.substr(1);
128                                 escaped = false;
129                                 continue;
130                         }
131                         // so we're done with this command.
132                         // now we fall through and check this character.
133                         scanning_cmd = false;
134                 }
135
136                 // was the last character a \? If so, then this is something like:
137                 // \\ or \$, so we'll just output it. That's probably not always right...
138                 if (escaped) {
139                         // exception: output \, as THIN SPACE
140                         if (ch == ',')
141                                 ret.push_back(0x2009);
142                         else
143                                 ret += ch;
144                         val = val.substr(1);
145                         escaped = false;
146                         continue;
147                 }
148
149                 if (ch == '$') {
150                         ret += ch;
151                         val = val.substr(1);
152                         scanning_math = true;
153                         continue;
154                 }
155
156                 // we just ignore braces
157                 if (ch == '{' || ch == '}') {
158                         val = val.substr(1);
159                         continue;
160                 }
161
162                 // we're going to check things that look like commands, so if
163                 // this doesn't, just output it.
164                 if (ch != '\\') {
165                         ret += ch;
166                         val = val.substr(1);
167                         continue;
168                 }
169
170                 // ok, could be a command of some sort
171                 // let's see if it corresponds to some unicode
172                 // unicodesymbols has things in the form: \"{u},
173                 // whereas we may see things like: \"u. So we'll
174                 // look for that and change it, if necessary.
175                 static boost::regex const reg("^\\\\\\W\\w");
176                 if (boost::regex_search(to_utf8(val), reg)) {
177                         val.insert(3, from_ascii("}"));
178                         val.insert(2, from_ascii("{"));
179                 }
180                 docstring rem;
181                 docstring const cnvtd = Encodings::fromLaTeXCommand(val, rem,
182                                                         Encodings::TEXT_CMD);
183                 if (!cnvtd.empty()) {
184                         // it did, so we'll take that bit and proceed with what's left
185                         ret += cnvtd;
186                         val = rem;
187                         continue;
188                 }
189                 // it's a command of some sort
190                 scanning_cmd = true;
191                 escaped = true;
192                 val = val.substr(1);
193         }
194         return ret;
195 }
196
197 } // anon namespace
198
199
200 //////////////////////////////////////////////////////////////////////
201 //
202 // BibTeXInfo
203 //
204 //////////////////////////////////////////////////////////////////////
205
206 BibTeXInfo::BibTeXInfo(docstring const & key, docstring const & type)
207         : is_bibtex_(true), bib_key_(key), entry_type_(type), info_(),
208           modifier_(0)
209 {}
210
211
212 docstring const BibTeXInfo::getAbbreviatedAuthor() const
213 {
214         if (!is_bibtex_) {
215                 docstring const opt = label();
216                 if (opt.empty())
217                         return docstring();
218
219                 docstring authors;
220                 split(opt, authors, '(');
221                 return authors;
222         }
223
224         docstring author = convertLaTeXCommands(operator[]("author"));
225         if (author.empty()) {
226                 author = convertLaTeXCommands(operator[]("editor"));
227                 if (author.empty())
228                         return bib_key_;
229         }
230
231         // OK, we've got some names. Let's format them.
232         // Try to split the author list on " and "
233         vector<docstring> const authors =
234                 getVectorFromString(author, from_ascii(" and "));
235
236         if (authors.size() == 2)
237                 return bformat(_("%1$s and %2$s"),
238                         familyName(authors[0]), familyName(authors[1]));
239
240         if (authors.size() > 2)
241                 return bformat(_("%1$s et al."), familyName(authors[0]));
242
243         return familyName(authors[0]);
244 }
245
246
247 docstring const BibTeXInfo::getYear() const
248 {
249         if (is_bibtex_) 
250                 return operator[]("year");
251
252         docstring const opt = label();
253         if (opt.empty())
254                 return docstring();
255
256         docstring authors;
257         docstring const tmp = split(opt, authors, '(');
258         docstring year;
259         split(tmp, year, ')');
260         return year;
261 }
262
263
264 docstring const BibTeXInfo::getXRef() const
265 {
266         if (!is_bibtex_)
267                 return docstring();
268         return operator[]("crossref");
269 }
270
271
272 docstring const & BibTeXInfo::getInfo(BibTeXInfo const * const xref) const
273 {
274         if (!info_.empty())
275                 return info_;
276
277         if (!is_bibtex_) {
278                 BibTeXInfo::const_iterator it = find(from_ascii("ref"));
279                 info_ = it->second;
280                 return info_;
281         }
282  
283         // FIXME
284         // This could be made a lot better using the entry_type_
285         // field to customize the output based upon entry type.
286         
287         // Search for all possible "required" fields
288         docstring author = getValueForKey("author", xref);
289         if (author.empty())
290                 author = getValueForKey("editor", xref);
291  
292         docstring year   = getValueForKey("year", xref);
293         docstring title  = getValueForKey("title", xref);
294         docstring docLoc = getValueForKey("pages", xref);
295         if (docLoc.empty()) {
296                 docLoc = getValueForKey("chapter", xref);
297                 if (!docLoc.empty())
298                         docLoc = _("Ch. ") + docLoc;
299         }       else {
300                 docLoc = _("pp. ") + docLoc;
301         }
302
303         docstring media = getValueForKey("journal", xref);
304         if (media.empty()) {
305                 media = getValueForKey("publisher", xref);
306                 if (media.empty()) {
307                         media = getValueForKey("school", xref);
308                         if (media.empty())
309                                 media = getValueForKey("institution");
310                 }
311         }
312         docstring volume = getValueForKey("volume", xref);
313
314         odocstringstream result;
315         if (!author.empty())
316                 result << author << ", ";
317         if (!title.empty())
318                 result << title;
319         if (!media.empty())
320                 result << ", " << media;
321         if (!year.empty())
322                 result << " (" << year << ")";
323         if (!docLoc.empty())
324                 result << ", " << docLoc;
325
326         docstring const result_str = rtrim(result.str());
327         if (!result_str.empty()) {
328                 info_ = convertLaTeXCommands(result_str);
329                 return info_;
330         }
331
332         // This should never happen (or at least be very unusual!)
333         static docstring e = docstring();
334         return e;
335 }
336
337
338 docstring const & BibTeXInfo::operator[](docstring const & field) const
339 {
340         BibTeXInfo::const_iterator it = find(field);
341         if (it != end())
342                 return it->second;
343         static docstring const empty_value = docstring();
344         return empty_value;
345 }
346         
347         
348 docstring const & BibTeXInfo::operator[](string const & field) const
349 {
350         return operator[](from_ascii(field));
351 }
352
353
354 docstring BibTeXInfo::getValueForKey(string const & key, 
355                 BibTeXInfo const * const xref) const
356 {
357         docstring const ret = operator[](key);
358         if (!ret.empty() || !xref)
359                 return ret;
360         return (*xref)[key];
361 }
362
363
364 //////////////////////////////////////////////////////////////////////
365 //
366 // BiblioInfo
367 //
368 //////////////////////////////////////////////////////////////////////
369
370 namespace {
371 // A functor for use with sort, leading to case insensitive sorting
372         class compareNoCase: public binary_function<docstring, docstring, bool>
373         {
374                 public:
375                         bool operator()(docstring const & s1, docstring const & s2) const {
376                                 return compare_no_case(s1, s2) < 0;
377                         }
378         };
379 } // namespace anon
380
381
382 vector<docstring> const BiblioInfo::getKeys() const
383 {
384         vector<docstring> bibkeys;
385         BiblioInfo::const_iterator it  = begin();
386         for (; it != end(); ++it)
387                 bibkeys.push_back(it->first);
388         sort(bibkeys.begin(), bibkeys.end(), compareNoCase());
389         return bibkeys;
390 }
391
392
393 vector<docstring> const BiblioInfo::getFields() const
394 {
395         vector<docstring> bibfields;
396         set<docstring>::const_iterator it = field_names_.begin();
397         set<docstring>::const_iterator end = field_names_.end();
398         for (; it != end; ++it)
399                 bibfields.push_back(*it);
400         sort(bibfields.begin(), bibfields.end());
401         return bibfields;
402 }
403
404
405 vector<docstring> const BiblioInfo::getEntries() const
406 {
407         vector<docstring> bibentries;
408         set<docstring>::const_iterator it = entry_types_.begin();
409         set<docstring>::const_iterator end = entry_types_.end();
410         for (; it != end; ++it)
411                 bibentries.push_back(*it);
412         sort(bibentries.begin(), bibentries.end());
413         return bibentries;
414 }
415
416
417 docstring const BiblioInfo::getAbbreviatedAuthor(docstring const & key) const
418 {
419         BiblioInfo::const_iterator it = find(key);
420         if (it == end())
421                 return docstring();
422         BibTeXInfo const & data = it->second;
423         return data.getAbbreviatedAuthor();
424 }
425
426
427 docstring const BiblioInfo::getCiteNumber(docstring const & key) const
428 {
429         BiblioInfo::const_iterator it = find(key);
430         if (it == end())
431                 return docstring();
432         BibTeXInfo const & data = it->second;
433         return data.citeNumber();
434 }
435
436
437 docstring const BiblioInfo::getYear(docstring const & key, bool use_modifier) const
438 {
439         BiblioInfo::const_iterator it = find(key);
440         if (it == end())
441                 return docstring();
442         BibTeXInfo const & data = it->second;
443         docstring year = data.getYear();
444         if (year.empty()) {
445                 // let's try the crossref
446                 docstring const xref = data.getXRef();
447                 if (xref.empty())
448                         return _("No year"); // no luck
449                 BiblioInfo::const_iterator const xrefit = find(xref);
450                 if (xrefit == end())
451                         return _("No year"); // no luck again
452                 BibTeXInfo const & xref_data = xrefit->second;
453                 year = xref_data.getYear();
454         }
455         if (use_modifier && data.modifier() != 0)
456                 year += data.modifier();
457         return year;
458 }
459
460
461 docstring const BiblioInfo::getInfo(docstring const & key) const
462 {
463         BiblioInfo::const_iterator it = find(key);
464         if (it == end())
465                 return docstring();
466         BibTeXInfo const & data = it->second;
467         BibTeXInfo const * xrefptr = 0;
468         docstring const xref = data.getXRef();
469         if (!xref.empty()) {
470                 BiblioInfo::const_iterator const xrefit = find(xref);
471                 if (xrefit != end())
472                         xrefptr = &(xrefit->second);
473         }
474         return data.getInfo(xrefptr);
475 }
476
477
478 vector<docstring> const BiblioInfo::getCiteStrings(
479         docstring const & key, Buffer const & buf) const
480 {
481         CiteEngine const engine = buf.params().citeEngine();
482         if (engine == ENGINE_BASIC || engine == ENGINE_NATBIB_NUMERICAL)
483                 return getNumericalStrings(key, buf);
484         else
485                 return getAuthorYearStrings(key, buf);
486 }
487
488
489 vector<docstring> const BiblioInfo::getNumericalStrings(
490         docstring const & key, Buffer const & buf) const
491 {
492         if (empty())
493                 return vector<docstring>();
494
495         docstring const author = getAbbreviatedAuthor(key);
496         docstring const year   = getYear(key);
497         if (author.empty() || year.empty())
498                 return vector<docstring>();
499
500         vector<CiteStyle> const & styles = citeStyles(buf.params().citeEngine());
501         
502         vector<docstring> vec(styles.size());
503         for (size_t i = 0; i != vec.size(); ++i) {
504                 docstring str;
505
506                 switch (styles[i]) {
507                         case CITE:
508                         case CITEP:
509                                 str = from_ascii("[#ID]");
510                                 break;
511
512                         case NOCITE:
513                                 str = _("Add to bibliography only.");
514                                 break;
515
516                         case CITET:
517                                 str = author + " [#ID]";
518                                 break;
519
520                         case CITEALT:
521                                 str = author + " #ID";
522                                 break;
523
524                         case CITEALP:
525                                 str = from_ascii("#ID");
526                                 break;
527
528                         case CITEAUTHOR:
529                                 str = author;
530                                 break;
531
532                         case CITEYEAR:
533                                 str = year;
534                                 break;
535
536                         case CITEYEARPAR:
537                                 str = '(' + year + ')';
538                                 break;
539                 }
540
541                 vec[i] = str;
542         }
543
544         return vec;
545 }
546
547
548 vector<docstring> const BiblioInfo::getAuthorYearStrings(
549         docstring const & key, Buffer const & buf) const
550 {
551         if (empty())
552                 return vector<docstring>();
553
554         docstring const author = getAbbreviatedAuthor(key);
555         docstring const year   = getYear(key);
556         if (author.empty() || year.empty())
557                 return vector<docstring>();
558
559         vector<CiteStyle> const & styles = citeStyles(buf.params().citeEngine());
560         
561         vector<docstring> vec(styles.size());
562         for (size_t i = 0; i != vec.size(); ++i) {
563                 docstring str;
564
565                 switch (styles[i]) {
566                         case CITE:
567                 // jurabib only: Author/Annotator
568                 // (i.e. the "before" field, 2nd opt arg)
569                                 str = author + "/<" + _("before") + '>';
570                                 break;
571
572                         case NOCITE:
573                                 str = _("Add to bibliography only.");
574                                 break;
575
576                         case CITET:
577                                 str = author + " (" + year + ')';
578                                 break;
579
580                         case CITEP:
581                                 str = '(' + author + ", " + year + ')';
582                                 break;
583
584                         case CITEALT:
585                                 str = author + ' ' + year ;
586                                 break;
587
588                         case CITEALP:
589                                 str = author + ", " + year ;
590                                 break;
591
592                         case CITEAUTHOR:
593                                 str = author;
594                                 break;
595
596                         case CITEYEAR:
597                                 str = year;
598                                 break;
599
600                         case CITEYEARPAR:
601                                 str = '(' + year + ')';
602                                 break;
603                 }
604                 vec[i] = str;
605         }
606         return vec;
607 }
608
609
610 void BiblioInfo::mergeBiblioInfo(BiblioInfo const & info)
611 {
612         bimap_.insert(info.begin(), info.end());
613 }
614
615
616 namespace {
617         // used in xhtml to sort a list of BibTeXInfo objects
618         bool lSorter(BibTeXInfo const * lhs, BibTeXInfo const * rhs)
619         {
620                 docstring const lauth = lhs->getAbbreviatedAuthor();
621                 docstring const rauth = rhs->getAbbreviatedAuthor();
622                 docstring const lyear = lhs->getYear();
623                 docstring const ryear = rhs->getYear();
624                 docstring const ltitl = lhs->operator[]("title");
625                 docstring const rtitl = rhs->operator[]("title");
626                 return  (lauth < rauth)
627                                 || (lauth == rauth && lyear < ryear)
628                                 || (lauth == rauth && lyear == ryear && ltitl < rtitl);
629         }
630 }
631
632
633 void BiblioInfo::collectCitedEntries(Buffer const & buf)
634 {
635         cited_entries_.clear();
636         // We are going to collect all the citation keys used in the document,
637         // getting them from the TOC.
638         // FIXME We may want to collect these differently, in the first case,
639         // so that we might have them in order of appearance.
640         set<docstring> citekeys;
641         Toc const & toc = buf.tocBackend().toc("citation");
642         Toc::const_iterator it = toc.begin();
643         Toc::const_iterator const en = toc.end();
644         for (; it != en; ++it) {
645                 if (it->str().empty())
646                         continue;
647                 vector<docstring> const keys = getVectorFromString(it->str());
648                 citekeys.insert(keys.begin(), keys.end());
649         }
650         if (citekeys.empty())
651                 return;
652         
653         // We have a set of the keys used in this document.
654         // We will now convert it to a list of the BibTeXInfo objects used in 
655         // this document...
656         vector<BibTeXInfo const *> bi;
657         set<docstring>::const_iterator cit = citekeys.begin();
658         set<docstring>::const_iterator const cen = citekeys.end();
659         for (; cit != cen; ++cit) {
660                 BiblioInfo::const_iterator const bt = find(*cit);
661                 if (bt == end() || !bt->second.isBibTeX())
662                         continue;
663                 bi.push_back(&(bt->second));
664         }
665         // ...and sort it.
666         sort(bi.begin(), bi.end(), lSorter);
667         
668         // Now we can write the sorted keys
669         vector<BibTeXInfo const *>::const_iterator bit = bi.begin();
670         vector<BibTeXInfo const *>::const_iterator ben = bi.end();
671         for (; bit != ben; ++bit)
672                 cited_entries_.push_back((*bit)->key());
673 }
674
675
676 void BiblioInfo::makeCitationLabels(Buffer const & buf)
677 {
678         collectCitedEntries(buf);
679         CiteEngine const engine = buf.params().citeEngine();
680         bool const numbers = 
681                 (engine == ENGINE_BASIC || engine == ENGINE_NATBIB_NUMERICAL);
682
683         int keynumber = 0;
684         char modifier = 0;
685         // used to remember the last one we saw
686         // we'll be comparing entries to see if we need to add
687         // modifiers, like "1984a"
688         map<docstring, BibTeXInfo>::iterator last;
689
690         vector<docstring>::const_iterator it = cited_entries_.begin();
691         vector<docstring>::const_iterator const en = cited_entries_.end();
692         for (; it != en; ++it) {
693                 map<docstring, BibTeXInfo>::iterator const biit = bimap_.find(*it);
694                 // this shouldn't happen, but...
695                 if (biit == bimap_.end())
696                         // ...fail gracefully, anyway.
697                         continue;
698                 BibTeXInfo & entry = biit->second;
699                 if (numbers) {
700                         docstring const num = convert<docstring>(++keynumber);
701                         entry.setCiteNumber(num);
702                 } else {
703                         if (it != cited_entries_.begin()
704                             && entry.getAbbreviatedAuthor() == last->second.getAbbreviatedAuthor()
705                             // we access the year via getYear() so as to get it from the xref,
706                             // if we need to do so
707                             && getYear(entry.key()) == getYear(last->second.key())) {
708                                 if (modifier == 0) {
709                                         // so the last one should have been 'a'
710                                         last->second.setModifier('a');
711                                         modifier = 'b';
712                                 } else if (modifier == 'z')
713                                         modifier = 'A';
714                                 else
715                                         modifier++;
716                         } else {
717                                 modifier = 0;
718                         }
719                         entry.setModifier(modifier);                            
720                         // remember the last one
721                         last = biit;
722                 }
723         }
724 }
725
726
727 //////////////////////////////////////////////////////////////////////
728 //
729 // CitationStyle
730 //
731 //////////////////////////////////////////////////////////////////////
732
733 namespace {
734
735
736 char const * const citeCommands[] = {
737         "cite", "citet", "citep", "citealt", "citealp",
738         "citeauthor", "citeyear", "citeyearpar", "nocite" };
739
740 unsigned int const nCiteCommands =
741                 sizeof(citeCommands) / sizeof(char *);
742
743 CiteStyle const citeStylesArray[] = {
744         CITE, CITET, CITEP, CITEALT, CITEALP, 
745         CITEAUTHOR, CITEYEAR, CITEYEARPAR, NOCITE };
746
747 unsigned int const nCiteStyles =
748                 sizeof(citeStylesArray) / sizeof(CiteStyle);
749
750 CiteStyle const citeStylesFull[] = {
751         CITET, CITEP, CITEALT, CITEALP, CITEAUTHOR };
752
753 unsigned int const nCiteStylesFull =
754                 sizeof(citeStylesFull) / sizeof(CiteStyle);
755
756 CiteStyle const citeStylesUCase[] = {
757         CITET, CITEP, CITEALT, CITEALP, CITEAUTHOR };
758
759 unsigned int const nCiteStylesUCase =
760         sizeof(citeStylesUCase) / sizeof(CiteStyle);
761
762 } // namespace anon
763
764
765 CitationStyle citationStyleFromString(string const & command)
766 {
767         CitationStyle s;
768         if (command.empty())
769                 return s;
770
771         string cmd = command;
772         if (cmd[0] == 'C') {
773                 s.forceUpperCase = true;
774                 cmd[0] = 'c';
775         }
776
777         size_t const n = cmd.size() - 1;
778         if (cmd != "cite" && cmd[n] == '*') {
779                 s.full = true;
780                 cmd = cmd.substr(0, n);
781         }
782
783         char const * const * const last = citeCommands + nCiteCommands;
784         char const * const * const ptr = find(citeCommands, last, cmd);
785
786         if (ptr != last) {
787                 size_t idx = ptr - citeCommands;
788                 s.style = citeStylesArray[idx];
789         }
790         return s;
791 }
792
793
794 string citationStyleToString(const CitationStyle & s)
795 {
796         string cite = citeCommands[s.style];
797         if (s.full) {
798                 CiteStyle const * last = citeStylesFull + nCiteStylesFull;
799                 if (std::find(citeStylesFull, last, s.style) != last)
800                         cite += '*';
801         }
802
803         if (s.forceUpperCase) {
804                 CiteStyle const * last = citeStylesUCase + nCiteStylesUCase;
805                 if (std::find(citeStylesUCase, last, s.style) != last)
806                         cite[0] = 'C';
807         }
808
809         return cite;
810 }
811
812 vector<CiteStyle> citeStyles(CiteEngine engine)
813 {
814         unsigned int nStyles = 0;
815         unsigned int start = 0;
816
817         switch (engine) {
818                 case ENGINE_BASIC:
819                         nStyles = 2;
820                         start = 0;
821                         break;
822                 case ENGINE_NATBIB_AUTHORYEAR:
823                 case ENGINE_NATBIB_NUMERICAL:
824                         nStyles = nCiteStyles - 1;
825                         start = 1;
826                         break;
827                 case ENGINE_JURABIB:
828                         nStyles = nCiteStyles;
829                         start = 0;
830                         break;
831         }
832
833         vector<CiteStyle> styles(nStyles);
834         size_t i = 0;
835         int j = start;
836         for (; i != styles.size(); ++i, ++j)
837                 styles[i] = citeStylesArray[j];
838
839         return styles;
840 }
841
842 } // namespace lyx
843