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