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