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