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