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