]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
437d00b700d23cdfc2954b6a7062bc6cc6d36bd9
[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 "Author.h"
19 #include "Citation.h"
20 #include "DocumentClassPtr.h"
21 #include "Format.h"
22 #include "LayoutModuleList.h"
23 #include "OutputParams.h"
24 #include "paper.h"
25
26 #include "insets/InsetQuotes.h"
27
28 #include "support/copied_ptr.h"
29
30 #include <map>
31 #include <vector>
32
33 namespace lyx {
34
35 namespace support { class FileName; }
36
37 class BranchList;
38 class Bullet;
39 class DocumentClass;
40 class Encoding;
41 class Font;
42 class HSpace;
43 class IndicesList;
44 class Language;
45 class LayoutFile;
46 class LayoutFileIndex;
47 class Length;
48 class Lexer;
49 class PDFOptions;
50 class Spacing;
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 &, Buffer const *) 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 (interrogates
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         Length const & getParIndent() const;
98         ///
99         void setParIndent(Length const & indent);
100         ///
101         VSpace const & getDefSkip() const;
102         ///
103         void setDefSkip(VSpace const & vs);
104
105         /// Whether formulas are indented
106         bool is_math_indent;
107
108         /// the indentation of formulas
109         std::string math_indentation;
110
111         /** Whether paragraphs are separated by using a indent like in
112          *  articles or by using a little skip like in letters.
113          */
114         ParagraphSeparation paragraph_separation;
115         ///
116         InsetQuotesParams::QuoteStyle quotes_style;
117         ///
118         bool dynamic_quotes;
119         ///
120         std::string fontsize;
121         /// Get the LayoutFile this document is using.
122         LayoutFile const * baseClass() const;
123         ///
124         LayoutFileIndex const & baseClassID() const;
125         /// Set the LyX layout file this document is using.
126         /// NOTE: This does not call makeDocumentClass() to update the local
127         /// DocumentClass. That needs to be done manually.
128         /// \param classname: the name of the layout file
129         bool setBaseClass(std::string const & classname);
130         /// Adds the module information to the baseClass information to
131         /// create our local DocumentClass.
132         /// NOTE: This should NEVER be called externally unless one immediately goes
133         /// on to class BufferView::updateDocumentClass(). The exception, of course,
134         /// is in GuiDocument, where we use a BufferParams simply to hold a copy of
135         /// the parameters from the active Buffer.
136         void makeDocumentClass(bool const clone = false);
137         /// Returns the DocumentClass currently in use: the BaseClass as modified
138         /// by modules.
139         DocumentClass const & documentClass() const;
140         /// \return A pointer to the DocumentClass currently in use: the BaseClass
141         /// as modified by modules.
142         DocumentClassConstPtr documentClassPtr() const;
143         /// This bypasses the baseClass and sets the textClass directly.
144         /// Should be called with care and would be better not being here,
145         /// but it seems to be needed by CutAndPaste::putClipboard().
146         void setDocumentClass(DocumentClassConstPtr);
147         /// List of modules in use
148         LayoutModuleList const & getModules() const { return layout_modules_; }
149         /// List of default modules the user has removed
150         std::list<std::string> const & getRemovedModules() const
151                         { return removed_modules_; }
152         ///
153         /// Add a module to the list of modules in use. This checks only that the
154         /// module is not already in the list, so use layoutModuleCanBeAdeed first 
155         /// if you want to check for compatibility.
156         /// \return true if module was successfully added.
157         bool addLayoutModule(std::string const & modName);
158         /// checks to make sure module's requriements are satisfied, that it does
159         /// not conflict with already-present modules, isn't already loaded, etc.
160         bool layoutModuleCanBeAdded(std::string const & modName) const;
161         /// same, but for citaton modules.
162         bool citationModuleCanBeAdded(std::string const & modName) const;
163         ///
164         void addRemovedModule(std::string const & modName)
165                         { removed_modules_.push_back(modName); }
166         /// Clear the list
167         void clearLayoutModules() { layout_modules_.clear(); }
168         /// Clear the removed module list
169         void clearRemovedModules() { removed_modules_.clear(); }
170         /// Get the local layouts
171         docstring getLocalLayout(bool forced) const;
172         /// Set the local layouts
173         void setLocalLayout(docstring const & layout, bool forced);
174
175         /// returns \c true if the buffer contains a LaTeX document
176         bool isLatex() const;
177         /// returns \c true if the buffer contains a DocBook document
178         bool isDocBook() const;
179         /// returns \c true if the buffer contains a Wed document
180         bool isLiterate() const;
181
182         /// return the format of the buffer on a string
183         std::string bufferFormat() const;
184         /// return the default output format of the current backend
185         std::string getDefaultOutputFormat() const;
186         /// return the output flavor of \p format or the default
187         OutputParams::FLAVOR getOutputFlavor(
188                   std::string const & format = std::string()) const;
189         ///
190         bool isExportable(std::string const & format, bool need_viewable) const;
191         ///
192         std::vector<const Format *> const & exportableFormats(bool only_viewable) const;
193         /// the backends appropriate for use with this document.
194         /// so, e.g., latex is excluded , if we're using non-TeX fonts
195         std::vector<std::string> backends() const;
196
197         /// List of included children (for includeonly)
198         std::list<std::string> const & getIncludedChildren() const
199                         { return included_children_; }
200         ///
201         void addIncludedChildren(std::string const & child)
202                         { included_children_.push_back(child); }
203         /// Clear the list of included children
204         void clearIncludedChildren() { included_children_.clear(); }
205
206         /// update aux files of unincluded children (with \includeonly)
207         bool maintain_unincluded_children;
208
209         /// returns the main font for the buffer (document)
210         Font const getFont() const;
211
212         /// translate quote style string to enum value
213         InsetQuotesParams::QuoteStyle getQuoteStyle(std::string const & qs) const;
214
215         /* these are for the PaperLayout */
216         /// the papersize
217         PAPER_SIZE papersize;
218         ///
219         PAPER_ORIENTATION orientation;
220         /// use custom margins
221         bool use_geometry;
222         ///
223         std::string paperwidth;
224         ///
225         std::string paperheight;
226         ///
227         std::string leftmargin;
228         ///
229         std::string topmargin;
230         ///
231         std::string rightmargin;
232         ///
233         std::string bottommargin;
234         ///
235         std::string headheight;
236         ///
237         std::string headsep;
238         ///
239         std::string footskip;
240         ///
241         std::string columnsep;
242
243         /* some LaTeX options */
244         /// The graphics driver
245         std::string graphics_driver;
246         /// The default output format
247         std::string default_output_format;
248         /// customized bibliography processor
249         std::string bibtex_command;
250         /// customized index processor
251         std::string index_command;
252         /// font encoding(s) requested for this document
253         std::string fontenc;
254         /// the rm font: [0] for TeX fonts, [1] for non-TeX fonts
255         std::string fonts_roman[2];
256         /// the rm font
257         std::string const & fontsRoman() const { return fonts_roman[useNonTeXFonts]; }
258         /// the sf font: [0] for TeX fonts, [1] for non-TeX fonts
259         std::string fonts_sans[2];
260         /// the sf font
261         std::string const & fontsSans() const { return fonts_sans[useNonTeXFonts]; }
262         /// the tt font: [0] for TeX fonts, [1] for non-TeX fonts
263         std::string fonts_typewriter[2];
264         /// the tt font
265         std::string const & fontsTypewriter() const { return fonts_typewriter[useNonTeXFonts]; }
266         /// the math font: [0] for TeX fonts, [1] for non-TeX fonts
267         std::string fonts_math[2];
268         /// the math font
269         std::string const & fontsMath() const { return fonts_math[useNonTeXFonts]; }
270         /// the default family (rm, sf, tt)
271         std::string fonts_default_family;
272         /// use the fonts of the OS (OpenType, True Type) directly
273         bool useNonTeXFonts;
274         /// use expert Small Caps
275         bool fonts_expert_sc;
276         /// use Old Style Figures
277         bool fonts_old_figures;
278         /// the scale factor of the sf font: [0] for TeX fonts, [1] for non-TeX fonts
279         int fonts_sans_scale[2];
280         /// the scale factor of the sf font
281         int fontsSansScale() const { return fonts_sans_scale[useNonTeXFonts]; }
282         /// the scale factor of the tt font: [0] for TeX fonts, [1] for non-TeX fonts
283         int fonts_typewriter_scale[2];
284         /// the scale factor of the tt font
285         int fontsTypewriterScale() const { return fonts_typewriter_scale[useNonTeXFonts]; }
286         /// the font used by the CJK command
287         std::string fonts_cjk;
288         /// use LaTeX microtype package
289         bool use_microtype;
290         /// use font ligatures for en- and em-dashes
291         bool use_dash_ligatures;
292         ///
293         Spacing & spacing();
294         Spacing const & spacing() const;
295         ///
296         int secnumdepth;
297         ///
298         int tocdepth;
299         ///
300         Language const * language;
301         /// language package
302         std::string lang_package;
303         /// BranchList:
304         BranchList & branchlist();
305         BranchList const & branchlist() const;
306         /// IndicesList:
307         IndicesList & indiceslist();
308         IndicesList const & indiceslist() const;
309         /**
310          * The LyX name of the input encoding for LaTeX. This can be one of
311          * - \c auto: find out the input encoding from the used languages
312          * - \c default: ditto
313          * - any encoding defined in the file lib/encodings
314          * The encoding of the LyX file is always utf8 and has nothing to
315          * do with this setting.
316          * The difference between \c auto and \c default is that \c auto also
317          * causes loading of the inputenc package, while \c default does not.
318          * \c default will not work unless the user takes additional measures
319          * (such as using special environments like the CJK environment from
320          * CJK.sty).
321          * \c default can be seen as an unspecified 8bit encoding, since LyX
322          * does not interpret it in any way apart from display on screen.
323          */
324         std::string inputenc;
325         /// The main encoding used by this buffer for LaTeX output.
326         /// Individual pieces of text can use different encodings.
327         /// Output for XeTeX with 8-bit TeX fonts uses ASCII (set at runtime)
328         /// instead of the value returned by this function.
329         Encoding const & encoding() const;
330         ///
331         std::string origin;
332         ///
333         docstring preamble;
334         ///
335         std::string options;
336         /// use the class options defined in the layout?
337         bool use_default_options;
338         ///
339         std::string master;
340         ///
341         bool suppress_date;
342         ///
343         std::string float_placement;
344         ///
345         unsigned int columns;
346         ///
347         bool justification;
348         /// parameters for the listings package
349         std::string listings_params;
350         ///
351         PageSides sides;
352         ///
353         std::string pagestyle;
354         ///
355         RGBColor backgroundcolor;
356         ///
357         bool isbackgroundcolor;
358         ///
359         RGBColor fontcolor;
360         ///
361         bool isfontcolor;
362         ///
363         RGBColor notefontcolor;
364         ///
365         RGBColor boxbgcolor;
366         /// \param index should lie in the range 0 <= \c index <= 3.
367         Bullet & temp_bullet(size_type index);
368         Bullet const & temp_bullet(size_type index) const;
369         /// \param index should lie in the range 0 <= \c index <= 3.
370         Bullet & user_defined_bullet(size_type index);
371         Bullet const & user_defined_bullet(size_type index) const;
372
373         /// Whether to load a package such as amsmath or esint.
374         /// The enum values must not be changed (file format!)
375         enum Package {
376                 /// Don't load the package. For experts only.
377                 package_off = 0,
378                 /// Load the package if needed (recommended)
379                 package_auto = 1,
380                 /// Always load the package (e.g. if the document contains
381                 /// some ERT that needs the package)
382                 package_on = 2
383         };
384         /// Whether to load a package such as amsmath or esint.
385         Package use_package(std::string const & p) const;
386         /// Set whether to load a package such as amsmath or esint.
387         void use_package(std::string const & p, Package u);
388         /// All packages that can be switched on or off
389         static std::map<std::string, std::string> const & auto_packages();
390         /// Do we use the bibtopic package?
391         bool useBibtopic() const;
392         /// Split bibliography?
393         bool splitbib() const { return use_bibtopic; }
394         /// Set split bibliography
395         void splitbib(bool const b) { use_bibtopic = b; }
396         /// Do we have multiple bibliographies (by chapter etc.)?
397         std::string multibib;
398         /// Split the index?
399         bool use_indices;
400         /// Save transient properties?
401         bool save_transient_properties;
402         /// revision tracking for this buffer ? (this is a transient property)
403         bool track_changes;
404         /** This param decides whether change tracking marks should be used
405          *  in output (irrespective of how these marks are actually defined;
406          *  for instance, they may differ for DVI and PDF generation)
407          *  This is a transient property.
408          */
409         bool output_changes;
410         ///
411         bool compressed;
412
413         /// the author list for the document
414         AuthorList & authors();
415         AuthorList const & authors() const;
416         void addAuthor(Author a);
417
418         /// map of the file's author IDs to AuthorList indexes
419         typedef std::map<int, int> AuthorMap;
420         AuthorMap author_map_;
421
422         /// the buffer's active font encoding
423         std::string const main_font_encoding() const;
424         /// all font encodings requested by the prefs/document/main language.
425         /// This does NOT include font encodings required by secondary languages
426         std::vector<std::string> const font_encodings() const;
427
428         ///
429         std::string const dvips_options() const;
430         /** The return value of paperSizeName() depends on the
431          *  purpose for which the paper size is needed, since they
432          *  support different subsets of paper sizes.
433         */
434         enum PapersizePurpose {
435                 ///
436                 DVIPS,
437                 ///
438                 DVIPDFM,
439                 ///
440                 XDVI
441         };
442         ///
443         std::string paperSizeName(PapersizePurpose purpose) const;
444         /// set up if and how babel is called
445         std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
446         /// return supported drivers for specific packages
447         docstring getGraphicsDriver(std::string const & package) const;
448         /// handle inputenc etc.
449         void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
450         ///
451         std::string const parseFontName(std::string const & name) const;
452         /// set up the document fonts
453         std::string const loadFonts(LaTeXFeatures & features) const;
454
455         /// the cite engine modules
456         LayoutModuleList const & citeEngine() const
457                 { return cite_engine_; }
458         /// the type of cite engine (authoryear or numerical)
459         CiteEngineType const & citeEngineType() const
460                 { return cite_engine_type_; }
461         /// add the module to the cite engine modules
462         bool addCiteEngine(std::string const &);
463         /// add the modules to the cite engine modules
464         bool addCiteEngine(std::vector<std::string> const &);
465         /// clear the list of cite engine modules
466         void clearCiteEngine() { cite_engine_.clear(); }
467         /// set the cite engine module
468         void setCiteEngine(std::string const &);
469         /// set the cite engine modules
470         void setCiteEngine(std::vector<std::string> const &);
471         /// set the cite engine type
472         void setCiteEngineType(CiteEngineType const & engine_type)
473                 { cite_engine_type_ = engine_type; }
474
475         /// the available citation commands
476         std::vector<std::string> citeCommands() const;
477         /// the available citation styles
478         std::vector<CitationStyle> citeStyles() const;
479
480         /// Return the actual bibtex command (lyxrc or buffer param)
481         std::string const bibtexCommand() const;
482
483         /// Are we using biblatex?
484         bool useBiblatex() const;
485
486         /// Set the default BibTeX style file for the document
487         void setDefaultBiblioStyle(std::string const & s){ biblio_style = s; }
488         /// Get the default BibTeX style file from the TextClass
489         std::string const & defaultBiblioStyle() const;
490         /// whether the BibTeX style supports full author lists
491         bool const & fullAuthorList() const;
492         /// Check if a citation style is an alias to another style
493         std::string getCiteAlias(std::string const & s) const;
494
495         /// Options of the bibiography package
496         std::string biblio_opts;
497         /// The biblatex bibliography style
498         std::string biblatex_bibstyle;
499         /// The biblatex citation style
500         std::string biblatex_citestyle;
501
502         /// options for pdf output
503         PDFOptions & pdfoptions();
504         PDFOptions const & pdfoptions() const;
505
506         // do not change these values. we rely upon them.
507         enum MathOutput {
508                 MathML = 0,
509                 HTML = 1,
510                 Images = 2,
511                 LaTeX = 3
512         };
513         /// what to use for math output. present choices are above
514         MathOutput html_math_output;
515         /// whether to attempt to be XHTML 1.1 compliant or instead be
516         /// a little more mellow
517         bool html_be_strict;
518         ///
519         double html_math_img_scale;
520         ///
521         double display_pixel_ratio;
522         ///
523         std::string html_latex_start;
524         ///
525         std::string html_latex_end;
526         ///
527         bool html_css_as_file;
528         /// generate output usable for reverse/forward search
529         bool output_sync;
530         /// custom LaTeX macro from user instead our own
531         std::string output_sync_macro;
532         /// use refstyle? or prettyref?
533         bool use_refstyle;
534
535         /// Return true if language could be set to lang,
536         /// otherwise return false and do not change language
537         bool setLanguage(std::string const & lang);
538         ///
539         void invalidateConverterCache() const;
540
541 private:
542         ///
543         void readPreamble(Lexer &);
544         ///
545         void readLocalLayout(Lexer &, bool);
546         ///
547         void readLanguage(Lexer &);
548         ///
549         void readGraphicsDriver(Lexer &);
550         ///
551         void readBullets(Lexer &);
552         ///
553         void readBulletsLaTeX(Lexer &);
554         ///
555         void readModules(Lexer &);
556         ///
557         void readRemovedModules(Lexer &);
558         ///
559         void readIncludeonly(Lexer &);
560         /// A cache for the default flavors
561         typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
562         ///
563         mutable DefaultFlavorCache default_flavors_;
564         /// the cite engine modules
565         LayoutModuleList cite_engine_;
566         /// the type of cite engine (authoryear or numerical)
567         CiteEngineType cite_engine_type_;
568         /// the default BibTeX style file for the document
569         std::string biblio_style;
570         /// Split bibliography?
571         bool use_bibtopic;
572         ///
573         DocumentClassPtr doc_class_;
574         ///
575         LayoutModuleList layout_modules_;
576         /// this is for modules that are required by the document class but that
577         /// the user has chosen not to use
578         std::list<std::string> removed_modules_;
579         /// The local layouts without the forced ones
580         docstring local_layout_;
581         /// Forced local layouts only for reading (use getLocalLayout() instead)
582         docstring forced_local_layout_;
583
584         /// the list of included children (for includeonly)
585         std::list<std::string> included_children_;
586
587         typedef std::map<std::string, Package> PackageMap;
588         /** Whether and how to load packages like amsmath, esint, mhchem,
589          *  mathdots, stackrel, stmaryrd and undertilde.
590          */
591         PackageMap use_packages;
592
593         /** Use the Pimpl idiom to hide those member variables that would otherwise
594          *  drag in other header files.
595          */
596         class Impl;
597         class MemoryTraits {
598         public:
599                 static Impl * clone(Impl const *);
600                 static void destroy(Impl *);
601         };
602         support::copied_ptr<Impl, MemoryTraits> pimpl_;
603
604 };
605
606 } // namespace lyx
607
608 #endif