]> git.lyx.org Git - lyx.git/blob - src/LaTeXFeatures.h
Fix compiler warnings spotted by Uwe
[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         /// Do we need to pass the languages to babel directly?
70         bool needBabelLangOptions() 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, bool use_polyglossia) const;
77         ///
78         docstring const getTClassHTMLStyles() const;
79         ///
80         docstring const getTClassHTMLPreamble() const;
81         /// The sgml definitions needed by the document (docbook)
82         docstring const getLyXSGMLEntities() const;
83         /// The SGML Required to include the files added with includeFile();
84         docstring const getIncludedFiles(std::string const & fname) const;
85         /// Include a file for use with the SGML entities
86         void includeFile(docstring const & key, std::string const & name);
87         /// The float definitions.
88         void getFloatDefinitions(otexstream & os) const;
89         /// Print requirements to lyxerr
90         void showStruct() const;
91         /// Add preamble snippet with TexRow information
92         void addPreambleSnippet(TexString snippet, bool allowdupes = false);
93         /// Add preamble snippet without TexRow information
94         void addPreambleSnippet(docstring const & snippet, bool allowdupes = false);
95         ///
96         TexString getPreambleSnippets() const;
97         ///
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         /// Is the (required) package available?
106         static bool isAvailable(std::string const & name);
107         /// Has the package been required?
108         bool isRequired(std::string const & name) const;
109         /** Is this feature already provided
110          *  e.g. by the document class?
111         */
112         bool isProvided(std::string const & name) const;
113         /** Is it necessary to load the package? This is true if
114             isRequired is true and the feature is not already provided
115         */
116         bool mustProvide(std::string const & name) const;
117         ///
118         void useFloat(std::string const & name, bool subfloat = false);
119         ///
120         void useLanguage(Language const *);
121         ///
122         bool hasLanguages() const;
123         /// check if all used languages are supported by polyglossia
124         bool hasOnlyPolyglossiaLanguages() const;
125         /// check if a language is supported only by polyglossia
126         bool hasPolyglossiaExclusiveLanguages() const;
127         ///
128         std::string getBabelLanguages() const;
129         ///
130         std::map<std::string, std::string> getPolyglossiaLanguages() const;
131         ///
132         std::set<std::string> getEncodingSet(std::string const & doc_encoding) const;
133         ///
134         void getFontEncodings(std::vector<std::string> & encodings) const;
135         ///
136         void useLayout(docstring const & lyt);
137         ///
138         void useInsetLayout(InsetLayout const & lay);
139         ///
140         Buffer const & buffer() const;
141         ///
142         void setBuffer(Buffer const &);
143         ///
144         BufferParams const & bufferParams() const;
145         /** Which language package do we require? \p englishbabel determines
146          *  if we require babel even if English is the only language.
147          */
148         LangPackage langPackage() const;
149         /// Convenience function to test if we use babel
150         bool useBabel() const { return langPackage() == LANG_PACK_BABEL; }
151         /// Convenience function to test if we use polyglossia
152         bool usePolyglossia() const { return langPackage() == LANG_PACK_POLYGLOSSIA; }
153         /// are we in a float?
154         bool inFloat() const { return in_float_; }
155         /// are we in a float?
156         void inFloat(bool const b) { in_float_ = b; }
157         /// are we in a deleted inset?
158         bool inDeletedInset() const { return in_deleted_inset_; }
159         /// are we in a deleted inset?
160         void inDeletedInset(bool const b) { in_deleted_inset_ = b; }
161         /// Runparams that will be used for exporting this file.
162         OutputParams const & runparams() const { return runparams_; }
163         /// Resolve alternatives like "esint|amsmath|wasysym"
164         void resolveAlternatives();
165         /// Expand multiple requirements like "textcomp,lyxmathsym,amstext"
166         void expandMultiples();
167         ///
168         void setHTMLTitle(docstring const & t) { htmltitle_ = t; }
169         ///
170         docstring const & htmlTitle() const { return htmltitle_; }
171
172 private:
173         ///
174         void useLayout(docstring const &, int);
175         ///
176         std::list<docstring> usedLayouts_;
177         ///
178         std::list<docstring> usedInsetLayouts_;
179         /// The features that are needed by the document
180         typedef std::set<std::string> Features;
181         ///
182         Features features_;
183         /// Static preamble bits, from external templates, or anywhere else
184         typedef std::list<TexString> SnippetList;
185         ///
186         SnippetList preamble_snippets_;
187         ///
188         SnippetList css_snippets_;
189         ///
190         typedef std::set<Language const *> LanguageList;
191         /// used languages (only those that are supported by babel)
192         LanguageList UsedLanguages_;
193         ///
194         typedef std::map<std::string, bool> UsedFloats;
195         ///
196         UsedFloats usedFloats_;
197         ///
198         typedef std::map<docstring, std::string> FileMap;
199         ///
200         FileMap IncludedFiles_;
201         /** Buffer of the file being processed.
202          *  This may be a child buffer of the to-be-exported file and
203          *  therefore may not be the buffer that belongs to params_.
204          *  Only needed by InsetInclude::validate().
205          */
206         Buffer const * buffer_;
207         ///
208         BufferParams const & params_;
209         /** Some insets need to know details about the to-be-produced file
210          *  in validate().
211          */
212         OutputParams const & runparams_;
213         ///
214         bool in_float_;
215         ///
216         bool in_deleted_inset_;
217         ///
218         docstring htmltitle_;
219 };
220
221
222 } // namespace lyx
223
224 #endif