]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
bacda570b37b4a8880fbb873bea9e05430a64041
[lyx.git] / src / BufferParams.h
1 // -*- C++ -*-
2 /**
3  * \file BufferParams.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  * \author John Levon
10  * \author André Pönitz
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef BUFFERPARAMS_H
16 #define BUFFERPARAMS_H
17
18 #include "Citation.h"
19 #include "Font.h"
20 #include "LayoutModuleList.h"
21 #include "paper.h"
22
23 #include "insets/InsetQuotes.h"
24
25 #include "support/copied_ptr.h"
26 #include "support/FileName.h"
27
28 #include <list>
29 #include <map>
30 #include <vector>
31
32 namespace lyx {
33
34 namespace support { class FileName; }
35
36 class AuthorList;
37 class BranchList;
38 class Bullet;
39 class DocumentClass;
40 class Encoding;
41 class HSpace;
42 class IndicesList;
43 class Language;
44 class LatexFeatures;
45 class LayoutFile;
46 class LayoutFileIndex;
47 class Lexer;
48 class PDFOptions;
49 class Spacing;
50 class TexRow;
51 class VSpace;
52
53 /** Buffer parameters.
54  *  This class contains all the parameters for this buffer's use. Some
55  *  work needs to be done on this class to make it nice. Now everything
56  *  is in public.
57  */
58 class BufferParams {
59 public:
60         ///
61         enum ParagraphSeparation {
62                 ///
63                 ParagraphIndentSeparation,
64                 ///
65                 ParagraphSkipSeparation
66         };
67         ///
68         BufferParams();
69
70         /// get l10n translated to the buffers language
71         docstring B_(std::string const & l10n) const;
72
73         /// read a header token, if unrecognised, return it or an unknown class name
74         std::string readToken(Lexer & lex,
75                 std::string const & token, ///< token to read.
76                 support::FileName const & filepath);
77
78         ///
79         void writeFile(std::ostream &) const;
80
81         /// check what features are implied by the buffer parameters.
82         void validate(LaTeXFeatures &) const;
83
84         /** \returns true if the babel package is used (interogates
85          *  the BufferParams and a LyXRC variable).
86          *  This returned value can then be passed to the insets...
87          */
88         bool writeLaTeX(odocstream &, LaTeXFeatures &, TexRow &,
89                         support::FileName const &) const;
90
91         ///
92         void useClassDefaults();
93         ///
94         bool hasClassDefaults() const;
95
96         ///
97         HSpace const & getIndentation() const;
98         ///
99         void setIndentation(HSpace const & indent);
100         ///
101         VSpace const & getDefSkip() const;
102         ///
103         void setDefSkip(VSpace const & vs);
104
105         /** Whether paragraphs are separated by using a indent like in
106          *  articles or by using a little skip like in letters.
107          */
108         ParagraphSeparation paragraph_separation;
109         ///
110         InsetQuotes::QuoteLanguage quotes_language;
111         ///
112         InsetQuotes::QuoteTimes quotes_times;
113         ///
114         std::string fontsize;
115         ///Get the LayoutFile this document is using.
116         LayoutFile const * baseClass() const;
117         ///
118         LayoutFileIndex const & baseClassID() const;
119         /// Set the LyX layout file this document is using.
120         /// NOTE: This does not call makeDocumentClass() to update the local 
121         /// DocumentClass. That needs to be done manually.
122         /// \param filename the name of the layout file
123         bool setBaseClass(std::string const & classname);
124         /// Adds the module information to the baseClass information to
125         /// create our local DocumentClass.
126         void makeDocumentClass();
127         /// Returns the DocumentClass currently in use: the BaseClass as modified
128         /// by modules.
129         DocumentClass const & documentClass() const;
130         /// \return A pointer to the DocumentClass currently in use: the BaseClass 
131         /// as modified by modules. 
132         DocumentClass const * documentClassPtr() const;
133         /// This bypasses the baseClass and sets the textClass directly.
134         /// Should be called with care and would be better not being here,
135         /// but it seems to be needed by CutAndPaste::putClipboard().
136         void setDocumentClass(DocumentClass const * const);
137         /// List of modules in use
138         LayoutModuleList const & getModules() const { return layoutModules_; }
139         /// List of default modules the user has removed
140         std::list<std::string> const & getRemovedModules() const 
141                         { return removedModules_; }
142         ///
143         /// Add a module to the list of modules in use. This checks only that the
144         /// module is not already in the list, so use moduleIsCompatible first if
145         /// you want to check for compatibility.
146         /// \return true if module was successfully added.
147         bool addLayoutModule(std::string const & modName);
148         /// checks to make sure module's requriements are satisfied, that it does
149         /// not conflict with already-present modules, isn't already loaded, etc.
150         bool moduleCanBeAdded(std::string const & modName) const;
151         ///
152         void addRemovedModule(std::string const & modName) 
153                         { removedModules_.push_back(modName); }
154         /// Clear the list
155         void clearLayoutModules() { layoutModules_.clear(); }
156         /// Clear the removed module list
157         void clearRemovedModules() { removedModules_.clear(); }
158
159         /// List of included children (for includeonly)
160         std::list<std::string> const & getIncludedChildren() const 
161                         { return includedChildren_; }
162         ///
163         void addIncludedChildren(std::string const & child) 
164                         { includedChildren_.push_back(child); }
165         /// Clear the list of included children
166         void clearIncludedChildren() { includedChildren_.clear(); }
167
168         /// returns the main font for the buffer (document)
169         Font const getFont() const;
170
171         /* these are for the PaperLayout */
172         /// the papersize
173         PAPER_SIZE papersize;
174         ///
175         PAPER_ORIENTATION orientation;
176         /// use custom margins
177         bool use_geometry;
178         ///
179         std::string paperwidth;
180         ///
181         std::string paperheight;
182         ///
183         std::string leftmargin;
184         ///
185         std::string topmargin;
186         ///
187         std::string rightmargin;
188         ///
189         std::string bottommargin;
190         ///
191         std::string headheight;
192         ///
193         std::string headsep;
194         ///
195         std::string footskip;
196         ///
197         std::string columnsep;
198
199         /* some LaTeX options */
200         /// The graphics driver
201         std::string graphicsDriver;
202         /// The default output format
203         std::string defaultOutputFormat;
204         /// customized bibliography processor
205         std::string bibtex_command;
206         /// customized index processor
207         std::string index_command;
208         /// font encoding
209         std::string fontenc;
210         /// the rm font
211         std::string fontsRoman;
212         /// the sf font
213         std::string fontsSans;
214         /// the tt font
215         std::string fontsTypewriter;
216         /// the default family (rm, sf, tt)
217         std::string fontsDefaultFamily;
218         /// use the XeTeX processor
219         bool useXetex;
220         /// use expert Small Caps
221         bool fontsSC;
222         /// use Old Style Figures
223         bool fontsOSF;
224         /// the scale factor of the sf font
225         int fontsSansScale;
226         /// the scale factor of the tt font
227         int fontsTypewriterScale;
228         /// the font used by the CJK command
229         std::string fontsCJK;
230         ///
231         Spacing & spacing();
232         Spacing const & spacing() const;
233         ///
234         int secnumdepth;
235         ///
236         int tocdepth;
237         ///
238         Language const * language;
239         /// BranchList:
240         BranchList & branchlist();
241         BranchList const & branchlist() const;
242         /// IndicesList:
243         IndicesList & indiceslist();
244         IndicesList const & indiceslist() const;
245         /**
246          * The input encoding for LaTeX. This can be one of
247          * - \c auto: find out the input encoding from the used languages
248          * - \c default: ditto
249          * - any encoding supported by the inputenc package
250          * The encoding of the LyX file is always utf8 and has nothing to
251          * do with this setting.
252          * The difference between \c auto and \c default is that \c auto also
253          * causes loading of the inputenc package, while \c default does not.
254          * \c default will not work unless the user takes additional measures
255          * (such as using special environments like the CJK environment from
256          * CJK.sty).
257          * \c default can be seen as an unspecified 8bit encoding, since LyX
258          * does not interpret it in any way apart from display on screen.
259          */
260         std::string inputenc;
261         /// The main encoding used by this buffer for LaTeX output.
262         /// Individual pieces of text can use different encodings.
263         Encoding const & encoding() const;
264         ///
265         std::string preamble;
266         ///
267         std::string local_layout;
268         ///
269         std::string options;
270         /// use the class options defined in the layout?
271         bool use_default_options;
272         ///
273         std::string master;
274         ///
275         bool suppress_date;
276         ///
277         std::string float_placement;
278         ///
279         unsigned int columns;
280         /// parameters for the listings package
281         std::string listings_params;
282         ///
283         PageSides sides;
284         ///
285         std::string pagestyle;
286         ///
287         RGBColor backgroundcolor;
288         /// \param index should lie in the range 0 <= \c index <= 3.
289         Bullet & temp_bullet(size_type index);
290         Bullet const & temp_bullet(size_type index) const;
291         /// \param index should lie in the range 0 <= \c index <= 3.
292         Bullet & user_defined_bullet(size_type index);
293         Bullet const & user_defined_bullet(size_type index) const;
294
295         /// Whether to load a package such as amsmath or esint.
296         /// The enum values must not be changed (file format!)
297         enum Package {
298                 /// Don't load the package. For experts only.
299                 package_off = 0,
300                 /// Load the package if needed (recommended)
301                 package_auto = 1,
302                 /// Always load the package (e.g. if the document contains
303                 /// some ERT that needs the package)
304                 package_on = 2
305         };
306         /// Whether and how to load amsmath
307         Package use_amsmath;
308         /// Whether and how to load esint
309         Package use_esint;
310         /// Whether and how to load mhchem
311         Package use_mhchem;
312         /// Split bibliography?
313         bool use_bibtopic;
314         /// Split the index?
315         bool use_indices;
316         /// revision tracking for this buffer ?
317         bool trackChanges;
318         /** This param decides whether change tracking marks should be used
319          *  in output (irrespective of how these marks are actually defined;
320          *  for instance, they may differ for DVI and PDF generation)
321          */
322         bool outputChanges;
323         ///
324         bool compressed;
325
326         /// the author list for the document
327         AuthorList & authors();
328         AuthorList const & authors() const;
329
330         /// map of the file's author IDs to AuthorList indexes
331         std::map<unsigned int, int> author_map;
332         /// the buffer's font encoding
333         std::string const font_encoding() const;
334         ///
335         std::string const dvips_options() const;
336         /** The return value of paperSizeName() depends on the
337          *  purpose for which the paper size is needed, since they
338          *  support different subsets of paper sizes.
339         */
340         enum PapersizePurpose {
341                 ///
342                 DVIPS,
343                 ///
344                 DVIPDFM,
345                 ///
346                 XDVI
347         };
348         ///
349         std::string paperSizeName(PapersizePurpose purpose) const;
350         /// set up if and how babel is called
351         std::string babelCall(std::string const & lang_opts) const;
352         /// return supported drivers for specific packages
353         docstring getGraphicsDriver(std::string const & package) const;
354         /// handle inputenc etc.
355         void writeEncodingPreamble(odocstream & os, LaTeXFeatures & features,
356                                               TexRow & texrow) const;
357         ///
358         std::string const parseFontName(std::string const & name) const;
359         /// set up the document fonts
360         std::string const loadFonts(std::string const & rm,
361                                      std::string const & sf, std::string const & tt,
362                                      bool const & sc, bool const & osf,
363                                      int const & sfscale, int const & ttscale,
364                                      bool const & xetex) const;
365
366         /// get the appropriate cite engine (natbib handling)
367         CiteEngine citeEngine() const;
368         ///
369         void setCiteEngine(CiteEngine const);
370
371         /// options for pdf output
372         PDFOptions & pdfoptions();
373         PDFOptions const & pdfoptions() const;
374
375         /// whether to use MathML for math output, or instead images
376         bool html_use_mathml;
377         /// whether to attempt to be XHTML 1.1 compliant or instead be
378         /// a little more mellow
379         bool html_be_strict;
380
381 private:
382         ///
383         void readPreamble(Lexer &);
384         ///
385         void readLocalLayout(Lexer &);
386         ///
387         void readLanguage(Lexer &);
388         ///
389         void readGraphicsDriver(Lexer &);
390         ///
391         void readBullets(Lexer &);
392         ///
393         void readBulletsLaTeX(Lexer &);
394         ///
395         void readModules(Lexer &);
396         ///
397         void readRemovedModules(Lexer &);
398         ///
399         void readIncludeonly(Lexer &);
400         /// for use with natbib
401         CiteEngine cite_engine_;
402         ///
403         DocumentClass * doc_class_;
404         /// 
405         LayoutModuleList layoutModules_;
406         /// this is for modules that are required by the document class but that
407         /// the user has chosen not to use
408         std::list<std::string> removedModules_;
409
410         /// the list of included children (for includeonly)
411         std::list<std::string> includedChildren_;
412
413         /** Use the Pimpl idiom to hide those member variables that would otherwise
414          *  drag in other header files.
415          */
416         class Impl;
417         class MemoryTraits {
418         public:
419                 static Impl * clone(Impl const *);
420                 static void destroy(Impl *);
421         };
422         support::copied_ptr<Impl, MemoryTraits> pimpl_;
423
424 };
425
426 } // namespace lyx
427
428 #endif