3 * \file LaTeXFeatures.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
10 * Full author contact details are available in file CREDITS.
13 #ifndef LATEXFEATURES_H
14 #define LATEXFEATURES_H
16 #include "OutputParams.h"
17 #include "support/docstring.h"
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).
35 * i.e require("amssymb")
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
46 /// Which Language package do we use?
50 LANG_PACK_POLYGLOSSIA,
54 LaTeXFeatures(Buffer const &, BufferParams const &,
55 OutputParams const &);
56 /// The color packages
57 std::string const getColorOptions() const;
58 /// The requested package options
59 std::string const getPackageOptions() const;
60 /// The packages needed by the document
61 std::string const getPackages() const;
62 /// The macros definitions needed by the document
63 docstring const getMacros() const;
64 /// Extra preamble code before babel is called
65 std::string const getBabelPresettings() const;
66 /// Extra preamble code after babel is called
67 std::string const getBabelPostsettings() const;
68 /// Do we need to pass the languages to babel directly?
69 bool needBabelLangOptions() const;
70 /// Load AMS packages when appropriate
71 std::string const loadAMSPackages() const;
72 /// The definitions needed by the document's textclass
73 docstring const getTClassPreamble() const;
74 /// The language dependent definitions needed by the document's textclass
75 docstring const getTClassI18nPreamble(bool use_babel, bool use_polyglossia) const;
77 docstring const getTClassHTMLStyles() const;
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(odocstream & os) const;
88 /// Print requirements to lyxerr
89 void showStruct() const;
91 void addPreambleSnippet(std::string const & snippet,
92 bool allowdupes = false);
94 std::string getPreambleSnippets() const;
96 void addCSSSnippet(std::string const &);
98 std::string 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 /// Is the (required) package available?
104 static bool isAvailable(std::string const & name);
105 /// Has the package been required?
106 bool isRequired(std::string const & name) const;
107 /** Is this feature already provided
108 * e.g. by the document class?
110 bool isProvided(std::string const & name) const;
111 /** Is it necessary to load the package? This is true if
112 isRequired is true and the feature is not already provided
114 bool mustProvide(std::string const & name) const;
116 void useFloat(std::string const & name, bool subfloat = false);
118 void useLanguage(Language const *);
120 bool hasLanguages() const;
121 /// check if all used languages are supported by polyglossia
122 bool hasOnlyPolyglossiaLanguages() const;
123 /// check if a language is supported only by polyglossia
124 bool hasPolyglossiaExclusiveLanguages() const;
125 /// A vector of all used languages supported only by polyglossia
126 std::vector<std::string> getPolyglossiaExclusiveLanguages() const;
127 /// A vector of all used languages supported only by babel
128 std::vector<std::string> getBabelExclusiveLanguages() const;
130 std::string getBabelLanguages() const;
132 std::set<std::string> getPolyglossiaLanguages() const;
134 std::set<std::string> getEncodingSet(std::string const & doc_encoding) const;
136 void getFontEncodings(std::vector<std::string> & encodings) const;
138 void useLayout(docstring const & lyt);
140 void useInsetLayout(InsetLayout const & lay);
142 Buffer const & buffer() const;
144 void setBuffer(Buffer const &);
146 BufferParams const & bufferParams() const;
147 /** Which language package do we require? \p englishbabel determines
148 * if we require babel even if English is the only language.
150 LangPackage langPackage() const;
151 /// Convenience function to test if we use babel
152 bool useBabel() const { return langPackage() == LANG_PACK_BABEL; }
153 /// Convenience function to test if we use polyglossia
154 bool usePolyglossia() const { return langPackage() == LANG_PACK_POLYGLOSSIA; }
155 /// are we in a float?
156 bool inFloat() const { return in_float_; }
157 /// are we in a float?
158 void inFloat(bool const b) { in_float_ = b; }
159 /// Runparams that will be used for exporting this file.
160 OutputParams const & runparams() const { return runparams_; }
161 /// Resolve alternatives like "esint|amsmath|wasysym"
162 void resolveAlternatives();
164 void setHTMLTitle(docstring const & t) { htmltitle_ = t; }
166 docstring const & htmlTitle() const { return htmltitle_; }
170 void useLayout(docstring const &, int);
172 std::list<docstring> usedLayouts_;
174 std::list<docstring> usedInsetLayouts_;
175 /// The features that are needed by the document
176 typedef std::set<std::string> Features;
179 /// Static preamble bits, from external templates, or anywhere else
180 typedef std::list<std::string> SnippetList;
182 SnippetList preamble_snippets_;
184 SnippetList css_snippets_;
186 typedef std::set<Language const *> LanguageList;
187 /// used languages (only those that are supported by babel)
188 LanguageList UsedLanguages_;
190 typedef std::map<std::string, bool> UsedFloats;
192 UsedFloats usedFloats_;
194 typedef std::map<docstring, std::string> FileMap;
196 FileMap IncludedFiles_;
197 /** Buffer of the file being processed.
198 * This may be a child buffer of the to-be-exported file and
199 * therefore may not be the buffer that belongs to params_.
200 * Only needed by InsetInclude::validate().
202 Buffer const * buffer_;
204 BufferParams const & params_;
205 /** Some insets need to know details about the to-be-produced file
208 OutputParams const & runparams_;
212 docstring htmltitle_;