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 "support/docstring.h"
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).
38 * i.e require("amssymb")
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
49 /// Which Language package do we use?
53 LANG_PACK_POLYGLOSSIA,
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;
79 docstring const getTClassHTMLStyles() const;
81 docstring const getTClassHTMLPreamble() const;
82 /// The sgml definitions needed by the document (docbook)
83 docstring const getLyXSGMLEntities() const;
84 /// The SGML Required to include the files added with includeFile();
85 docstring const getIncludedFiles(std::string const & fname) const;
86 /// Include a file for use with the SGML entities
87 void includeFile(docstring const & key, std::string const & name);
88 /// The float definitions.
89 void getFloatDefinitions(otexstream & os) const;
90 /// Print requirements to lyxerr
91 void showStruct() const;
92 /// Add preamble snippet with TexRow information
93 void addPreambleSnippet(TexString snippet, bool allowdupes = false);
94 /// Add preamble snippet without TexRow information
95 void addPreambleSnippet(docstring const & snippet, bool allowdupes = false);
97 TexString getPreambleSnippets() const;
98 /// Adds CSS information for HTML export.
99 /// Note that addPreambleSnippet is for LaTeX-type export
100 void addCSSSnippet(std::string const &);
102 docstring getCSSSnippets() const;
103 /// Add a feature name requirements
104 void require(std::string const & name);
105 /// Add a set of feature names requirements
106 void require(std::set<std::string> const & names);
107 /// Add a feature name provision
108 void provide(std::string const & name);
109 /// Is the (required) package available?
110 static bool isAvailable(std::string const & name);
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?
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
120 bool mustProvide(std::string const & name) const;
122 void useFloat(std::string const & name, bool subfloat = false);
124 void useLanguage(Language const *);
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;
136 std::string getBabelLanguages() const;
138 std::set<std::string> getPolyglossiaLanguages() const;
140 std::string getActiveChars() const;
142 std::set<std::string> getEncodingSet(std::string const & doc_encoding) const;
144 void getFontEncodings(std::vector<std::string> & encodings,
145 bool const onlylangs = false) const;
147 void useLayout(docstring const & layoutname);
149 void useInsetLayout(InsetLayout const & lay);
151 Buffer const & buffer() const;
153 void setBuffer(Buffer const &);
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.
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();
183 void setHTMLTitle(docstring const & t) { htmltitle_ = t; }
185 docstring const & htmlTitle() const { return htmltitle_; }
187 bool hasRTLLanguage() const;
191 void useLayout(docstring const &, int);
193 std::list<docstring> usedLayouts_;
195 std::list<docstring> usedInsetLayouts_;
197 typedef std::set<std::string> Features;
198 /// The features that are needed by the document
200 /// Features that are provided
202 /// Static preamble bits, from external templates, or anywhere else
203 typedef std::list<TexString> SnippetList;
205 SnippetList preamble_snippets_;
207 SnippetList css_snippets_;
209 typedef std::set<Language const *> LanguageList;
210 /// used languages (only those that are supported by babel)
211 LanguageList UsedLanguages_;
213 typedef std::map<std::string, bool> UsedFloats;
215 UsedFloats usedFloats_;
217 typedef std::map<docstring, std::string> FileMap;
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().
225 Buffer const * buffer_;
227 BufferParams const & params_;
228 /** Some insets need to know details about the to-be-produced file
231 OutputParams const & runparams_;
235 bool in_deleted_inset_;
237 docstring htmltitle_;
239 std::string savenote_env_;