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,
77 				bool use_polyglossia, bool use_minted) const;
78 	///
79 	docstring const getTClassHTMLStyles() const;
80 	///
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);
96 	///
97 	TexString getPreambleSnippets() const;
98 	///
99 	void addCSSSnippet(std::string const &);
100 	///
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 	/// Is the (required) package available?
107 	static bool isAvailable(std::string const & name);
108 	/// Has the package been required?
109 	bool isRequired(std::string const & name) const;
110 	/** Is this feature already provided
111 	 *  e.g. by the document class?
112 	*/
113 	bool isProvided(std::string const & name) const;
114 	/** Is it necessary to load the package? This is true if
115 	    isRequired is true and the feature is not already provided
116 	*/
117 	bool mustProvide(std::string const & name) const;
118 	///
119 	void useFloat(std::string const & name, bool subfloat = false);
120 	///
121 	void useLanguage(Language const *);
122 	///
123 	bool hasLanguages() const;
124 	/// check if all used languages are supported by polyglossia
125 	bool hasOnlyPolyglossiaLanguages() const;
126 	/// check if a language is supported only by polyglossia
127 	bool hasPolyglossiaExclusiveLanguages() const;
128 	/// A vector of all used languages supported only by polyglossia
129 	std::vector<std::string> getPolyglossiaExclusiveLanguages() const;
130 	/// A vector of all used languages supported only by babel
131 	std::vector<std::string> getBabelExclusiveLanguages() const;
132 	///
133 	std::string getBabelLanguages() const;
134 	///
135 	std::set<std::string> getPolyglossiaLanguages() const;
136 	///
137 	std::set<std::string> getEncodingSet(std::string const & doc_encoding) const;
138 	///
139 	void getFontEncodings(std::vector<std::string> & encodings) const;
140 	///
141 	void useLayout(docstring const & lyt);
142 	///
143 	void useInsetLayout(InsetLayout const & lay);
144 	///
145 	Buffer const & buffer() const;
146 	///
147 	void setBuffer(Buffer const &);
148 	///
149 	BufferParams const & bufferParams() const;
150 	/** Which language package do we require? \p englishbabel determines
151 	 *  if we require babel even if English is the only language.
152 	 */
153 	LangPackage langPackage() const;
154 	/// Convenience function to test if we use babel
useBabel()155 	bool useBabel() const { return langPackage() == LANG_PACK_BABEL; }
156 	/// Convenience function to test if we use polyglossia
usePolyglossia()157 	bool usePolyglossia() const { return langPackage() == LANG_PACK_POLYGLOSSIA; }
158 	/// are we in a float?
inFloat()159 	bool inFloat() const { return in_float_; }
160 	/// are we in a float?
inFloat(bool const b)161 	void inFloat(bool const b) { in_float_ = b; }
162 	/// are we in a deleted inset?
inDeletedInset()163 	bool inDeletedInset() const { return in_deleted_inset_; }
164 	/// are we in a deleted inset?
inDeletedInset(bool const b)165 	void inDeletedInset(bool const b) { in_deleted_inset_ = b; }
166 	/// set savenote environment (footnote package)
saveNoteEnv()167 	std::string saveNoteEnv() const { return savenote_env_; }
168 	/// return savenote environment
saveNoteEnv(std::string const s)169 	void saveNoteEnv(std::string const s) { savenote_env_ = s; }
170 	/// Runparams that will be used for exporting this file.
runparams()171 	OutputParams const & runparams() const { return runparams_; }
172 	/// Resolve alternatives like "esint|amsmath|wasysym"
173 	void resolveAlternatives();
174 	/// Expand multiple requirements like "textcomp,lyxmathsym,amstext"
175 	void expandMultiples();
176 	///
setHTMLTitle(docstring const & t)177 	void setHTMLTitle(docstring const & t) { htmltitle_ = t; }
178 	///
htmlTitle()179 	docstring const & htmlTitle() const { return htmltitle_; }
180 	///
181 	bool hasRTLLanguage() const;
182 
183 private:
184 	///
185 	void useLayout(docstring const &, int);
186 	///
187 	std::list<docstring> usedLayouts_;
188 	///
189 	std::list<docstring> usedInsetLayouts_;
190 	/// The features that are needed by the document
191 	typedef std::set<std::string> Features;
192 	///
193 	Features features_;
194 	/// Static preamble bits, from external templates, or anywhere else
195 	typedef std::list<TexString> SnippetList;
196 	///
197 	SnippetList preamble_snippets_;
198 	///
199 	SnippetList css_snippets_;
200 	///
201 	typedef std::set<Language const *> LanguageList;
202 	/// used languages (only those that are supported by babel)
203 	LanguageList UsedLanguages_;
204 	///
205 	typedef std::map<std::string, bool> UsedFloats;
206 	///
207 	UsedFloats usedFloats_;
208 	///
209 	typedef std::map<docstring, std::string> FileMap;
210 	///
211 	FileMap IncludedFiles_;
212 	/** Buffer of the file being processed.
213 	 *  This may be a child buffer of the to-be-exported file and
214 	 *  therefore may not be the buffer that belongs to params_.
215 	 *  Only needed by InsetInclude::validate().
216 	 */
217 	Buffer const * buffer_;
218 	///
219 	BufferParams const & params_;
220 	/** Some insets need to know details about the to-be-produced file
221 	 *  in validate().
222 	 */
223 	OutputParams const & runparams_;
224 	///
225 	bool in_float_;
226 	///
227 	bool in_deleted_inset_;
228 	///
229 	docstring htmltitle_;
230 	///
231 	std::string savenote_env_;
232 };
233 
234 
235 } // namespace lyx
236 
237 #endif
238