]> git.lyx.org Git - lyx.git/blob - src/LaTeXFeatures.h
Avoid full metrics computation with Update:FitCursor
[lyx.git] / src / LaTeXFeatures.h
1 // -*- C++ -*-
2 /**
3  * \file LaTeXFeatures.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef LATEXFEATURES_H
14 #define LATEXFEATURES_H
15
16 #include "support/docstring.h"
17
18 #include <set>
19 #include <list>
20 #include <map>
21 #include <vector>
22
23
24 namespace lyx {
25
26 class Buffer;
27 class BufferParams;
28 class InsetLayout;
29 class Language;
30 class otexstream;
31 class OutputParams;
32 struct TexString;
33
34 /** The packages and commands that a buffer needs. This class
35  *  contains a list<string>.  Each of the LaTeX packages that a buffer needs
36  *  should be added with void require(string const & name).
37  *
38  *  i.e require("amssymb")
39  *
40  *  To add support you should only need to require() the package name as
41  *  packages which don't have special requirements are handled automatically.
42  *  If your new package does need special consideration you'll need to alter
43  *  string const getPackages() const;
44  *  Remember to update the validate function in Buffer.cpp and Paragraph.cpp
45  *  when you do so.
46  */
47 class LaTeXFeatures {
48 public:
49         /// Which Language package do we use?
50         enum LangPackage {
51                 LANG_PACK_NONE,
52                 LANG_PACK_BABEL,
53                 LANG_PACK_POLYGLOSSIA,
54                 LANG_PACK_CUSTOM
55         };
56         ///
57         LaTeXFeatures(Buffer const &, BufferParams const &,
58                       OutputParams const &);
59         /// The color packages
60         std::string const getColorOptions() const;
61         /// The requested package options
62         std::string const getPackageOptions() const;
63         /// The packages needed by the document
64         std::string const getPackages() const;
65         /// The macros definitions needed by the document
66         TexString getMacros() const;
67         /// Extra preamble code before babel is called
68         docstring const getBabelPresettings() const;
69         /// Extra preamble code after babel is called
70         docstring const getBabelPostsettings() const;
71         /// Load AMS packages when appropriate
72         std::string const loadAMSPackages() const;
73         /// The definitions needed by the document's textclass
74         docstring const getTClassPreamble() const;
75         /// The language dependent definitions needed by the document's textclass
76         docstring const getTClassI18nPreamble(bool use_babel,
77                                 bool use_polyglossia, bool use_minted) const;
78         ///
79         docstring const getTClassHTMLStyles() const;
80         ///
81         docstring const getTClassHTMLPreamble() const;
82         /// Include a file for use with the SGML entities
83         void includeFile(docstring const & key, std::string const & name);
84         /// The float definitions.
85         void getFloatDefinitions(otexstream & os) const;
86         /// Print requirements to lyxerr
87         void showStruct() const;
88         /// Add preamble snippet with TexRow information
89         void addPreambleSnippet(TexString snippet, bool allowdupes = false);
90         /// Add preamble snippet without TexRow information
91         void addPreambleSnippet(docstring const & snippet, bool allowdupes = false);
92         ///
93         TexString getPreambleSnippets() const;
94         /// Adds CSS information for HTML export.
95         /// Note that addPreambleSnippet is for LaTeX-type export
96         void addCSSSnippet(std::string const &);
97         ///
98         docstring getCSSSnippets() const;
99         /// Add a feature name requirements
100         void require(std::string const & name);
101         /// Add a set of feature names requirements
102         void require(std::set<std::string> const & names);
103         /// Add a feature name provision
104         void provide(std::string const & name);
105         /// Is the (required) package available?
106         static bool isAvailable(std::string const & name);
107         /// Is the (required) package available at least as of version
108         /// y/m/d?
109         static bool isAvailableAtLeastFrom(std::string const & name,
110                                            int const y, int const m, int const d = 1);
111         /// Has the package been required?
112         bool isRequired(std::string const & name) const;
113         /** Is this feature already provided
114          *  e.g. by the document class?
115         */
116         bool isProvided(std::string const & name) const;
117         /** Is it necessary to load the package? This is true if
118             isRequired is true and the feature is not already provided
119         */
120         bool mustProvide(std::string const & name) const;
121         ///
122         void useFloat(std::string const & name, bool subfloat = false);
123         ///
124         void useLanguage(Language const *);
125         ///
126         bool hasLanguages() const;
127         /// check if all used languages are supported by polyglossia
128         bool hasOnlyPolyglossiaLanguages() const;
129         /// check if a language is supported only by polyglossia
130         bool hasPolyglossiaExclusiveLanguages() const;
131         /// A vector of all used languages supported only by polyglossia
132         std::vector<std::string> getPolyglossiaExclusiveLanguages() const;
133         /// A vector of all used languages supported only by babel
134         std::vector<std::string> getBabelExclusiveLanguages() const;
135         ///
136         std::string getBabelLanguages() const;
137         ///
138         std::set<std::string> getPolyglossiaLanguages() const;
139         ///
140         std::string getActiveChars() const;
141         ///
142         std::set<std::string> getEncodingSet(std::string const & doc_encoding) const;
143         ///
144         void getFontEncodings(std::vector<std::string> & encodings,
145                               bool const onlylangs = false) const;
146         ///
147         void useLayout(docstring const & layoutname);
148         ///
149         void useInsetLayout(InsetLayout const & lay);
150         ///
151         Buffer const & buffer() const;
152         ///
153         void setBuffer(Buffer const &);
154         ///
155         BufferParams const & bufferParams() const;
156         /** Which language package do we require? \p englishbabel determines
157          *  if we require babel even if English is the only language.
158          */
159         LangPackage langPackage() const;
160         /// Convenience function to test if we use babel
161         bool useBabel() const { return langPackage() == LANG_PACK_BABEL; }
162         /// Convenience function to test if we use polyglossia
163         bool usePolyglossia() const { return langPackage() == LANG_PACK_POLYGLOSSIA; }
164         /// are we in a float?
165         bool inFloat() const { return in_float_; }
166         /// are we in a float?
167         void inFloat(bool const b) { in_float_ = b; }
168         /// are we in a deleted inset?
169         bool inDeletedInset() const { return in_deleted_inset_; }
170         /// are we in a deleted inset?
171         void inDeletedInset(bool const b) { in_deleted_inset_ = b; }
172         /// set savenote environment (footnote package)
173         std::string saveNoteEnv() const { return savenote_env_; }
174         /// return savenote environment
175         void saveNoteEnv(std::string const & s) { savenote_env_ = s; }
176         /// Runparams that will be used for exporting this file.
177         OutputParams const & runparams() const { return runparams_; }
178         /// Resolve alternatives like "esint|amsmath|wasysym"
179         void resolveAlternatives();
180         /// Expand multiple requirements like "textcomp,lyxmathsym,amstext"
181         void expandMultiples();
182         ///
183         void setHTMLTitle(docstring const & t) { htmltitle_ = t; }
184         ///
185         docstring const & htmlTitle() const { return htmltitle_; }
186         ///
187         bool hasRTLLanguage() const;
188
189 private:
190         ///
191         void useLayout(docstring const &, int);
192         ///
193         std::list<docstring> usedLayouts_;
194         ///
195         std::list<docstring> usedInsetLayouts_;
196         ///
197         typedef std::set<std::string> Features;
198         /// The features that are needed by the document
199         Features features_;
200         /// Features that are provided
201         Features provides_;
202         /// Static preamble bits, from external templates, or anywhere else
203         typedef std::list<TexString> SnippetList;
204         ///
205         SnippetList preamble_snippets_;
206         ///
207         SnippetList css_snippets_;
208         ///
209         typedef std::set<Language const *> LanguageList;
210         /// used languages (only those that are supported by babel)
211         LanguageList UsedLanguages_;
212         ///
213         typedef std::map<std::string, bool> UsedFloats;
214         ///
215         UsedFloats usedFloats_;
216         ///
217         typedef std::map<docstring, std::string> FileMap;
218         ///
219         FileMap IncludedFiles_;
220         /** Buffer of the file being processed.
221          *  This may be a child buffer of the to-be-exported file and
222          *  therefore may not be the buffer that belongs to params_.
223          *  Only needed by InsetInclude::validate().
224          */
225         Buffer const * buffer_;
226         ///
227         BufferParams const & params_;
228         /** Some insets need to know details about the to-be-produced file
229          *  in validate().
230          */
231         OutputParams const & runparams_;
232         ///
233         bool in_float_;
234         ///
235         bool in_deleted_inset_;
236         ///
237         docstring htmltitle_;
238         ///
239         std::string savenote_env_;
240 };
241
242
243 } // namespace lyx
244
245 #endif