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