]> git.lyx.org Git - lyx.git/blob - src/BufferParams.h
Add buffer param to opt-out fragile content movement
[lyx.git] / src / BufferParams.h
1 // -*- C++ -*-
2 /**
3  * \file BufferParams.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author John Levon
10  * \author André Pönitz
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef BUFFERPARAMS_H
16 #define BUFFERPARAMS_H
17
18 #include "Author.h"
19 #include "Citation.h"
20 #include "DocumentClassPtr.h"
21 #include "Format.h"
22 #include "LayoutModuleList.h"
23 #include "OutputParams.h"
24 #include "paper.h"
25
26 #include "insets/InsetQuotes.h"
27
28 #include "support/copied_ptr.h"
29
30 #include <map>
31 #include <vector>
32
33 namespace lyx {
34
35 namespace support { class FileName; }
36
37 class BranchList;
38 class Bullet;
39 class DocumentClass;
40 class Encoding;
41 class Font;
42 class 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         bool maintain_unincluded_children;
218
219         /// returns the main font for the buffer (document)
220         Font const getFont() const;
221
222         /// translate quote style string to enum value
223         InsetQuotesParams::QuoteStyle getQuoteStyle(std::string const & qs) const;
224
225         /* these are for the PaperLayout */
226         /// the papersize
227         PAPER_SIZE papersize;
228         ///
229         PAPER_ORIENTATION orientation;
230         /// use custom margins
231         bool use_geometry;
232         ///
233         std::string paperwidth;
234         ///
235         std::string paperheight;
236         ///
237         std::string leftmargin;
238         ///
239         std::string topmargin;
240         ///
241         std::string rightmargin;
242         ///
243         std::string bottommargin;
244         ///
245         std::string headheight;
246         ///
247         std::string headsep;
248         ///
249         std::string footskip;
250         ///
251         std::string columnsep;
252
253         /* some LaTeX options */
254         /// The graphics driver
255         std::string graphics_driver;
256         /// The default output format
257         std::string default_output_format;
258         /// customized bibliography processor
259         std::string bibtex_command;
260         /// customized index processor
261         std::string index_command;
262         /// font encoding(s) requested for this document
263         std::string fontenc;
264         /// the rm font: [0] for TeX fonts, [1] for non-TeX fonts
265         std::string fonts_roman[2];
266         /// the rm font
267         std::string const & fontsRoman() const { return fonts_roman[useNonTeXFonts]; }
268         /// the sf font: [0] for TeX fonts, [1] for non-TeX fonts
269         std::string fonts_sans[2];
270         /// the sf font
271         std::string const & fontsSans() const { return fonts_sans[useNonTeXFonts]; }
272         /// the tt font: [0] for TeX fonts, [1] for non-TeX fonts
273         std::string fonts_typewriter[2];
274         /// the tt font
275         std::string const & fontsTypewriter() const { return fonts_typewriter[useNonTeXFonts]; }
276         /// the math font: [0] for TeX fonts, [1] for non-TeX fonts
277         std::string fonts_math[2];
278         /// the math font
279         std::string const & fontsMath() const { return fonts_math[useNonTeXFonts]; }
280         /// the default family (rm, sf, tt)
281         std::string fonts_default_family;
282         /// use the fonts of the OS (OpenType, True Type) directly
283         bool useNonTeXFonts;
284         /// use expert Small Caps
285         bool fonts_expert_sc;
286         /// use Old Style Figures (rm)
287         bool fonts_roman_osf;
288         /// use Old Style Figures (sf)
289         bool fonts_sans_osf;
290         /// use Old Style Figures (tt)
291         bool fonts_typewriter_osf;
292         /// the options for the roman font
293         std::string font_roman_opts;
294         /// the scale factor of the sf font: [0] for TeX fonts, [1] for non-TeX fonts
295         int fonts_sans_scale[2];
296         /// the scale factor of the sf font
297         int fontsSansScale() const { return fonts_sans_scale[useNonTeXFonts]; }
298         // the options for the sans font
299         std::string font_sans_opts;
300         /// the scale factor of the tt font: [0] for TeX fonts, [1] for non-TeX fonts
301         int fonts_typewriter_scale[2];
302         /// the scale factor of the tt font
303         int fontsTypewriterScale() const { return fonts_typewriter_scale[useNonTeXFonts]; }
304         // the options for the typewriter font
305         std::string font_typewriter_opts;
306         /// the font used by the CJK command
307         std::string fonts_cjk;
308         /// use LaTeX microtype package
309         bool use_microtype;
310         /// use font ligatures for en- and em-dashes
311         bool use_dash_ligatures;
312         ///
313         Spacing & spacing();
314         Spacing const & spacing() const;
315         ///
316         int secnumdepth;
317         ///
318         int tocdepth;
319         ///
320         Language const * language;
321         /// language package
322         std::string lang_package;
323         /// BranchList:
324         BranchList & branchlist();
325         BranchList const & branchlist() const;
326         /// IndicesList:
327         IndicesList & indiceslist();
328         IndicesList const & indiceslist() const;
329         /**
330          * The LyX name of the input encoding for LaTeX. This can be one of
331          * - \c auto: find out the input encoding from the used languages
332          * - \c default: ditto
333          * - any encoding defined in the file lib/encodings
334          * The encoding of the LyX file is always utf8 and has nothing to
335          * do with this setting.
336          * The difference between \c auto and \c default is that \c auto also
337          * causes loading of the inputenc package and writes a \inputenc{} command
338          * to the file when switching to another encoding, while \c default does not.
339          * \c default will not work unless the user takes additional measures
340          * (such as using special environments like the CJK environment from
341          * CJK.sty).
342          * \c default can be seen as an unspecified mix of 8bit encodings, since LyX
343          * does not interpret it in any way apart from display on screen.
344          */
345         std::string inputenc;
346         /// The main encoding used by this buffer for LaTeX output.
347         /// If the main encoding is \c auto or \c default,
348         /// individual pieces of text can use different encodings.
349         /// Output for XeTeX with 8-bit TeX fonts uses ASCII (set at runtime)
350         /// instead of the value returned by this function (cf. #10600).
351         Encoding const & encoding() const;
352         ///
353         std::string origin;
354         ///
355         docstring preamble;
356         ///
357         std::string options;
358         /// use the class options defined in the layout?
359         bool use_default_options;
360         ///
361         std::string master;
362         ///
363         bool suppress_date;
364         ///
365         std::string float_placement;
366         ///
367         std::string float_alignment;
368         ///
369         unsigned int columns;
370         ///
371         bool justification;
372         /// parameters for the listings package
373         std::string listings_params;
374         ///
375         PageSides sides;
376         ///
377         std::string pagestyle;
378         ///
379         std::string tablestyle;
380         ///
381         RGBColor backgroundcolor;
382         ///
383         bool isbackgroundcolor;
384         ///
385         RGBColor fontcolor;
386         ///
387         bool isfontcolor;
388         ///
389         RGBColor notefontcolor;
390         ///
391         RGBColor boxbgcolor;
392         /// \param index should lie in the range 0 <= \c index <= 3.
393         Bullet & temp_bullet(size_type index);
394         Bullet const & temp_bullet(size_type index) const;
395         /// \param index should lie in the range 0 <= \c index <= 3.
396         Bullet & user_defined_bullet(size_type index);
397         Bullet const & user_defined_bullet(size_type index) const;
398
399         /// Whether to load a package such as amsmath or esint.
400         /// The enum values must not be changed (file format!)
401         enum Package {
402                 /// Don't load the package. For experts only.
403                 package_off = 0,
404                 /// Load the package if needed (recommended)
405                 package_auto = 1,
406                 /// Always load the package (e.g. if the document contains
407                 /// some ERT that needs the package)
408                 package_on = 2
409         };
410         /// Whether to load a package such as amsmath or esint.
411         Package use_package(std::string const & p) const;
412         /// Set whether to load a package such as amsmath or esint.
413         void use_package(std::string const & p, Package u);
414         /// All packages that can be switched on or off
415         static std::map<std::string, std::string> const & auto_packages();
416         /// Do we use the bibtopic package?
417         bool useBibtopic() const;
418         /// Split bibliography?
419         bool splitbib() const { return use_bibtopic; }
420         /// Set split bibliography
421         void splitbib(bool const b) { use_bibtopic = b; }
422         /// Do we have multiple bibliographies (by chapter etc.)?
423         std::string multibib;
424         /// Split the index?
425         bool use_indices;
426         /// Save transient properties?
427         bool save_transient_properties;
428         /// revision tracking for this buffer ? (this is a transient property)
429         bool track_changes;
430         /** This param decides whether change tracking marks should be used
431          *  in output (irrespective of how these marks are actually defined;
432          *  for instance, they may differ for DVI and PDF generation)
433          *  This is a transient property.
434          */
435         bool output_changes;
436         ///
437         bool change_bars;
438         ///
439         bool compressed;
440         ///
441         bool postpone_fragile_content;
442
443         /// the author list for the document
444         AuthorList & authors();
445         AuthorList const & authors() const;
446         void addAuthor(Author a);
447
448         /// map of the file's author IDs to AuthorList indexes
449         typedef std::map<int, int> AuthorMap;
450         AuthorMap author_map_;
451
452         /// the buffer's active font encoding
453         std::string const main_font_encoding() const;
454         /// all font encodings requested by the prefs/document/main language.
455         /// This does NOT include font encodings required by secondary languages
456         std::vector<std::string> const font_encodings() const;
457
458         ///
459         std::string const dvips_options() const;
460         /** The return value of paperSizeName() depends on the
461          *  purpose for which the paper size is needed, since they
462          *  support different subsets of paper sizes.
463         */
464         enum PapersizePurpose {
465                 ///
466                 DVIPS,
467                 ///
468                 DVIPDFM,
469                 ///
470                 XDVI
471         };
472         ///
473         std::string paperSizeName(PapersizePurpose purpose,
474                                   std::string const & psize = std::string()) const;
475         /// set up if and how babel is called
476         std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
477         /// return supported drivers for specific packages
478         docstring getGraphicsDriver(std::string const & package) const;
479         /// handle inputenc etc.
480         void writeEncodingPreamble(otexstream & os, LaTeXFeatures & features) const;
481         ///
482         std::string const parseFontName(std::string const & name) const;
483         /// set up the document fonts
484         std::string const loadFonts(LaTeXFeatures & features) const;
485
486         /// the cite engine modules
487         std::string const & citeEngine() const { return cite_engine_; }
488         /// the type of cite engine (authoryear or numerical)
489         CiteEngineType const & citeEngineType() const
490                 { return cite_engine_type_; }
491         /// add the module to the cite engine modules
492         void setCiteEngine(std::string const & eng) { cite_engine_ = eng; }
493         /// set the cite engine type
494         void setCiteEngineType(CiteEngineType const & engine_type)
495                 { cite_engine_type_ = engine_type; }
496
497         /// the available citation commands
498         std::vector<std::string> citeCommands() const;
499         /// the available citation styles
500         std::vector<CitationStyle> citeStyles() const;
501
502         /// Return the actual bibtex command (lyxrc or buffer param)
503         std::string const bibtexCommand() const;
504
505         /// Are we using biblatex?
506         bool useBiblatex() const;
507
508         /// Set the default BibTeX style file for the document
509         void setDefaultBiblioStyle(std::string const & s){ biblio_style = s; }
510         /// Get the default BibTeX style file from the TextClass
511         std::string const & defaultBiblioStyle() const;
512         /// whether the BibTeX style supports full author lists
513         bool const & fullAuthorList() const;
514         /// Check if a citation style is an alias to another style
515         std::string getCiteAlias(std::string const & s) const;
516
517         /// Options of the bibiography package
518         std::string biblio_opts;
519         /// The biblatex bibliography style
520         std::string biblatex_bibstyle;
521         /// The biblatex citation style
522         std::string biblatex_citestyle;
523         /// Set the bib file encoding (for biblatex)
524         void setBibEncoding(std::string const & s) { bib_encoding = s; }
525         /// Get the bib file encoding (for biblatex)
526         std::string const & bibEncoding() const { return bib_encoding; }
527         /// Set encoding for individual bib file (for biblatex)
528         void setBibFileEncoding(std::string const & file, std::string const & enc);
529         ///
530         std::string const bibFileEncoding(std::string const & file) const;
531
532         /// options for pdf output
533         PDFOptions & pdfoptions();
534         PDFOptions const & pdfoptions() const;
535
536         // do not change these values. we rely upon them.
537         enum MathOutput {
538                 MathML = 0,
539                 HTML = 1,
540                 Images = 2,
541                 LaTeX = 3
542         };
543         /// what to use for math output. present choices are above
544         MathOutput html_math_output;
545         /// whether to attempt to be XHTML 1.1 compliant or instead be
546         /// a little more mellow
547         bool html_be_strict;
548         ///
549         double html_math_img_scale;
550         ///
551         double display_pixel_ratio;
552         ///
553         std::string html_latex_start;
554         ///
555         std::string html_latex_end;
556         ///
557         bool html_css_as_file;
558         /// allow the LaTeX backend to run external programs
559         bool shell_escape;
560         /// generate output usable for reverse/forward search
561         bool output_sync;
562         /// custom LaTeX macro from user instead our own
563         std::string output_sync_macro;
564         /// use refstyle? or prettyref?
565         bool use_refstyle;
566         /// use minted? or listings?
567         bool use_minted;
568         //output line numbering
569         bool use_lineno;
570         //optional params for lineno package
571         std::string lineno_opts;
572
573         /// Return true if language could be set to lang,
574         /// otherwise return false and do not change language
575         bool setLanguage(std::string const & lang);
576         ///
577         void invalidateConverterCache() const;
578         /// Copies over some of the settings from \param bp,
579         /// namely the ones need by Advanced F&R. We don't want
580         /// to copy them all, e.g., not the default master.
581         void copyForAdvFR(BufferParams const & bp);
582
583 private:
584         ///
585         void readPreamble(Lexer &);
586         ///
587         void readLocalLayout(Lexer &, bool);
588         ///
589         void readLanguage(Lexer &);
590         ///
591         void readGraphicsDriver(Lexer &);
592         ///
593         void readBullets(Lexer &);
594         ///
595         void readBulletsLaTeX(Lexer &);
596         ///
597         void readModules(Lexer &);
598         ///
599         void readRemovedModules(Lexer &);
600         ///
601         void readIncludeonly(Lexer &);
602         /// A cache for the default flavors
603         typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
604         ///
605         mutable DefaultFlavorCache default_flavors_;
606         /// the cite engine
607         std::string cite_engine_;
608         /// the type of cite engine (authoryear or numerical)
609         CiteEngineType cite_engine_type_;
610         /// the default BibTeX style file for the document
611         std::string biblio_style;
612         /// The main encoding of the bib files, for Biblatex
613         std::string bib_encoding;
614         /// Individual file encodings, for Biblatex
615         std::map<std::string, std::string> bib_encodings;
616         /// Split bibliography?
617         bool use_bibtopic;
618         ///
619         DocumentClassPtr doc_class_;
620         ///
621         LayoutModuleList layout_modules_;
622         /// this is for modules that are required by the document class but that
623         /// the user has chosen not to use
624         std::list<std::string> removed_modules_;
625         /// The local layouts without the forced ones
626         docstring local_layout_;
627         /// Forced local layouts only for reading (use getLocalLayout() instead)
628         docstring forced_local_layout_;
629
630         /// the list of included children (for includeonly)
631         std::list<std::string> included_children_;
632
633         typedef std::map<std::string, Package> PackageMap;
634         /** Whether and how to load packages like amsmath, esint, mhchem,
635          *  mathdots, stackrel, stmaryrd and undertilde.
636          */
637         PackageMap use_packages;
638
639         /** Use the Pimpl idiom to hide those member variables that would otherwise
640          *  drag in other header files.
641          */
642         class Impl;
643         class MemoryTraits {
644         public:
645                 static Impl * clone(Impl const *);
646                 static void destroy(Impl *);
647         };
648         support::copied_ptr<Impl, MemoryTraits> pimpl_;
649 };
650
651 } // namespace lyx
652
653 #endif