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 docstring expandFormat(std::string const & fmt,
121 BibTeXInfo const * const xref, bool richtext) const;
122 /// true if from BibTeX; false if from bibliography environment
124 /// the BibTeX key for this entry
126 /// the label that will appear in citations
127 /// this is easily set from bibliography environments, but has
128 /// to be calculated for entries we get from BibTeX
130 /// a single string containing all BibTeX data associated with this key
132 /// the BibTeX entry type (article, book, incollection, ...)
133 docstring entry_type_;
134 /// a cache for getInfo()
135 mutable docstring info_;
137 docstring cite_number_;
140 /// our map: <field, value>
141 std::map <docstring, docstring> bimap_;
145 /// Class to represent a collection of bibliographical data, whether
146 /// from BibTeX or from bibliography environments.
149 /// bibliography key --> data for that key
150 typedef std::map<docstring, BibTeXInfo>::const_iterator const_iterator;
151 /// \return a sorted vector of bibliography keys
152 std::vector<docstring> const getKeys() const;
153 /// \return a sorted vector of present BibTeX fields
154 std::vector<docstring> const getFields() const;
155 /// \return a sorted vector of BibTeX entry types in use
156 std::vector<docstring> const getEntries() const;
157 /// \return the short form of an authorlist
158 docstring const getAbbreviatedAuthor(docstring const & key) const;
159 /// \return the year from the bibtex data record for \param key
160 /// if \param use_modifier is true, then we will also append any
161 /// modifier for this entry (e.g., 1998b).
162 /// Note that this will get the year from the crossref if it's
163 /// not present in the record itself.
164 docstring const getYear(docstring const & key,
165 bool use_modifier = false) const;
167 docstring const getCiteNumber(docstring const & key) const;
168 /// \return formatted BibTeX data associated with a given key.
169 /// Empty if no info exists.
170 /// Note that this will retrieve data from the crossref as needed.
171 docstring const getInfo(docstring const & key, Buffer const & buf,
172 bool richtext = false) const;
173 /// Is this a reference from a bibtex database
174 /// or from a bibliography environment?
175 bool isBibtex(docstring const & key) const;
177 * "Translates" the available Citation Styles into strings for a given key,
178 * either numerical or author-year depending upon the active engine. (See
179 * below for those methods.)
181 std::vector<docstring> const
182 getCiteStrings(docstring const & key, Buffer const & buf) const;
184 * "Translates" the available Citation Styles into strings for a given key.
185 * The returned string is displayed by the GUI.
186 * [XX] is used in place of the actual reference
187 * Eg, the vector will contain: [XX], Jones et al. [XX], ...
192 std::vector<docstring> const
193 getNumericalStrings(docstring const & key, Buffer const & buf) const;
195 * "Translates" the available Citation Styles into strings for a given key.
196 * The returned string is displayed by the GUI.
197 * Eg, the vector will contain:
198 * Jones et al. (1990), (Jones et al. 1990), Jones et al. 1990, ...
203 std::vector<docstring> const
204 getAuthorYearStrings(docstring const & key, Buffer const & buf) const;
205 /// Collects the cited entries from buf.
206 void collectCitedEntries(Buffer const & buf);
207 /// A list of BibTeX keys cited in the current document, sorted by
208 /// the last name of the author.
209 /// Make sure you have called collectCitedEntries() before you try to
210 /// use this. You should probably call it just before you use this.
211 std::vector<docstring> const & citedEntries() const
212 { return cited_entries_; }
214 void makeCitationLabels(Buffer const & buf);
216 const_iterator begin() const { return bimap_.begin(); }
218 void clear() { bimap_.clear(); }
220 bool empty() const { return bimap_.empty(); }
222 const_iterator end() const { return bimap_.end(); }
224 const_iterator find(docstring const & f) const { return bimap_.find(f); }
226 void mergeBiblioInfo(BiblioInfo const & info);
228 BibTeXInfo & operator[](docstring const & f) { return bimap_[f]; }
230 void addFieldName(docstring const & f) { field_names_.insert(f); }
232 void addEntryType(docstring const & f) { entry_types_.insert(f); }
235 std::set<docstring> field_names_;
237 std::set<docstring> entry_types_;
238 /// our map: keys --> BibTeXInfo
239 std::map<docstring, BibTeXInfo> bimap_;
240 /// a possibly sorted list of entries cited in our Buffer.
241 /// do not try to make this a vector<BibTeXInfo *> or anything of
242 /// the sort, because reloads will invalidate those pointers.
243 std::vector<docstring> cited_entries_;
248 #endif // BIBLIOINFO_H