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