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