]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
Force redraw after completion
[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         WordLangTable & spellignore();
341         WordLangTable const & spellignore() const;
342         bool spellignored(WordLangTuple const & wl) const;
343         /**
344          * The LyX name of the input encoding for LaTeX. This can be one of
345          * - \c auto: find out the input encoding from the used languages
346          * - \c default: ditto
347          * - any encoding defined in the file lib/encodings
348          * The encoding of the LyX file is always utf8 and has nothing to
349          * do with this setting.
350          * The difference between \c auto and \c default is that \c auto also
351          * causes loading of the inputenc package and writes a \inputenc{} command
352          * to the file when switching to another encoding, while \c default does not.
353          * \c default will not work unless the user takes additional measures
354          * (such as using special environments like the CJK environment from
355          * CJK.sty).
356          * \c default can be seen as an unspecified mix of 8bit encodings, since LyX
357          * does not interpret it in any way apart from display on screen.
358          */
359         std::string inputenc;
360         /// The main encoding used by this buffer for LaTeX output.
361         /// If the main encoding is \c auto or \c default,
362         /// individual pieces of text can use different encodings.
363         /// Output for XeTeX with 8-bit TeX fonts uses ASCII (set at runtime)
364         /// instead of the value returned by this function (cf. #10600).
365         Encoding const & encoding() const;
366         ///
367         std::string origin;
368         ///
369         docstring preamble;
370         ///
371         std::string options;
372         /// use the class options defined in the layout?
373         bool use_default_options;
374         ///
375         std::string master;
376         ///
377         bool suppress_date;
378         ///
379         std::string float_placement;
380         ///
381         std::string float_alignment;
382         ///
383         unsigned int columns;
384         ///
385         bool justification;
386         /// parameters for the listings package
387         std::string listings_params;
388         ///
389         PageSides sides;
390         ///
391         std::string pagestyle;
392         ///
393         std::string tablestyle;
394         ///
395         RGBColor backgroundcolor;
396         ///
397         bool isbackgroundcolor;
398         ///
399         RGBColor fontcolor;
400         ///
401         bool isfontcolor;
402         ///
403         RGBColor notefontcolor;
404         ///
405         bool isnotefontcolor;
406         ///
407         RGBColor boxbgcolor;
408         ///
409         bool isboxbgcolor;
410         /// \param index should lie in the range 0 <= \c index <= 3.
411         Bullet & temp_bullet(size_type index);
412         Bullet const & temp_bullet(size_type index) const;
413         /// \param index should lie in the range 0 <= \c index <= 3.
414         Bullet & user_defined_bullet(size_type index);
415         Bullet const & user_defined_bullet(size_type index) const;
416
417         /// Whether to load a package such as amsmath or esint.
418         /// The enum values must not be changed (file format!)
419         enum Package {
420                 /// Don't load the package. For experts only.
421                 package_off = 0,
422                 /// Load the package if needed (recommended)
423                 package_auto = 1,
424                 /// Always load the package (e.g. if the document contains
425                 /// some ERT that needs the package)
426                 package_on = 2
427         };
428         /// Whether to load a package such as amsmath or esint.
429         Package use_package(std::string const & p) const;
430         /// Set whether to load a package such as amsmath or esint.
431         void use_package(std::string const & p, Package u);
432         /// All packages that can be switched on or off
433         static std::map<std::string, std::string> const & auto_packages();
434         /// Do we use the bibtopic package?
435         bool useBibtopic() const;
436         /// Split bibliography?
437         bool splitbib() const { return use_bibtopic; }
438         /// Set split bibliography
439         void splitbib(bool const b) { use_bibtopic = b; }
440         /// Do we have multiple bibliographies (by chapter etc.)?
441         std::string multibib;
442         /// Split the index?
443         bool use_indices;
444         /// Save transient properties?
445         bool save_transient_properties;
446         /// revision tracking for this buffer ? (this is a transient property)
447         bool track_changes;
448         /** This param decides whether change tracking marks should be used
449          *  in output (irrespective of how these marks are actually defined;
450          *  for instance, they may differ for DVI and PDF generation)
451          *  This is a transient property.
452          */
453         bool output_changes;
454         ///
455         bool change_bars;
456         ///
457         bool compressed;
458         ///
459         bool postpone_fragile_content;
460
461         /// the author list for the document
462         AuthorList & authors();
463         AuthorList const & authors() const;
464         void addAuthor(Author const & a);
465
466         /// map of the file's author IDs to AuthorList indexes
467         typedef std::map<int, int> AuthorMap;
468         AuthorMap author_map_;
469
470         /// the buffer's active font encoding
471         std::string const main_font_encoding() const;
472         /// all font encodings requested by the prefs/document/main language.
473         /// This does NOT include font encodings required by secondary languages
474         std::vector<std::string> const font_encodings() const;
475
476         ///
477         std::string const dvips_options() const;
478         /** The return value of paperSizeName() depends on the
479          *  purpose for which the paper size is needed, since they
480          *  support different subsets of paper sizes.
481         */
482         enum PapersizePurpose {
483                 ///
484                 DVIPS,
485                 ///
486                 DVIPDFM,
487                 ///
488                 XDVI
489         };
490         ///
491         std::string paperSizeName(PapersizePurpose purpose,
492                                   std::string const & psize = std::string()) const;
493         /// set up if and how babel is called
494         std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
495         /// return supported drivers for specific packages
496         docstring getGraphicsDriver(std::string const & package) const;
497         /// handle inputenc etc.
498         void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
499         ///
500         std::string const parseFontName(std::string const & name) const;
501         /// set up the document fonts
502         std::string const loadFonts(LaTeXFeatures & features) const;
503
504         /// the cite engine modules
505         std::string const & citeEngine() const { return cite_engine_; }
506         /// the type of cite engine (authoryear or numerical)
507         CiteEngineType const & citeEngineType() const
508                 { return cite_engine_type_; }
509         /// add the module to the cite engine modules
510         void setCiteEngine(std::string const & eng) { cite_engine_ = eng; }
511         /// set the cite engine type
512         void setCiteEngineType(CiteEngineType const & engine_type)
513                 { cite_engine_type_ = engine_type; }
514
515         /// the available citation commands
516         std::vector<std::string> citeCommands() const;
517         /// the available citation styles
518         std::vector<CitationStyle> citeStyles() const;
519
520         /// Return the actual bibtex command (lyxrc or buffer param)
521         std::string const bibtexCommand(bool const warn = false) const;
522
523         /// Are we using biblatex?
524         bool useBiblatex() const;
525
526         /// Set the default BibTeX style file for the document
527         void setDefaultBiblioStyle(std::string const & s){ biblio_style = s; }
528         /// Get the default BibTeX style file from the TextClass
529         std::string const & defaultBiblioStyle() const;
530         /// whether the BibTeX style supports full author lists
531         bool fullAuthorList() const;
532         /// Check if a citation style is an alias to another style
533         std::string getCiteAlias(std::string const & s) const;
534
535         /// Options of the bibiography package
536         std::string biblio_opts;
537         /// The biblatex bibliography style
538         std::string biblatex_bibstyle;
539         /// The biblatex citation style
540         std::string biblatex_citestyle;
541         /// Set the bib file encoding (for biblatex)
542         void setBibEncoding(std::string const & s) { bib_encoding = s; }
543         /// Get the bib file encoding (for biblatex)
544         std::string const & bibEncoding() const { return bib_encoding; }
545         /// Set encoding for individual bib file (for biblatex)
546         void setBibFileEncoding(std::string const & file, std::string const & enc);
547         ///
548         std::string const bibFileEncoding(std::string const & file) const;
549
550         /// options for pdf output
551         PDFOptions & pdfoptions();
552         PDFOptions const & pdfoptions() const;
553
554         // do not change these values. we rely upon them.
555         enum MathOutput {
556                 MathML = 0,
557                 HTML = 1,
558                 Images = 2,
559                 LaTeX = 3
560         };
561         /// what to use for math output. present choices are above
562         MathOutput html_math_output;
563         /// whether to attempt to be XHTML 1.1 compliant or instead be
564         /// a little more mellow
565         bool html_be_strict;
566         ///
567         double html_math_img_scale;
568         ///
569         double display_pixel_ratio;
570         ///
571         std::string html_latex_start;
572         ///
573         std::string html_latex_end;
574         ///
575         bool html_css_as_file;
576
577         // do not change these values. we rely upon them.
578         enum TableOutput {
579                 HTMLTable = 0,
580                 CALSTable = 1
581         };
582         /// what format to use for table output in DocBook. present choices are above
583         TableOutput docbook_table_output;
584
585         // do not change these values. we rely upon them.
586         enum MathMLNameSpacePrefix {
587                 NoPrefix = 0,
588                 MPrefix = 1,
589                 MMLPrefix = 2
590         };
591         /// what prefix to use when outputting MathML. present choices are above
592         MathMLNameSpacePrefix docbook_mathml_prefix;
593
594         /// allow the LaTeX backend to run external programs
595         bool shell_escape;
596         /// generate output usable for reverse/forward search
597         bool output_sync;
598         /// custom LaTeX macro from user instead our own
599         std::string output_sync_macro;
600         /// use refstyle? or prettyref?
601         bool use_refstyle;
602         /// use minted? or listings?
603         bool use_minted;
604         //output line numbering
605         bool use_lineno;
606         //optional params for lineno package
607         std::string lineno_opts;
608
609         /// Return true if language could be set to lang,
610         /// otherwise return false and do not change language
611         bool setLanguage(std::string const & lang);
612         ///
613         void invalidateConverterCache() const;
614         /// Copies over some of the settings from \param bp,
615         /// namely the ones need by Advanced F&R. We don't want
616         /// to copy them all, e.g., not the default master.
617         void copyForAdvFR(BufferParams const & bp);
618
619 private:
620         ///
621         void readPreamble(Lexer &);
622         ///
623         void readLocalLayout(Lexer &, bool);
624         ///
625         void readLanguage(Lexer &);
626         ///
627         void readGraphicsDriver(Lexer &);
628         ///
629         void readBullets(Lexer &);
630         ///
631         void readBulletsLaTeX(Lexer &);
632         ///
633         void readModules(Lexer &);
634         ///
635         void readRemovedModules(Lexer &);
636         ///
637         void readIncludeonly(Lexer &);
638         /// A cache for the default flavors
639         typedef std::map<std::string, Flavor> DefaultFlavorCache;
640         ///
641         mutable DefaultFlavorCache default_flavors_;
642         /// the cite engine
643         std::string cite_engine_;
644         /// the type of cite engine (authoryear or numerical)
645         CiteEngineType cite_engine_type_;
646         /// the default BibTeX style file for the document
647         std::string biblio_style;
648         /// The main encoding of the bib files, for Biblatex
649         std::string bib_encoding;
650         /// Individual file encodings, for Biblatex
651         std::map<std::string, std::string> bib_encodings;
652         /// Split bibliography?
653         bool use_bibtopic;
654         /// Return the actual or an appropriate fallback bibtex command
655         std::string const getBibtexCommand(std::string const cmd,
656                                            bool const warn) const;
657         ///
658         DocumentClassPtr doc_class_;
659         ///
660         LayoutModuleList layout_modules_;
661         /// this is for modules that are required by the document class but that
662         /// the user has chosen not to use
663         std::list<std::string> removed_modules_;
664         /// The local layouts without the forced ones
665         docstring local_layout_;
666         /// Forced local layouts only for reading (use getLocalLayout() instead)
667         docstring forced_local_layout_;
668
669         /// the list of included children (for includeonly)
670         std::list<std::string> included_children_;
671
672         typedef std::map<std::string, Package> PackageMap;
673         /** Whether and how to load packages like amsmath, esint, mhchem,
674          *  mathdots, stackrel, stmaryrd and undertilde.
675          */
676         PackageMap use_packages;
677
678         /** Use the Pimpl idiom to hide those member variables that would otherwise
679          *  drag in other header files.
680          */
681         class Impl;
682         class MemoryTraits {
683         public:
684                 static Impl * clone(Impl const *);
685                 static void destroy(Impl *);
686         };
687         support::copied_ptr<Impl, MemoryTraits> pimpl_;
688 };
689
690 } // namespace lyx
691
692 #endif