]> git.lyx.org Git - lyx.git/blob - src/LaTeXFeatures.h
Add Benjamin Piwowarski to contributors. Welcome to LyX!
[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
31 /** The packages and commands that a buffer needs. This class
32  *  contains a list<string>.  Each of the LaTeX packages that a buffer needs
33  *  should be added with void require(string const & name).
34  *
35  *  i.e require("amssymb")
36  *
37  *  To add support you should only need to require() the package name as
38  *  packages which don't have special requirements are handled automatically.
39  *  If your new package does need special consideration you'll need to alter
40  *  string const getPackages() const;
41  *  Remember to update the validate function in Buffer.cpp and Paragraph.cpp
42  *  when you do so.
43  */
44 class LaTeXFeatures {
45 public:
46         /// Which Language package do we use?
47         enum LangPackage {
48                 LANG_PACK_NONE,
49                 LANG_PACK_BABEL,
50                 LANG_PACK_POLYGLOSSIA,
51                 LANG_PACK_CUSTOM
52         };
53         ///
54         LaTeXFeatures(Buffer const &, BufferParams const &,
55                       OutputParams const &);
56         /// The color packages
57         std::string const getColorOptions() const;
58         /// The packages needed by the document
59         std::string const getPackages() const;
60         /// The macros definitions needed by the document
61         docstring const getMacros() const;
62         /// Extra preamble code before babel is called
63         std::string const getBabelPresettings() const;
64         /// Extra preamble code after babel is called
65         std::string const getBabelPostsettings() const;
66         /// Do we need to pass the languages to babel directly?
67         bool needBabelLangOptions() const;
68         /// Load AMS packages when appropriate
69         std::string const loadAMSPackages() const;
70         /// The definitions needed by the document's textclass
71         docstring const getTClassPreamble() const;
72         /// The language dependent definitions needed by the document's textclass
73         docstring const getTClassI18nPreamble(bool use_babel, bool use_polyglossia) const;
74         ///
75         docstring const getTClassHTMLStyles() const;
76         ///
77         docstring const getTClassHTMLPreamble() const;
78         /// The sgml definitions needed by the document (docbook)
79         docstring const getLyXSGMLEntities() const;
80         /// The SGML Required to include the files added with includeFile();
81         docstring const getIncludedFiles(std::string const & fname) 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(odocstream & os) const;
86         /// Print requirements to lyxerr
87         void showStruct() const;
88         ///
89         void addPreambleSnippet(std::string const &);
90         ///
91         std::string getPreambleSnippets() const;
92         ///
93         void addCSSSnippet(std::string const &);
94         ///
95         std::string getCSSSnippets() const;
96         /// Add a feature name requirements
97         void require(std::string const & name);
98         /// Add a set of feature names requirements
99         void require(std::set<std::string> const & names);
100         /// Is the (required) package available?
101         static bool isAvailable(std::string const & name);
102         /// Has the package been required?
103         bool isRequired(std::string const & name) const;
104         /** Is this feature already provided
105          *  e.g. by the document class?
106         */
107         bool isProvided(std::string const & name) const;
108         /** Is it necessary to load the package? This is true if
109             isRequired is true and the feature is not already provided
110         */
111         bool mustProvide(std::string const & name) const;
112         ///
113         void useFloat(std::string const & name, bool subfloat = false);
114         ///
115         void useLanguage(Language const *);
116         ///
117         bool hasLanguages() const;
118         /// check if all used languages are supported by polyglossia
119         bool hasOnlyPolyglossiaLanguages() const;
120         /// check if a language is supported only by polyglossia
121         bool hasPolyglossiaExclusiveLanguages() const;
122         ///
123         std::string getBabelLanguages() const;
124         ///
125         std::map<std::string, std::string> getPolyglossiaLanguages() const;
126         ///
127         std::set<std::string> getEncodingSet(std::string const & doc_encoding) const;
128         ///
129         void useLayout(docstring const & lyt);
130         ///
131         void useInsetLayout(InsetLayout const & lay);
132         ///
133         Buffer const & buffer() const;
134         ///
135         void setBuffer(Buffer const &);
136         ///
137         BufferParams const & bufferParams() const;
138         /** Which language package do we require? \p englishbabel determines
139          *  if we require babel even if English is the only language.
140          */
141         LangPackage langPackage() const;
142         /// Convenience function to test if we use babel
143         bool useBabel() const { return langPackage() == LANG_PACK_BABEL; }
144         /// Convenience function to test if we use polyglossia
145         bool usePolyglossia() const { return langPackage() == LANG_PACK_POLYGLOSSIA; }
146         /// are we in a float?
147         bool inFloat() const { return in_float_; }
148         /// are we in a float?
149         void inFloat(bool const b) { in_float_ = b; }
150         /// Runparams that will be used for exporting this file.
151         OutputParams const & runparams() const { return runparams_; }
152         /// Resolve alternatives like "esint|amsmath|wasysym"
153         void resolveAlternatives();
154         ///
155         void setHTMLTitle(docstring const & t) { htmltitle_ = t; }
156         ///
157         docstring const & htmlTitle() const { return htmltitle_; }
158
159 private:
160         ///
161         std::list<docstring> usedLayouts_;
162         ///
163         std::list<docstring> usedInsetLayouts_;
164         /// The features that are needed by the document
165         typedef std::set<std::string> Features;
166         ///
167         Features features_;
168         /// Static preamble bits, from external templates, or anywhere else
169         typedef std::list<std::string> SnippetList;
170         ///
171         SnippetList preamble_snippets_;
172         ///
173         SnippetList css_snippets_;
174         ///
175         typedef std::set<Language const *> LanguageList;
176         /// used languages (only those that are supported by babel)
177         LanguageList UsedLanguages_;
178         ///
179         typedef std::map<std::string, bool> UsedFloats;
180         ///
181         UsedFloats usedFloats_;
182         ///
183         typedef std::map<docstring, std::string> FileMap;
184         ///
185         FileMap IncludedFiles_;
186         /** Buffer of the file being processed.
187          *  This may be a child buffer of the to-be-exported file and
188          *  therefore may not be the buffer that belongs to params_.
189          *  Only needed by InsetInclude::validate().
190          */
191         Buffer const * buffer_;
192         ///
193         BufferParams const & params_;
194         /** Some insets need to know details about the to-be-produced file
195          *  in validate().
196          */
197         OutputParams const & runparams_;
198         ///
199         bool in_float_;
200         ///
201         docstring htmltitle_;
202 };
203
204
205 } // namespace lyx
206
207 #endif