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