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"
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).
36 * i.e require("amssymb")
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
47 /// Which Language package do we use?
51 LANG_PACK_POLYGLOSSIA,
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,
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;
99 void addCSSSnippet(std::string const &);
101 docstring getCSSSnippets() const;
102 /// Add a feature name requirements
103 void require(std::string const & name);
104 /// Add a set of feature names requirements
105 void require(std::set<std::string> const & names);
106 /// Add a feature name provision
107 void provide(std::string const & name);
108 /// Is the (required) package available?
109 static bool isAvailable(std::string const & name);
110 /// Has the package been required?
111 bool isRequired(std::string const & name) const;
112 /** Is this feature already provided
113 * e.g. by the document class?
115 bool isProvided(std::string const & name) const;
116 /** Is it necessary to load the package? This is true if
117 isRequired is true and the feature is not already provided
119 bool mustProvide(std::string const & name) const;
121 void useFloat(std::string const & name, bool subfloat = false);
123 void useLanguage(Language const *);
125 bool hasLanguages() const;
126 /// check if all used languages are supported by polyglossia
127 bool hasOnlyPolyglossiaLanguages() const;
128 /// check if a language is supported only by polyglossia
129 bool hasPolyglossiaExclusiveLanguages() const;
130 /// A vector of all used languages supported only by polyglossia
131 std::vector<std::string> getPolyglossiaExclusiveLanguages() const;
132 /// A vector of all used languages supported only by babel
133 std::vector<std::string> getBabelExclusiveLanguages() const;
135 std::string getBabelLanguages() const;
137 std::set<std::string> getPolyglossiaLanguages() const;
139 std::set<std::string> getEncodingSet(std::string const & doc_encoding) const;
141 void getFontEncodings(std::vector<std::string> & encodings,
142 bool const onlylangs = false) const;
144 void useLayout(docstring const & lyt);
146 void useInsetLayout(InsetLayout const & lay);
148 Buffer const & buffer() const;
150 void setBuffer(Buffer const &);
152 BufferParams const & bufferParams() const;
153 /** Which language package do we require? \p englishbabel determines
154 * if we require babel even if English is the only language.
156 LangPackage langPackage() const;
157 /// Convenience function to test if we use babel
158 bool useBabel() const { return langPackage() == LANG_PACK_BABEL; }
159 /// Convenience function to test if we use polyglossia
160 bool usePolyglossia() const { return langPackage() == LANG_PACK_POLYGLOSSIA; }
161 /// are we in a float?
162 bool inFloat() const { return in_float_; }
163 /// are we in a float?
164 void inFloat(bool const b) { in_float_ = b; }
165 /// are we in a deleted inset?
166 bool inDeletedInset() const { return in_deleted_inset_; }
167 /// are we in a deleted inset?
168 void inDeletedInset(bool const b) { in_deleted_inset_ = b; }
169 /// set savenote environment (footnote package)
170 std::string saveNoteEnv() const { return savenote_env_; }
171 /// return savenote environment
172 void saveNoteEnv(std::string const s) { savenote_env_ = s; }
173 /// Runparams that will be used for exporting this file.
174 OutputParams const & runparams() const { return runparams_; }
175 /// Resolve alternatives like "esint|amsmath|wasysym"
176 void resolveAlternatives();
177 /// Expand multiple requirements like "textcomp,lyxmathsym,amstext"
178 void expandMultiples();
180 void setHTMLTitle(docstring const & t) { htmltitle_ = t; }
182 docstring const & htmlTitle() const { return htmltitle_; }
186 void useLayout(docstring const &, int);
188 std::list<docstring> usedLayouts_;
190 std::list<docstring> usedInsetLayouts_;
192 typedef std::set<std::string> Features;
193 /// The features that are needed by the document
195 /// Features that are provided
197 /// Static preamble bits, from external templates, or anywhere else
198 typedef std::list<TexString> SnippetList;
200 SnippetList preamble_snippets_;
202 SnippetList css_snippets_;
204 typedef std::set<Language const *> LanguageList;
205 /// used languages (only those that are supported by babel)
206 LanguageList UsedLanguages_;
208 typedef std::map<std::string, bool> UsedFloats;
210 UsedFloats usedFloats_;
212 typedef std::map<docstring, std::string> FileMap;
214 FileMap IncludedFiles_;
215 /** Buffer of the file being processed.
216 * This may be a child buffer of the to-be-exported file and
217 * therefore may not be the buffer that belongs to params_.
218 * Only needed by InsetInclude::validate().
220 Buffer const * buffer_;
222 BufferParams const & params_;
223 /** Some insets need to know details about the to-be-produced file
226 OutputParams const & runparams_;
230 bool in_deleted_inset_;
232 docstring htmltitle_;
234 std::string savenote_env_;