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