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