]> git.lyx.org Git - features.git/blob - src/BufferParams.h
7280506a09c09cf2f8a9c2815389bd7da7b8ade6
[features.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 "Format.h"
20 #include "LayoutModuleList.h"
21 #include "OutputParams.h"
22 #include "paper.h"
23
24 #include "insets/InsetQuotes.h"
25
26 #include "support/copied_ptr.h"
27
28 #include <map>
29 #include <vector>
30
31 namespace lyx {
32
33 namespace support { class FileName; }
34
35 class AuthorList;
36 class BranchList;
37 class Bullet;
38 class DocumentClass;
39 class Encoding;
40 class Font;
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, a LyXRC variable, and the document class).
86          *  This returned value can then be passed to the insets...
87          */
88         bool writeLaTeX(otexstream &, LaTeXFeatures &,
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 layout_modules_; }
139         /// List of default modules the user has removed
140         std::list<std::string> const & getRemovedModules() const
141                         { return removed_modules_; }
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                         { removed_modules_.push_back(modName); }
154         /// Clear the list
155         void clearLayoutModules() { layout_modules_.clear(); }
156         /// Clear the removed module list
157         void clearRemovedModules() { removed_modules_.clear(); }
158
159         /// returns \c true if the buffer contains a LaTeX document
160         bool isLatex() const;
161         /// returns \c true if the buffer contains a DocBook document
162         bool isDocBook() const;
163         /// returns \c true if the buffer contains a Wed document
164         bool isLiterate() const;
165
166         /// return the format of the buffer on a string
167         std::string bufferFormat() const;
168         /// return the default output format of the current backend
169         std::string getDefaultOutputFormat() const;
170         /// return the output flavor of \p format or the default
171         OutputParams::FLAVOR getOutputFlavor(
172                   std::string const format = std::string()) const;
173         ///
174         bool isExportable(std::string const & format) const;
175         ///
176         std::vector<Format const *> exportableFormats(bool only_viewable) const;
177         ///
178         bool isExportableFormat(std::string const & format) const;
179         ///
180         std::vector<std::string> backends() const;
181
182         /// List of included children (for includeonly)
183         std::list<std::string> const & getIncludedChildren() const
184                         { return included_children_; }
185         ///
186         void addIncludedChildren(std::string const & child)
187                         { included_children_.push_back(child); }
188         /// Clear the list of included children
189         void clearIncludedChildren() { included_children_.clear(); }
190
191         /// update aux files of unincluded children (with \includeonly)
192         bool maintain_unincluded_children;
193
194         /// returns the main font for the buffer (document)
195         Font const getFont() const;
196
197         /* these are for the PaperLayout */
198         /// the papersize
199         PAPER_SIZE papersize;
200         ///
201         PAPER_ORIENTATION orientation;
202         /// use custom margins
203         bool use_geometry;
204         ///
205         std::string paperwidth;
206         ///
207         std::string paperheight;
208         ///
209         std::string leftmargin;
210         ///
211         std::string topmargin;
212         ///
213         std::string rightmargin;
214         ///
215         std::string bottommargin;
216         ///
217         std::string headheight;
218         ///
219         std::string headsep;
220         ///
221         std::string footskip;
222         ///
223         std::string columnsep;
224
225         /* some LaTeX options */
226         /// The graphics driver
227         std::string graphics_driver;
228         /// The default output format
229         std::string default_output_format;
230         /// customized bibliography processor
231         std::string bibtex_command;
232         /// customized index processor
233         std::string index_command;
234         /// font encoding
235         std::string fontenc;
236         /// the rm font
237         std::string fonts_roman;
238         /// the sf font
239         std::string fonts_sans;
240         /// the tt font
241         std::string fonts_typewriter;
242         /// the default family (rm, sf, tt)
243         std::string fonts_default_family;
244         /// use the fonts of the OS (OpenType, True Type) directly
245         bool useNonTeXFonts;
246         /// use expert Small Caps
247         bool fonts_expert_sc;
248         /// use Old Style Figures
249         bool fonts_old_figures;
250         /// the scale factor of the sf font
251         int fonts_sans_scale;
252         /// the scale factor of the tt font
253         int fonts_typewriter_scale;
254         /// the font used by the CJK command
255         std::string fonts_cjk;
256         ///
257         Spacing & spacing();
258         Spacing const & spacing() const;
259         ///
260         int secnumdepth;
261         ///
262         int tocdepth;
263         ///
264         Language const * language;
265         /// language package
266         std::string lang_package;
267         /// BranchList:
268         BranchList & branchlist();
269         BranchList const & branchlist() const;
270         /// IndicesList:
271         IndicesList & indiceslist();
272         IndicesList const & indiceslist() const;
273         /**
274          * The input encoding for LaTeX. This can be one of
275          * - \c auto: find out the input encoding from the used languages
276          * - \c default: ditto
277          * - any encoding supported by the inputenc package
278          * The encoding of the LyX file is always utf8 and has nothing to
279          * do with this setting.
280          * The difference between \c auto and \c default is that \c auto also
281          * causes loading of the inputenc package, while \c default does not.
282          * \c default will not work unless the user takes additional measures
283          * (such as using special environments like the CJK environment from
284          * CJK.sty).
285          * \c default can be seen as an unspecified 8bit encoding, since LyX
286          * does not interpret it in any way apart from display on screen.
287          */
288         std::string inputenc;
289         /// The main encoding used by this buffer for LaTeX output.
290         /// Individual pieces of text can use different encodings.
291         Encoding const & encoding() const;
292         ///
293         std::string preamble;
294         ///
295         std::string local_layout;
296         ///
297         std::string options;
298         /// use the class options defined in the layout?
299         bool use_default_options;
300         ///
301         std::string master;
302         ///
303         bool suppress_date;
304         ///
305         std::string float_placement;
306         ///
307         unsigned int columns;
308         ///
309         bool justification;
310         /// parameters for the listings package
311         std::string listings_params;
312         ///
313         PageSides sides;
314         ///
315         std::string pagestyle;
316         ///
317         RGBColor backgroundcolor;
318         ///
319         bool isbackgroundcolor;
320         ///
321         RGBColor fontcolor;
322         ///
323         bool isfontcolor;
324         ///
325         RGBColor notefontcolor;
326         ///
327         RGBColor boxbgcolor;
328         /// \param index should lie in the range 0 <= \c index <= 3.
329         Bullet & temp_bullet(size_type index);
330         Bullet const & temp_bullet(size_type index) const;
331         /// \param index should lie in the range 0 <= \c index <= 3.
332         Bullet & user_defined_bullet(size_type index);
333         Bullet const & user_defined_bullet(size_type index) const;
334
335         /// Whether to load a package such as amsmath or esint.
336         /// The enum values must not be changed (file format!)
337         enum Package {
338                 /// Don't load the package. For experts only.
339                 package_off = 0,
340                 /// Load the package if needed (recommended)
341                 package_auto = 1,
342                 /// Always load the package (e.g. if the document contains
343                 /// some ERT that needs the package)
344                 package_on = 2
345         };
346         /// Whether to load a package such as amsmath or esint.
347         Package use_package(std::string const & p) const;
348         /// Set whether to load a package such as amsmath or esint.
349         void use_package(std::string const & p, Package u);
350         /// All packages that can be switched on or off
351         static std::vector<std::string> const & auto_packages();
352         /// Split bibliography?
353         bool use_bibtopic;
354         /// Split the index?
355         bool use_indices;
356         /// revision tracking for this buffer ?
357         bool trackChanges;
358         /** This param decides whether change tracking marks should be used
359          *  in output (irrespective of how these marks are actually defined;
360          *  for instance, they may differ for DVI and PDF generation)
361          */
362         bool outputChanges;
363         ///
364         bool compressed;
365
366         /// the author list for the document
367         AuthorList & authors();
368         AuthorList const & authors() const;
369
370         /// map of the file's author IDs to AuthorList indexes
371         typedef std::map<int, int> AuthorMap;
372         AuthorMap author_map;
373         /// the buffer's font encoding
374         std::string const font_encoding() const;
375         ///
376         std::string const dvips_options() const;
377         /** The return value of paperSizeName() depends on the
378          *  purpose for which the paper size is needed, since they
379          *  support different subsets of paper sizes.
380         */
381         enum PapersizePurpose {
382                 ///
383                 DVIPS,
384                 ///
385                 DVIPDFM,
386                 ///
387                 XDVI
388         };
389         ///
390         std::string paperSizeName(PapersizePurpose purpose) const;
391         /// set up if and how babel is called
392         std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
393         /// return supported drivers for specific packages
394         docstring getGraphicsDriver(std::string const & package) const;
395         /// handle inputenc etc.
396         void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
397         ///
398         std::string const parseFontName(std::string const & name) const;
399         /// set up the document fonts
400         std::string const loadFonts(std::string const & rm,
401                                      std::string const & sf, std::string const & tt,
402                                      bool const & sc, bool const & osf,
403                                      int const & sfscale, int const & ttscale,
404                                      bool const & use_nonlatexfonts,
405                                      LaTeXFeatures & features) const;
406
407         /// the cite engine modules
408         LayoutModuleList const & citeEngine() const
409                 { return cite_engine_; }
410         /// the type of cite engine (authoryear or numerical)
411         CiteEngineType const & citeEngineType() const
412                 { return cite_engine_type_; }
413         /// add the module to the cite engine modules
414         bool addCiteEngine(std::string const &);
415         /// add the modules to the cite engine modules
416         bool addCiteEngine(std::vector<std::string> const &);
417         /// clear the list of cite engine modules
418         void clearCiteEngine() { cite_engine_.clear(); }
419         /// set the cite engine module
420         void setCiteEngine(std::string const &);
421         /// set the cite engine modules
422         void setCiteEngine(std::vector<std::string> const &);
423         /// set the cite engine type
424         void setCiteEngineType(CiteEngineType const & engine_type)
425                 { cite_engine_type_ = engine_type; }
426
427         /// the available citation commands
428         std::vector<std::string> citeCommands() const;
429         /// the available citation styles
430         std::vector<CitationStyle> citeStyles() const;
431
432         /// the default BibTeX style file for the document
433         std::string biblio_style;
434         /// the default BibTeX style file from the TextClass
435         std::string const & defaultBiblioStyle() const;
436         /// whether the BibTeX style supports full author lists
437         bool const & fullAuthorList() const;
438
439         /// options for pdf output
440         PDFOptions & pdfoptions();
441         PDFOptions const & pdfoptions() const;
442
443         // do not change these values. we rely upon them.
444         enum MathOutput {
445                 MathML = 0,
446                 HTML = 1,
447                 Images = 2,
448                 LaTeX = 3
449         };
450         /// what to use for math output. present choices are above
451         MathOutput html_math_output;
452         /// whether to attempt to be XHTML 1.1 compliant or instead be
453         /// a little more mellow
454         bool html_be_strict;
455         ///
456         double html_math_img_scale;
457         ///
458         std::string html_latex_start;
459         ///
460         std::string html_latex_end;
461         ///
462         bool html_css_as_file;
463         /// generate output usable for reverse/forward search
464         bool output_sync;
465         /// custom LaTeX macro from user instead our own
466         std::string output_sync_macro;
467         /// use refstyle? or prettyref?
468         bool use_refstyle;
469
470         /// Return true if language could be set to lang,
471         /// otherwise return false and do not change language
472         bool setLanguage(std::string const & lang);
473
474 private:
475         ///
476         void readPreamble(Lexer &);
477         ///
478         void readLocalLayout(Lexer &);
479         ///
480         void readLanguage(Lexer &);
481         ///
482         void readGraphicsDriver(Lexer &);
483         ///
484         void readBullets(Lexer &);
485         ///
486         void readBulletsLaTeX(Lexer &);
487         ///
488         void readModules(Lexer &);
489         ///
490         void readRemovedModules(Lexer &);
491         ///
492         void readIncludeonly(Lexer &);
493         /// A cache for the default flavors
494         typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
495         ///
496         mutable DefaultFlavorCache default_flavors_;
497         /// the cite engine modules
498         LayoutModuleList cite_engine_;
499         /// the type of cite engine (authoryear or numerical)
500         CiteEngineType cite_engine_type_;
501         ///
502         DocumentClass * doc_class_;
503         ///
504         LayoutModuleList layout_modules_;
505         /// this is for modules that are required by the document class but that
506         /// the user has chosen not to use
507         std::list<std::string> removed_modules_;
508
509         /// the list of included children (for includeonly)
510         std::list<std::string> included_children_;
511
512         typedef std::map<std::string, Package> PackageMap;
513         /** Whether and how to load packages like amsmath, esint, mhchem,
514          *  mathdots and undertilde.
515          */
516         PackageMap use_packages;
517
518         /** Use the Pimpl idiom to hide those member variables that would otherwise
519          *  drag in other header files.
520          */
521         class Impl;
522         class MemoryTraits {
523         public:
524                 static Impl * clone(Impl const *);
525                 static void destroy(Impl *);
526         };
527         support::copied_ptr<Impl, MemoryTraits> pimpl_;
528
529 };
530
531 } // namespace lyx
532
533 #endif