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