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