]> git.lyx.org Git - lyx.git/blob - src/tex2lyx/Preamble.h
Fix #10778 (issue with CJK and language nesting)
[lyx.git] / src / tex2lyx / Preamble.h
1 /**
2  * \file Preamble.h
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  * \author Uwe Stöhr
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 // {[(
13
14 #ifndef LYX_PREAMBLE_H
15 #define LYX_PREAMBLE_H
16
17 #include "Author.h"
18
19 #include <iosfwd>
20 #include <sstream>
21 #include <string>
22 #include <vector>
23 #include <map>
24 #include <set>
25
26
27 namespace lyx {
28
29 class Parser;
30 class TeX2LyXDocClass;
31
32 class Preamble
33 {
34 public:
35         Preamble();
36
37         ///
38         std::string inputencoding() const { return h_inputencoding; }
39         ///
40         void setInputencoding(std::string const & e) { h_inputencoding = e; }
41         ///
42         std::string notefontcolor() const { return h_notefontcolor; }
43         ///
44         bool refstyle() const { return h_use_refstyle; }
45         ///
46         bool fontCJKSet() const { return h_font_cjk_set; }
47         ///
48         std::string fontCJK() const { return h_font_cjk; }
49         ///
50         void fontCJK(std::string const & f) { h_font_cjk_set = true; h_font_cjk = f; }
51         /// The document language
52         std::string docLanguage() const { return h_language; }
53         /// The language of text which is not explicitly marked
54         std::string defaultLanguage() const  { return default_language; }
55         ///
56         bool usePolyglossia() const;
57         ///
58         std::string use_indices() const { return h_use_indices; }
59         ///
60         std::string polyglossia2lyx(std::string const & language);
61         ///
62         bool indentParagraphs() const;
63         ///
64         bool isPackageUsed(std::string const & package) const;
65         ///
66         std::vector<std::string>
67         getPackageOptions(std::string const & package) const;
68         /// Tell that \p package will be loaded automatically by LyX.
69         /// This has only an effect if \p package is prepared for
70         /// autoloading in parse().
71         void registerAutomaticallyLoadedPackage(std::string const & package);
72         ///
73         void addModule(std::string const & module);
74         ///
75         void suppressDate(bool suppress);
76         ///
77         std::string citeEngine() const { return h_cite_engine; }
78         ///
79         void citeEngine(std::string const & e) { h_cite_engine = e; }
80         ///
81         bool titleLayoutFound() const { return title_layout_found; }
82         ///
83         void titleLayoutFound(bool found) { title_layout_found = found; }
84         /// Register an author named \p name in the author list
85         void registerAuthor(std::string const & name);
86         /// Get author named \p name (must be registered first)
87         Author const & getAuthor(std::string const & name) const;
88         /// Get number of arguments of special table column type \c or -1
89         /// if no column type \p c exists
90         int getSpecialTableColumnArguments(char c) const;
91
92         /// Parses the LaTeX preamble into internal data
93         void parse(Parser & p, std::string const & forceclass,
94                    TeX2LyXDocClass & tc);
95         /// Parse the encoding from a preamble. *this is unusable afterwards.
96         std::string parseEncoding(Parser & p, std::string const & forceclass);
97         /// Writes the LyX file header from internal data
98         bool writeLyXHeader(std::ostream & os, bool subdoc,
99                             std::string const & outfiledir);
100
101         /// known polyglossia language names (including variants)
102         static const char * const polyglossia_languages[];
103         /// the same as polyglossia_languages with .lyx names
104         static const char * const coded_polyglossia_languages[];
105
106 private:
107         ///
108         void parse(Parser & p, std::string const & forceclass,
109                    bool detectEncoding, TeX2LyXDocClass & tc);
110         ///
111         std::map<std::string, std::vector<std::string> > used_packages;
112         /// Packages that will be loaded automatically by LyX
113         std::set<std::string> auto_packages;
114         ///
115         std::vector<std::string> used_modules;
116
117         /// needed to handle encodings with babel
118         bool one_language;
119         /// the main non-CJK language
120         std::string default_language;
121         /// Was babel called explicitly?
122         bool explicit_babel;
123
124         /// was at least one title layout found?
125         bool title_layout_found;
126
127         /// used for the handling of \newindex
128         int index_number;
129
130         std::ostringstream h_preamble;
131         std::string h_backgroundcolor;
132         std::string h_biblio_style;
133         std::string h_bibtex_command;
134         std::string h_boxbgcolor;
135         std::string h_cite_engine;
136         std::string h_cite_engine_type;
137         std::string h_color;
138         std::string h_defskip;
139         std::string h_float_placement;
140         std::string h_fontcolor;
141         std::string h_fontencoding;
142         std::string h_font_math[2];
143         std::string h_font_roman[2];
144         std::string h_font_sans[2];
145         std::string h_font_typewriter[2];
146         std::string h_font_default_family;
147         bool h_use_non_tex_fonts;
148         std::string h_font_sc;
149         std::string h_font_osf;
150         std::string h_font_sf_scale[2];
151         std::string h_font_tt_scale[2];
152         bool h_font_cjk_set;
153         std::string h_font_cjk;
154         std::string h_graphics;
155         std::string h_default_output_format;
156         std::string h_html_be_strict;
157         std::string h_html_css_as_file;
158         std::string h_html_math_output;
159         std::string h_index[99];
160         std::string h_index_command;
161         std::string h_inputencoding;
162         std::string h_justification;
163         std::string h_language;
164         std::string h_language_package;
165         std::string h_listings_params;
166         std::string h_maintain_unincluded_children;
167         std::string h_margins;
168         std::string h_notefontcolor;
169         std::string h_options;
170         std::string h_output_changes;
171         std::string h_output_sync;
172         std::string h_output_sync_macro;
173         std::string h_papercolumns;
174         std::string h_paperfontsize;
175         std::string h_paperorientation;
176         std::string h_paperpagestyle;
177         std::string h_papersides;
178         std::string h_papersize;
179         std::string h_paragraph_indentation;
180         /// necessary to set the separation when \setlength is parsed
181         std::string h_paragraph_separation;
182         std::string h_pdf_title;
183         std::string h_pdf_author;
184         std::string h_pdf_subject;
185         std::string h_pdf_keywords;
186         std::string h_pdf_bookmarks;
187         std::string h_pdf_bookmarksnumbered;
188         std::string h_pdf_bookmarksopen;
189         std::string h_pdf_bookmarksopenlevel;
190         std::string h_pdf_breaklinks;
191         std::string h_pdf_pdfborder;
192         std::string h_pdf_colorlinks;
193         std::string h_pdf_backref;
194         std::string h_pdf_pdfusetitle;
195         std::string h_pdf_pagemode;
196         std::string h_pdf_quoted_options;
197         std::string h_quotes_language;
198         std::string h_secnumdepth;
199         std::string h_shortcut[99];
200         std::string h_spacing;
201         std::string h_suppress_date;
202         std::string h_save_transient_properties;
203         std::string h_textclass;
204         std::string h_tocdepth;
205         std::string h_tracking_changes;
206         std::string h_use_bibtopic;
207         std::string h_use_indices;
208         std::string h_use_geometry;
209         std::map<std::string, std::string> h_use_packages;
210         std::string h_use_default_options;
211         std::string h_use_hyperref;
212         bool h_use_refstyle;
213
214         /*!
215          * Add package \p name with options \p options to used_packages.
216          * Remove options from \p options that we don't want to output.
217          */
218         void add_package(std::string const & name,
219                          std::vector<std::string> & options);
220         ///
221         void handle_hyperref(std::vector<std::string> & options);
222         ///
223         void handle_geometry(std::vector<std::string> & options);
224         ///
225         void handle_package(Parser &p, std::string const & name,
226                             std::string const & opts, bool in_lyx_preamble,
227                             bool detectEncoding);
228         ///
229         void handle_if(Parser & p, bool in_lyx_preamble);
230
231         ///
232         AuthorList authors_;
233         /// special table column types
234         std::map<char, int> special_columns_;
235 };
236
237
238 extern Preamble preamble;
239
240 // }])
241
242
243 } // namespace lyx
244
245 #endif