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