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