]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
Fix lilypond support, patch from Julien Rioux, bug #6940.
[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 "LayoutModuleList.h"
20 #include "paper.h"
21
22 #include "insets/InsetQuotes.h"
23
24 #include "support/copied_ptr.h"
25
26 #include <map>
27
28 namespace lyx {
29
30 namespace support { class FileName; }
31
32 class AuthorList;
33 class BranchList;
34 class Bullet;
35 class DocumentClass;
36 class Encoding;
37 class Font;
38 class HSpace;
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, a LyXRC variable, and the document class).
83          *  This returned value can then be passed to the insets...
84          */
85         bool writeLaTeX(odocstream &, LaTeXFeatures &, TexRow &,
86                         support::FileName const &) const;
87
88         ///
89         void useClassDefaults();
90         ///
91         bool hasClassDefaults() const;
92
93         ///
94         HSpace const & getIndentation() const;
95         ///
96         void setIndentation(HSpace const & indent);
97         ///
98         VSpace const & getDefSkip() const;
99         ///
100         void setDefSkip(VSpace const & vs);
101
102         /** Whether paragraphs are separated by using a indent like in
103          *  articles or by using a little skip like in letters.
104          */
105         ParagraphSeparation paragraph_separation;
106         ///
107         InsetQuotes::QuoteLanguage quotes_language;
108         ///
109         InsetQuotes::QuoteTimes quotes_times;
110         ///
111         std::string fontsize;
112         /// Get the LayoutFile this document is using.
113         LayoutFile const * baseClass() const;
114         ///
115         LayoutFileIndex const & baseClassID() const;
116         /// Set the LyX layout file this document is using.
117         /// NOTE: This does not call makeDocumentClass() to update the local 
118         /// DocumentClass. That needs to be done manually.
119         /// \param filename the name of the layout file
120         bool setBaseClass(std::string const & classname);
121         /// Adds the module information to the baseClass information to
122         /// create our local DocumentClass.
123         void makeDocumentClass();
124         /// Returns the DocumentClass currently in use: the BaseClass as modified
125         /// by modules.
126         DocumentClass const & documentClass() const;
127         /// \return A pointer to the DocumentClass currently in use: the BaseClass 
128         /// as modified by modules. 
129         DocumentClass const * documentClassPtr() const;
130         /// This bypasses the baseClass and sets the textClass directly.
131         /// Should be called with care and would be better not being here,
132         /// but it seems to be needed by CutAndPaste::putClipboard().
133         void setDocumentClass(DocumentClass const * const);
134         /// List of modules in use
135         LayoutModuleList const & getModules() const { return layoutModules_; }
136         /// List of default modules the user has removed
137         std::list<std::string> const & getRemovedModules() const 
138                         { return removedModules_; }
139         ///
140         /// Add a module to the list of modules in use. This checks only that the
141         /// module is not already in the list, so use moduleIsCompatible first if
142         /// you want to check for compatibility.
143         /// \return true if module was successfully added.
144         bool addLayoutModule(std::string const & modName);
145         /// checks to make sure module's requriements are satisfied, that it does
146         /// not conflict with already-present modules, isn't already loaded, etc.
147         bool moduleCanBeAdded(std::string const & modName) const;
148         ///
149         void addRemovedModule(std::string const & modName) 
150                         { removedModules_.push_back(modName); }
151         /// Clear the list
152         void clearLayoutModules() { layoutModules_.clear(); }
153         /// Clear the removed module list
154         void clearRemovedModules() { removedModules_.clear(); }
155
156         /// List of included children (for includeonly)
157         std::list<std::string> const & getIncludedChildren() const 
158                         { return includedChildren_; }
159         ///
160         void addIncludedChildren(std::string const & child) 
161                         { includedChildren_.push_back(child); }
162         /// Clear the list of included children
163         void clearIncludedChildren() { includedChildren_.clear(); }
164
165         /// update aux files of unincluded children (with \includeonly)
166         bool maintain_unincluded_children;
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         ///
289         bool isbackgroundcolor;
290         ///
291         RGBColor fontcolor;
292         ///
293         bool isfontcolor;
294         ///
295         RGBColor notefontcolor;
296         ///
297         RGBColor boxbgcolor;
298         /// \param index should lie in the range 0 <= \c index <= 3.
299         Bullet & temp_bullet(size_type index);
300         Bullet const & temp_bullet(size_type index) const;
301         /// \param index should lie in the range 0 <= \c index <= 3.
302         Bullet & user_defined_bullet(size_type index);
303         Bullet const & user_defined_bullet(size_type index) const;
304
305         /// Whether to load a package such as amsmath or esint.
306         /// The enum values must not be changed (file format!)
307         enum Package {
308                 /// Don't load the package. For experts only.
309                 package_off = 0,
310                 /// Load the package if needed (recommended)
311                 package_auto = 1,
312                 /// Always load the package (e.g. if the document contains
313                 /// some ERT that needs the package)
314                 package_on = 2
315         };
316         /// Whether and how to load amsmath
317         Package use_amsmath;
318         /// Whether and how to load esint
319         Package use_esint;
320         /// Whether and how to load mhchem
321         Package use_mhchem;
322         /// Whether and how to load mathdots
323         Package use_mathdots;
324         /// Split bibliography?
325         bool use_bibtopic;
326         /// Split the index?
327         bool use_indices;
328         /// revision tracking for this buffer ?
329         bool trackChanges;
330         /** This param decides whether change tracking marks should be used
331          *  in output (irrespective of how these marks are actually defined;
332          *  for instance, they may differ for DVI and PDF generation)
333          */
334         bool outputChanges;
335         ///
336         bool compressed;
337
338         /// the author list for the document
339         AuthorList & authors();
340         AuthorList const & authors() const;
341
342         /// map of the file's author IDs to AuthorList indexes
343         std::map<unsigned int, int> author_map;
344         /// the buffer's font encoding
345         std::string const font_encoding() const;
346         ///
347         std::string const dvips_options() const;
348         /** The return value of paperSizeName() depends on the
349          *  purpose for which the paper size is needed, since they
350          *  support different subsets of paper sizes.
351         */
352         enum PapersizePurpose {
353                 ///
354                 DVIPS,
355                 ///
356                 DVIPDFM,
357                 ///
358                 XDVI
359         };
360         ///
361         std::string paperSizeName(PapersizePurpose purpose) const;
362         /// set up if and how babel is called
363         std::string babelCall(std::string const & lang_opts) const;
364         /// return supported drivers for specific packages
365         docstring getGraphicsDriver(std::string const & package) const;
366         /// handle inputenc etc.
367         void writeEncodingPreamble(odocstream & os, LaTeXFeatures & features,
368                                               TexRow & texrow) const;
369         ///
370         std::string const parseFontName(std::string const & name) const;
371         /// set up the document fonts
372         std::string const loadFonts(std::string const & rm,
373                                      std::string const & sf, std::string const & tt,
374                                      bool const & sc, bool const & osf,
375                                      int const & sfscale, int const & ttscale,
376                                      bool const & xetex) const;
377
378         /// get the appropriate cite engine (natbib handling)
379         CiteEngine citeEngine() const;
380         ///
381         void setCiteEngine(CiteEngine const);
382
383         /// options for pdf output
384         PDFOptions & pdfoptions();
385         PDFOptions const & pdfoptions() const;
386
387         enum MathOutput {
388                 MathML,
389                 HTML,
390                 Images,
391                 LaTeX
392         };
393         /// what to use for math output. present choices are above
394         MathOutput html_math_output;
395         /// whether to attempt to be XHTML 1.1 compliant or instead be
396         /// a little more mellow
397         bool html_be_strict;
398         ///
399         double html_math_img_scale;
400         ///
401         std::string html_latex_start;
402         ///
403         std::string html_latex_end;
404         /// generate output usable for reverse/forward search
405         bool output_sync;
406         /// custom LaTeX macro from user instead our own
407         std::string output_sync_macro;
408         /// use refstyle? or prettyref?
409         bool use_refstyle;
410
411 private:
412         ///
413         void readPreamble(Lexer &);
414         ///
415         void readLocalLayout(Lexer &);
416         ///
417         void readLanguage(Lexer &);
418         ///
419         void readGraphicsDriver(Lexer &);
420         ///
421         void readBullets(Lexer &);
422         ///
423         void readBulletsLaTeX(Lexer &);
424         ///
425         void readModules(Lexer &);
426         ///
427         void readRemovedModules(Lexer &);
428         ///
429         void readIncludeonly(Lexer &);
430         /// for use with natbib
431         CiteEngine cite_engine_;
432         ///
433         DocumentClass * doc_class_;
434         /// 
435         LayoutModuleList layoutModules_;
436         /// this is for modules that are required by the document class but that
437         /// the user has chosen not to use
438         std::list<std::string> removedModules_;
439
440         /// the list of included children (for includeonly)
441         std::list<std::string> includedChildren_;
442
443         /** Use the Pimpl idiom to hide those member variables that would otherwise
444          *  drag in other header files.
445          */
446         class Impl;
447         class MemoryTraits {
448         public:
449                 static Impl * clone(Impl const *);
450                 static void destroy(Impl *);
451         };
452         support::copied_ptr<Impl, MemoryTraits> pimpl_;
453
454 };
455
456 } // namespace lyx
457
458 #endif