4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
11 * Full author contact details are available in file CREDITS.
17 #include "support/docstring.h"
30 /// FIXME: To Citation.cpp?
31 /// Returns a vector of available Citation styles.
32 std::vector<CiteStyle> citeStyles(CiteEngine);
33 /// \param latex_str a LaTeX command, "cite", "Citep*", etc
34 CitationStyle citationStyleFromString(std::string const & latex_str);
35 /// the other way round
36 std::string citationStyleToString(CitationStyle const &);
39 /// Class to represent information about a BibTeX or
40 /// bibliography entry.
41 /// This class basically wraps a std::map, and many of its
42 /// methods simply delegate to the corresponding methods of
46 /// The keys are BibTeX fields (e.g., author, title, etc),
47 /// and the values are the associated field values.
48 typedef std::map<docstring, docstring>::const_iterator const_iterator;
50 BibTeXInfo() : is_bibtex_(true) {}
51 /// argument sets isBibTeX_, so should be false only if it's coming
52 /// from a bibliography environment
53 BibTeXInfo(bool ib) : is_bibtex_(ib) {}
54 /// constructor that sets the entryType
55 BibTeXInfo(docstring const & key, docstring const & type);
56 /// \return the short form of an authorlist
57 docstring const getAbbreviatedAuthor() const;
59 docstring const getYear() const;
61 docstring const getXRef() const;
62 /// \return formatted BibTeX data suitable for framing.
63 /// \param pointer to crossref information
64 docstring const & getInfo(BibTeXInfo const * const xref,
65 Buffer const & buf, bool richtext) const;
67 const_iterator find(docstring const & f) const { return bimap_.find(f); }
69 const_iterator end() const { return bimap_.end(); }
70 /// \return value for field f
71 /// note that this will create an empty field if it does not exist
72 docstring & operator[](docstring const & f)
74 /// \return value for field f
75 /// this one, since it is const, will simply return docstring() if
76 /// we don't have the field and will NOT create an empty field
77 docstring const & operator[](docstring const & field) const;
79 docstring const & operator[](std::string const & field) const;
81 docstring const & allData() const { return all_data_; }
83 void setAllData(docstring const & d) { all_data_ = d; }
85 void label(docstring const & d) { label_= d; }
87 docstring const & label() const { return label_; }
89 docstring const & key() const { return bib_key_; }
90 /// numerical key for citing this entry. currently used only
91 /// by XHTML output routines.
92 docstring citeNumber() const { return cite_number_; }
94 void setCiteNumber(docstring const & num) { cite_number_ = num; }
95 /// a,b,c, etc, for author-year. currently used only by XHTML
97 char modifier() const { return modifier_; }
99 void setModifier(char c) { modifier_ = c; }
101 docstring entryType() const { return entry_type_; }
103 bool isBibTeX() const { return is_bibtex_; }
105 /// like operator[], except, if the field is empty, it will attempt
106 /// to get the data from xref BibTeXInfo object, which would normally
107 /// be the one referenced in the crossref field.
108 docstring getValueForKey(std::string const & key,
109 BibTeXInfo const * const xref = 0) const;
110 /// replace %keys% in a format string with their values
111 /// called from getInfo()
112 /// format strings may contain:
113 /// %key%, which represents a key
114 /// {%key%[[format]]}, which prints format if key is non-empty
115 /// the latter may optionally contain an `else' clause as well:
116 /// {%key%[[if format]][[else format]]}
117 /// material intended only for rich text (HTML) output should be
118 /// wrapped in "{!" and "!}". it will be removed if richtext is
120 /// a simple macro facility is also available. keys that look like
121 /// "%!key%" are substituted with their definition.
122 /// moreover, keys that look like "%_key%" are treated as translatable
123 /// so that things like "pp." and "vol." can be translated.
124 docstring expandFormat(std::string const & fmt,
125 BibTeXInfo const * const xref, int & counter,
126 Buffer const & buf, bool richtext) const;
127 /// true if from BibTeX; false if from bibliography environment
129 /// the BibTeX key for this entry
131 /// the label that will appear in citations
132 /// this is easily set from bibliography environments, but has
133 /// to be calculated for entries we get from BibTeX
135 /// a single string containing all BibTeX data associated with this key
137 /// the BibTeX entry type (article, book, incollection, ...)
138 docstring entry_type_;
139 /// a cache for getInfo()
140 mutable docstring info_;
142 docstring cite_number_;
145 /// our map: <field, value>
146 std::map <docstring, docstring> bimap_;
150 /// Class to represent a collection of bibliographical data, whether
151 /// from BibTeX or from bibliography environments.
154 /// bibliography key --> data for that key
155 typedef std::map<docstring, BibTeXInfo>::const_iterator const_iterator;
156 /// \return a sorted vector of bibliography keys
157 std::vector<docstring> const getKeys() const;
158 /// \return a sorted vector of present BibTeX fields
159 std::vector<docstring> const getFields() const;
160 /// \return a sorted vector of BibTeX entry types in use
161 std::vector<docstring> const getEntries() const;
162 /// \return the short form of an authorlist
163 docstring const getAbbreviatedAuthor(docstring const & key) const;
164 /// \return the year from the bibtex data record for \param key
165 /// if \param use_modifier is true, then we will also append any
166 /// modifier for this entry (e.g., 1998b).
167 /// Note that this will get the year from the crossref if it's
168 /// not present in the record itself.
169 docstring const getYear(docstring const & key,
170 bool use_modifier = false) const;
172 docstring const getCiteNumber(docstring const & key) const;
173 /// \return formatted BibTeX data associated with a given key.
174 /// Empty if no info exists.
175 /// Note that this will retrieve data from the crossref as needed.
176 docstring const getInfo(docstring const & key, Buffer const & buf,
177 bool richtext = false) const;
178 /// Is this a reference from a bibtex database
179 /// or from a bibliography environment?
180 bool isBibtex(docstring const & key) const;
182 * "Translates" the available Citation Styles into strings for a given key,
183 * either numerical or author-year depending upon the active engine. (See
184 * below for those methods.)
186 std::vector<docstring> const
187 getCiteStrings(docstring const & key, Buffer const & buf) const;
189 * "Translates" the available Citation Styles into strings for a given key.
190 * The returned string is displayed by the GUI.
191 * [XX] is used in place of the actual reference
192 * Eg, the vector will contain: [XX], Jones et al. [XX], ...
197 std::vector<docstring> const
198 getNumericalStrings(docstring const & key, Buffer const & buf) const;
200 * "Translates" the available Citation Styles into strings for a given key.
201 * The returned string is displayed by the GUI.
202 * Eg, the vector will contain:
203 * Jones et al. (1990), (Jones et al. 1990), Jones et al. 1990, ...
208 std::vector<docstring> const
209 getAuthorYearStrings(docstring const & key, Buffer const & buf) const;
210 /// Collects the cited entries from buf.
211 void collectCitedEntries(Buffer const & buf);
212 /// A list of BibTeX keys cited in the current document, sorted by
213 /// the last name of the author.
214 /// Make sure you have called collectCitedEntries() before you try to
215 /// use this. You should probably call it just before you use this.
216 std::vector<docstring> const & citedEntries() const
217 { return cited_entries_; }
219 void makeCitationLabels(Buffer const & buf);
221 const_iterator begin() const { return bimap_.begin(); }
223 void clear() { bimap_.clear(); }
225 bool empty() const { return bimap_.empty(); }
227 const_iterator end() const { return bimap_.end(); }
229 const_iterator find(docstring const & f) const { return bimap_.find(f); }
231 void mergeBiblioInfo(BiblioInfo const & info);
233 BibTeXInfo & operator[](docstring const & f) { return bimap_[f]; }
235 void addFieldName(docstring const & f) { field_names_.insert(f); }
237 void addEntryType(docstring const & f) { entry_types_.insert(f); }
240 std::set<docstring> field_names_;
242 std::set<docstring> entry_types_;
243 /// our map: keys --> BibTeXInfo
244 std::map<docstring, BibTeXInfo> bimap_;
245 /// a possibly sorted list of entries cited in our Buffer.
246 /// do not try to make this a vector<BibTeXInfo *> or anything of
247 /// the sort, because reloads will invalidate those pointers.
248 std::vector<docstring> cited_entries_;
253 #endif // BIBLIOINFO_H