]> git.lyx.org Git - lyx.git/blob - src/buffer.C
a10470487a745e3ee2ae3c79b9ff0353fdc8ef19
[lyx.git] / src / buffer.C
1 /**
2  * \file buffer.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "buffer.h"
14
15 #include "author.h"
16 #include "BranchList.h"
17 #include "buffer_funcs.h"
18 #include "bufferlist.h"
19 #include "bufferparams.h"
20 #include "counters.h"
21 #include "Bullet.h"
22 #include "Chktex.h"
23 #include "debug.h"
24 #include "encoding.h"
25 #include "errorlist.h"
26 #include "exporter.h"
27 #include "format.h"
28 #include "funcrequest.h"
29 #include "gettext.h"
30 #include "insetiterator.h"
31 #include "language.h"
32 #include "LaTeX.h"
33 #include "LaTeXFeatures.h"
34 #include "LyXAction.h"
35 #include "lyxlex.h"
36 #include "lyxtext.h"
37 #include "lyxrc.h"
38 #include "lyxvc.h"
39 #include "lyx_main.h"
40 #include "messages.h"
41 #include "output.h"
42 #include "output_docbook.h"
43 #include "output_latex.h"
44 #include "paragraph.h"
45 #include "paragraph_funcs.h"
46 #include "ParagraphParameters.h"
47 #include "pariterator.h"
48 #include "sgml.h"
49 #include "texrow.h"
50 #include "undo.h"
51 #include "version.h"
52
53 #include "insets/insetbibitem.h"
54 #include "insets/insetbibtex.h"
55 #include "insets/insetinclude.h"
56 #include "insets/insettext.h"
57
58 #include "mathed/math_macrotemplate.h"
59 #include "mathed/math_macrotable.h"
60 #include "mathed/math_support.h"
61
62 #include "frontends/Alert.h"
63
64 #include "graphics/Previews.h"
65
66 #include "support/types.h"
67 #include "support/lyxalgo.h"
68 #include "support/filetools.h"
69 #include "support/fs_extras.h"
70 # include <boost/iostreams/filtering_stream.hpp>
71 # include <boost/iostreams/filter/gzip.hpp>
72 # include <boost/iostreams/device/file.hpp>
73 namespace io = boost::iostreams;
74 #include "support/lyxlib.h"
75 #include "support/os.h"
76 #include "support/path.h"
77 #include "support/textutils.h"
78 #include "support/convert.h"
79
80 #include <boost/bind.hpp>
81 #include <boost/filesystem/exception.hpp>
82 #include <boost/filesystem/operations.hpp>
83
84 #if defined (HAVE_UTIME_H)
85 # include <utime.h>
86 #elif defined (HAVE_SYS_UTIME_H)
87 # include <sys/utime.h>
88 #endif
89
90 #include <iomanip>
91 #include <stack>
92 #include <sstream>
93 #include <fstream>
94
95
96 using lyx::pos_type;
97 using lyx::pit_type;
98
99 using lyx::support::addName;
100 using lyx::support::bformat;
101 using lyx::support::changeExtension;
102 using lyx::support::cmd_ret;
103 using lyx::support::createBufferTmpDir;
104 using lyx::support::destroyDir;
105 using lyx::support::getFormatFromContents;
106 using lyx::support::isDirWriteable;
107 using lyx::support::libFileSearch;
108 using lyx::support::latex_path;
109 using lyx::support::ltrim;
110 using lyx::support::makeAbsPath;
111 using lyx::support::makeDisplayPath;
112 using lyx::support::makeLatexName;
113 using lyx::support::onlyFilename;
114 using lyx::support::onlyPath;
115 using lyx::support::Path;
116 using lyx::support::quoteName;
117 using lyx::support::removeAutosaveFile;
118 using lyx::support::rename;
119 using lyx::support::runCommand;
120 using lyx::support::split;
121 using lyx::support::subst;
122 using lyx::support::tempName;
123 using lyx::support::trim;
124
125 namespace os = lyx::support::os;
126 namespace fs = boost::filesystem;
127
128 using std::endl;
129 using std::for_each;
130 using std::make_pair;
131
132 using std::ifstream;
133 using std::ios;
134 using std::map;
135 using std::ostream;
136 using std::ostringstream;
137 using std::ofstream;
138 using std::pair;
139 using std::stack;
140 using std::vector;
141 using std::string;
142
143
144 // all these externs should eventually be removed.
145 extern BufferList bufferlist;
146
147 namespace {
148
149 int const LYX_FORMAT = 249;
150
151 } // namespace anon
152
153
154 typedef std::map<string, bool> DepClean;
155
156 class Buffer::Impl
157 {
158 public:
159         Impl(Buffer & parent, string const & file, bool readonly);
160
161         limited_stack<Undo> undostack;
162         limited_stack<Undo> redostack;
163         BufferParams params;
164         LyXVC lyxvc;
165         string temppath;
166         TexRow texrow;
167
168         /// need to regenerate .tex?
169         DepClean dep_clean;
170
171         /// is save needed?
172         mutable bool lyx_clean;
173
174         /// is autosave needed?
175         mutable bool bak_clean;
176
177         /// is this a unnamed file (New...)?
178         bool unnamed;
179
180         /// buffer is r/o
181         bool read_only;
182
183         /// name of the file the buffer is associated with.
184         string filename;
185
186         boost::scoped_ptr<Messages> messages;
187
188         /** Set to true only when the file is fully loaded.
189          *  Used to prevent the premature generation of previews
190          *  and by the citation inset.
191          */
192         bool file_fully_loaded;
193
194         /// our LyXText that should be wrapped in an InsetText
195         InsetText inset;
196
197         ///
198         MacroTable macros;
199 };
200
201
202 Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_)
203         : lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
204           filename(file), file_fully_loaded(false),
205                 inset(params)
206 {
207         inset.setAutoBreakRows(true);
208         lyxvc.buffer(&parent);
209         temppath = createBufferTmpDir();
210         params.filepath = onlyPath(file);
211         // FIXME: And now do something if temppath == string(), because we
212         // assume from now on that temppath points to a valid temp dir.
213         // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg67406.html
214 }
215
216
217 Buffer::Buffer(string const & file, bool readonly)
218         : pimpl_(new Impl(*this, file, readonly))
219 {
220         lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
221 }
222
223
224 Buffer::~Buffer()
225 {
226         lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
227         // here the buffer should take care that it is
228         // saved properly, before it goes into the void.
229
230         closing();
231
232         if (!temppath().empty() && !destroyDir(temppath())) {
233                 Alert::warning(_("Could not remove temporary directory"),
234                         bformat(_("Could not remove the temporary directory %1$s"), temppath()));
235         }
236
237         // Remove any previewed LaTeX snippets associated with this buffer.
238         lyx::graphics::Previews::get().removeLoader(*this);
239 }
240
241
242 LyXText & Buffer::text() const
243 {
244         return const_cast<LyXText &>(pimpl_->inset.text_);
245 }
246
247
248 InsetBase & Buffer::inset() const
249 {
250         return const_cast<InsetText &>(pimpl_->inset);
251 }
252
253
254 limited_stack<Undo> & Buffer::undostack()
255 {
256         return pimpl_->undostack;
257 }
258
259
260 limited_stack<Undo> const & Buffer::undostack() const
261 {
262         return pimpl_->undostack;
263 }
264
265
266 limited_stack<Undo> & Buffer::redostack()
267 {
268         return pimpl_->redostack;
269 }
270
271
272 limited_stack<Undo> const & Buffer::redostack() const
273 {
274         return pimpl_->redostack;
275 }
276
277
278 BufferParams & Buffer::params()
279 {
280         return pimpl_->params;
281 }
282
283
284 BufferParams const & Buffer::params() const
285 {
286         return pimpl_->params;
287 }
288
289
290 ParagraphList & Buffer::paragraphs()
291 {
292         return text().paragraphs();
293 }
294
295
296 ParagraphList const & Buffer::paragraphs() const
297 {
298         return text().paragraphs();
299 }
300
301
302 LyXVC & Buffer::lyxvc()
303 {
304         return pimpl_->lyxvc;
305 }
306
307
308 LyXVC const & Buffer::lyxvc() const
309 {
310         return pimpl_->lyxvc;
311 }
312
313
314 string const & Buffer::temppath() const
315 {
316         return pimpl_->temppath;
317 }
318
319
320 TexRow & Buffer::texrow()
321 {
322         return pimpl_->texrow;
323 }
324
325
326 TexRow const & Buffer::texrow() const
327 {
328         return pimpl_->texrow;
329 }
330
331
332 string const Buffer::getLatexName(bool const no_path) const
333 {
334         string const name = changeExtension(makeLatexName(fileName()), ".tex");
335         return no_path ? onlyFilename(name) : name;
336 }
337
338
339 pair<Buffer::LogType, string> const Buffer::getLogName() const
340 {
341         string const filename = getLatexName(false);
342
343         if (filename.empty())
344                 return make_pair(Buffer::latexlog, string());
345
346         string const path = temppath();
347
348         string const fname = addName(path,
349                                      onlyFilename(changeExtension(filename,
350                                                                   ".log")));
351         string const bname =
352                 addName(path, onlyFilename(
353                         changeExtension(filename,
354                                         formats.extension("literate") + ".out")));
355
356         // If no Latex log or Build log is newer, show Build log
357
358         if (fs::exists(bname) &&
359             (!fs::exists(fname) || fs::last_write_time(fname) < fs::last_write_time(bname))) {
360                 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
361                 return make_pair(Buffer::buildlog, bname);
362         }
363         lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
364         return make_pair(Buffer::latexlog, fname);
365 }
366
367
368 void Buffer::setReadonly(bool const flag)
369 {
370         if (pimpl_->read_only != flag) {
371                 pimpl_->read_only = flag;
372                 readonly(flag);
373         }
374 }
375
376
377 void Buffer::setFileName(string const & newfile)
378 {
379         pimpl_->filename = makeAbsPath(newfile);
380         params().filepath = onlyPath(pimpl_->filename);
381         setReadonly(fs::is_readonly(pimpl_->filename));
382         updateTitles();
383 }
384
385
386 // We'll remove this later. (Lgb)
387 namespace {
388
389 void unknownClass(string const & unknown)
390 {
391         Alert::warning(_("Unknown document class"),
392                 bformat(_("Using the default document class, because the "
393                         "class %1$s is unknown."), unknown));
394 }
395
396 } // anon
397
398
399 int Buffer::readHeader(LyXLex & lex)
400 {
401         int unknown_tokens = 0;
402         int line = -1;
403         int begin_header_line = -1;
404
405         // Initialize parameters that may be/go lacking in header:
406         params().branchlist().clear();
407         params().preamble.erase();
408         params().options.erase();
409         params().float_placement.erase();
410         params().paperwidth.erase();
411         params().paperheight.erase();
412         params().leftmargin.erase();
413         params().rightmargin.erase();
414         params().topmargin.erase();
415         params().bottommargin.erase();
416         params().headheight.erase();
417         params().headsep.erase();
418         params().footskip.erase();
419
420         ErrorList & errorList = errorLists_["Parse"];
421
422         while (lex.isOK()) {
423                 lex.next();
424                 string const token = lex.getString();
425
426                 if (token.empty())
427                         continue;
428
429                 if (token == "\\end_header")
430                         break;
431
432                 ++line;
433                 if (token == "\\begin_header") {
434                         begin_header_line = line;
435                         continue;
436                 }
437
438                 lyxerr[Debug::PARSER] << "Handling document header token: `"
439                                       << token << '\'' << endl;
440
441                 string unknown = params().readToken(lex, token);
442                 if (!unknown.empty()) {
443                         if (unknown[0] != '\\' && token == "\\textclass") {
444                                 unknownClass(unknown);
445                         } else {
446                                 ++unknown_tokens;
447                                 string const s = bformat(_("Unknown token: "
448                                                            "%1$s %2$s\n"),
449                                                          token,
450                                                          lex.getString());
451                                 errorList.push_back(ErrorItem(_("Document header error"),
452                                         s, -1, 0, 0));
453                         }
454                 }
455         }
456         if (begin_header_line) {
457                 string const s = _("\\begin_header is missing");
458                 errorList.push_back(ErrorItem(_("Document header error"),
459                         s, -1, 0, 0));
460         }
461
462         return unknown_tokens;
463 }
464
465
466 // Uwe C. Schroeder
467 // changed to be public and have one parameter
468 // Returns false if "\end_document" is not read (Asger)
469 bool Buffer::readDocument(LyXLex & lex)
470 {
471         ErrorList & errorList = errorLists_["Parse"];
472         errorList.clear();
473
474         lex.next();
475         string const token = lex.getString();
476         if (token != "\\begin_document") {
477                 string const s = _("\\begin_document is missing");
478                 errorList.push_back(ErrorItem(_("Document header error"),
479                         s, -1, 0, 0));
480         }
481
482         // we are reading in a brand new document
483         BOOST_ASSERT(paragraphs().empty());
484
485         readHeader(lex);
486         if (!params().getLyXTextClass().load(filePath())) {
487                 string theclass = params().getLyXTextClass().name();
488                 Alert::error(_("Can't load document class"), bformat(
489                                      "Using the default document class, because the "
490                                      " class %1$s could not be loaded.", theclass));
491                 params().textclass = 0;
492         }
493
494         bool const res = text().read(*this, lex, errorList);
495         for_each(text().paragraphs().begin(),
496                  text().paragraphs().end(),
497                  bind(&Paragraph::setInsetOwner, _1, &inset()));
498         updateBibfilesCache();
499
500         return res;
501 }
502
503
504 // needed to insert the selection
505 void Buffer::insertStringAsLines(ParagraphList & pars,
506         pit_type & pit, pos_type & pos,
507         LyXFont const & fn, string const & str, bool autobreakrows)
508 {
509         LyXFont font = fn;
510
511         // insert the string, don't insert doublespace
512         bool space_inserted = true;
513         for (string::const_iterator cit = str.begin();
514             cit != str.end(); ++cit) {
515                 Paragraph & par = pars[pit];
516                 if (*cit == '\n') {
517                         if (autobreakrows && (!par.empty() || par.allowEmpty())) {
518                                 breakParagraph(params(), pars, pit, pos,
519                                                par.layout()->isEnvironment());
520                                 ++pit;
521                                 pos = 0;
522                                 space_inserted = true;
523                         } else {
524                                 continue;
525                         }
526                         // do not insert consecutive spaces if !free_spacing
527                 } else if ((*cit == ' ' || *cit == '\t') &&
528                            space_inserted && !par.isFreeSpacing()) {
529                         continue;
530                 } else if (*cit == '\t') {
531                         if (!par.isFreeSpacing()) {
532                                 // tabs are like spaces here
533                                 par.insertChar(pos, ' ', font);
534                                 ++pos;
535                                 space_inserted = true;
536                         } else {
537                                 const pos_type n = 8 - pos % 8;
538                                 for (pos_type i = 0; i < n; ++i) {
539                                         par.insertChar(pos, ' ', font);
540                                         ++pos;
541                                 }
542                                 space_inserted = true;
543                         }
544                 } else if (!isPrintable(*cit)) {
545                         // Ignore unprintables
546                         continue;
547                 } else {
548                         // just insert the character
549                         par.insertChar(pos, *cit, font);
550                         ++pos;
551                         space_inserted = (*cit == ' ');
552                 }
553
554         }
555 }
556
557
558 bool Buffer::readFile(string const & filename)
559 {
560         // Check if the file is compressed.
561         string const format = getFormatFromContents(filename);
562         if (format == "gzip" || format == "zip" || format == "compress") {
563                 params().compressed = true;
564         }
565
566         // remove dummy empty par
567         paragraphs().clear();
568         LyXLex lex(0, 0);
569         lex.setFile(filename);
570         if (!readFile(lex, filename))
571                 return false;
572
573         // After we have read a file, we must ensure that the buffer
574         // language is set and used in the gui.
575         // If you know of a better place to put this, please tell me. (Lgb)
576         updateDocLang(params().language);
577
578         return true;
579 }
580
581
582 bool Buffer::fully_loaded() const
583 {
584         return pimpl_->file_fully_loaded;
585 }
586
587
588 void Buffer::fully_loaded(bool const value)
589 {
590         pimpl_->file_fully_loaded = value;
591 }
592
593
594 bool Buffer::readFile(LyXLex & lex, string const & filename)
595 {
596         BOOST_ASSERT(!filename.empty());
597
598         if (!lex.isOK()) {
599                 Alert::error(_("Document could not be read"),
600                              bformat(_("%1$s could not be read."), filename));
601                 return false;
602         }
603
604         lex.next();
605         string const token(lex.getString());
606
607         if (!lex.isOK()) {
608                 Alert::error(_("Document could not be read"),
609                              bformat(_("%1$s could not be read."), filename));
610                 return false;
611         }
612
613         // the first token _must_ be...
614         if (token != "\\lyxformat") {
615                 lyxerr << "Token: " << token << endl;
616
617                 Alert::error(_("Document format failure"),
618                              bformat(_("%1$s is not a LyX document."),
619                                        filename));
620                 return false;
621         }
622
623         lex.next();
624         string tmp_format = lex.getString();
625         //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
626         // if present remove ".," from string.
627         string::size_type dot = tmp_format.find_first_of(".,");
628         //lyxerr << "           dot found at " << dot << endl;
629         if (dot != string::npos)
630                         tmp_format.erase(dot, 1);
631         int const file_format = convert<int>(tmp_format);
632         //lyxerr << "format: " << file_format << endl;
633
634         if (file_format != LYX_FORMAT) {
635                 string const tmpfile = tempName();
636                 if (tmpfile.empty()) {
637                         Alert::error(_("Conversion failed"),
638                                      bformat(_("%1$s is from an earlier"
639                                               " version of LyX, but a temporary"
640                                               " file for converting it could"
641                                               " not be created."),
642                                               filename));
643                         return false;
644                 }
645                 string const lyx2lyx = libFileSearch("lyx2lyx", "lyx2lyx");
646                 if (lyx2lyx.empty()) {
647                         Alert::error(_("Conversion script not found"),
648                                      bformat(_("%1$s is from an earlier"
649                                                " version of LyX, but the"
650                                                " conversion script lyx2lyx"
651                                                " could not be found."),
652                                                filename));
653                         return false;
654                 }
655                 ostringstream command;
656                 command << os::python() << ' ' << quoteName(lyx2lyx)
657                         << " -t " << convert<string>(LYX_FORMAT)
658                         << " -o " << quoteName(tmpfile) << ' '
659                         << quoteName(filename);
660                 string const command_str = command.str();
661
662                 lyxerr[Debug::INFO] << "Running '"
663                                     << command_str << '\''
664                                     << endl;
665
666                 cmd_ret const ret = runCommand(command_str);
667                 if (ret.first != 0) {
668                         Alert::error(_("Conversion script failed"),
669                                      bformat(_("%1$s is from an earlier version"
670                                               " of LyX, but the lyx2lyx script"
671                                               " failed to convert it."),
672                                               filename));
673                         return false;
674                 } else {
675                         bool const ret = readFile(tmpfile);
676                         // Do stuff with tmpfile name and buffer name here.
677                         return ret;
678                 }
679
680         }
681
682         if (readDocument(lex)) {
683                 Alert::error(_("Document format failure"),
684                              bformat(_("%1$s ended unexpectedly, which means"
685                                        " that it is probably corrupted."),
686                                        filename));
687         }
688
689         //lyxerr << "removing " << MacroTable::localMacros().size()
690         //      << " temporary macro entries" << endl;
691         //MacroTable::localMacros().clear();
692
693         pimpl_->file_fully_loaded = true;
694         return true;
695 }
696
697
698 // Should probably be moved to somewhere else: BufferView? LyXView?
699 bool Buffer::save() const
700 {
701         // We don't need autosaves in the immediate future. (Asger)
702         resetAutosaveTimers();
703
704         // make a backup
705         string s;
706         if (lyxrc.make_backup) {
707                 s = fileName() + '~';
708                 if (!lyxrc.backupdir_path.empty())
709                         s = addName(lyxrc.backupdir_path,
710                                     subst(os::internal_path(s),'/','!'));
711
712                 // It might very well be that this variant is just
713                 // good enough. (Lgb)
714                 // But to use this we need fs::copy_file to actually do a copy,
715                 // even when the target file exists. (Lgb)
716                 try {
717                     fs::copy_file(fileName(), s, false);
718                 }
719                 catch (fs::filesystem_error const & fe) {
720                         Alert::error(_("Backup failure"),
721                                 bformat(_("LyX was not able to make a backup copy in %1$s.\n"
722                                           "Please check if the directory exists and is writeable."),
723                                           fs::path(s).branch_path().native_directory_string()));
724                         lyxerr[Debug::DEBUG] << "Fs error: "
725                                              << fe.what() << endl;
726                 }
727         }
728
729         if (writeFile(fileName())) {
730                 markClean();
731                 removeAutosaveFile(fileName());
732         } else {
733                 // Saving failed, so backup is not backup
734                 if (lyxrc.make_backup)
735                         rename(s, fileName());
736                 return false;
737         }
738         return true;
739 }
740
741
742 bool Buffer::writeFile(string const & fname) const
743 {
744         if (pimpl_->read_only && fname == fileName())
745                 return false;
746
747         bool retval = false;
748
749         if (params().compressed) {
750                 io::filtering_ostream ofs(io::gzip_compressor() | io::file_sink(fname));
751                 if (!ofs)
752                         return false;
753
754                 retval = do_writeFile(ofs);
755         } else {
756                 ofstream ofs(fname.c_str(), ios::out|ios::trunc);
757                 if (!ofs)
758                         return false;
759
760                 retval = do_writeFile(ofs);
761         }
762
763         return retval;
764 }
765
766
767 bool Buffer::do_writeFile(ostream & ofs) const
768 {
769 #ifdef HAVE_LOCALE
770         // Use the standard "C" locale for file output.
771         ofs.imbue(std::locale::classic());
772 #endif
773
774         // The top of the file should not be written by params().
775
776         // write out a comment in the top of the file
777         ofs << "#LyX " << lyx_version
778             << " created this file. For more info see http://www.lyx.org/\n"
779             << "\\lyxformat " << LYX_FORMAT << "\n"
780             << "\\begin_document\n";
781
782         // now write out the buffer parameters.
783         ofs << "\\begin_header\n";
784         params().writeFile(ofs);
785         ofs << "\\end_header\n";
786
787         // write the text
788         ofs << "\n\\begin_body\n";
789         text().write(*this, ofs);
790         ofs << "\n\\end_body\n";
791
792         // Write marker that shows file is complete
793         ofs << "\\end_document" << endl;
794
795         // Shouldn't really be needed....
796         //ofs.close();
797
798         // how to check if close went ok?
799         // Following is an attempt... (BE 20001011)
800
801         // good() returns false if any error occured, including some
802         //        formatting error.
803         // bad()  returns true if something bad happened in the buffer,
804         //        which should include file system full errors.
805
806         bool status = true;
807         if (!ofs) {
808                 status = false;
809                 lyxerr << "File was not closed properly." << endl;
810         }
811
812         return status;
813 }
814
815
816 void Buffer::makeLaTeXFile(string const & fname,
817                            string const & original_path,
818                            OutputParams const & runparams,
819                            bool output_preamble, bool output_body)
820 {
821         lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
822
823         ofstream ofs;
824         if (!openFileWrite(ofs, fname))
825                 return;
826
827         writeLaTeXSource(ofs, original_path,
828                       runparams, output_preamble, output_body);
829
830         ofs.close();
831         if (ofs.fail())
832                 lyxerr << "File '" << fname << "' was not closed properly." << endl;
833 }
834
835
836 void Buffer::writeLaTeXSource(ostream & os,
837                            string const & original_path,
838                            OutputParams const & runparams_in,
839                            bool const output_preamble, bool const output_body)
840 {
841         OutputParams runparams = runparams_in;
842
843         // validate the buffer.
844         lyxerr[Debug::LATEX] << "  Validating buffer..." << endl;
845         LaTeXFeatures features(*this, params(), runparams);
846         validate(features);
847         lyxerr[Debug::LATEX] << "  Buffer validation done." << endl;
848
849         texrow().reset();
850
851         // The starting paragraph of the coming rows is the
852         // first paragraph of the document. (Asger)
853         texrow().start(paragraphs().begin()->id(), 0);
854
855         if (output_preamble && runparams.nice) {
856                 os << "%% LyX " << lyx_version << " created this file.  "
857                         "For more info, see http://www.lyx.org/.\n"
858                         "%% Do not edit unless you really know what "
859                         "you are doing.\n";
860                 texrow().newline();
861                 texrow().newline();
862         }
863         lyxerr[Debug::INFO] << "lyx document header finished" << endl;
864         // There are a few differences between nice LaTeX and usual files:
865         // usual is \batchmode and has a
866         // special input@path to allow the including of figures
867         // with either \input or \includegraphics (what figinsets do).
868         // input@path is set when the actual parameter
869         // original_path is set. This is done for usual tex-file, but not
870         // for nice-latex-file. (Matthias 250696)
871         // Note that input@path is only needed for something the user does
872         // in the preamble, included .tex files or ERT, files included by
873         // LyX work without it.
874         if (output_preamble) {
875                 if (!runparams.nice) {
876                         // code for usual, NOT nice-latex-file
877                         os << "\\batchmode\n"; // changed
878                         // from \nonstopmode
879                         texrow().newline();
880                 }
881                 if (!original_path.empty()) {
882                         string const inputpath = latex_path(original_path);
883                         os << "\\makeatletter\n"
884                             << "\\def\\input@path{{"
885                             << inputpath << "/}}\n"
886                             << "\\makeatother\n";
887                         texrow().newline();
888                         texrow().newline();
889                         texrow().newline();
890                 }
891
892                 // Write the preamble
893                 runparams.use_babel = params().writeLaTeX(os, features, texrow());
894
895                 if (!output_body)
896                         return;
897
898                 // make the body.
899                 os << "\\begin{document}\n";
900                 texrow().newline();
901         } // output_preamble
902         lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
903
904         if (!lyxrc.language_auto_begin) {
905                 os << subst(lyxrc.language_command_begin, "$$lang",
906                              params().language->babel())
907                     << endl;
908                 texrow().newline();
909         }
910
911         // if we are doing a real file with body, even if this is the
912         // child of some other buffer, let's cut the link here.
913         // This happens for example if only a child document is printed.
914         string save_parentname;
915         if (output_preamble) {
916                 save_parentname = params().parentname;
917                 params().parentname.erase();
918         }
919
920         // the real stuff
921         latexParagraphs(*this, paragraphs(), os, texrow(), runparams);
922
923         // Restore the parenthood if needed
924         if (output_preamble)
925                 params().parentname = save_parentname;
926
927         // add this just in case after all the paragraphs
928         os << endl;
929         texrow().newline();
930
931         if (!lyxrc.language_auto_end) {
932                 os << subst(lyxrc.language_command_end, "$$lang",
933                              params().language->babel())
934                     << endl;
935                 texrow().newline();
936         }
937
938         if (output_preamble) {
939                 os << "\\end{document}\n";
940                 texrow().newline();
941
942                 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
943         } else {
944                 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
945                                      << endl;
946         }
947
948         // Just to be sure. (Asger)
949         texrow().newline();
950
951         lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
952         lyxerr[Debug::INFO] << "Row count was " << texrow().rows() - 1
953                             << '.' << endl;
954 }
955
956
957 bool Buffer::isLatex() const
958 {
959         return params().getLyXTextClass().outputType() == LATEX;
960 }
961
962
963 bool Buffer::isLiterate() const
964 {
965         return params().getLyXTextClass().outputType() == LITERATE;
966 }
967
968
969 bool Buffer::isDocBook() const
970 {
971         return params().getLyXTextClass().outputType() == DOCBOOK;
972 }
973
974
975 void Buffer::makeDocBookFile(string const & fname,
976                               OutputParams const & runparams,
977                               bool const body_only)
978 {
979         lyxerr[Debug::LATEX] << "makeDocBookFile..." << endl;
980
981         ofstream ofs;
982         if (!openFileWrite(ofs, fname))
983                 return;
984
985         writeDocBookSource(ofs, fname, runparams, body_only);
986
987         ofs.close();
988         if (ofs.fail())
989                 lyxerr << "File '" << fname << "' was not closed properly." << endl;
990 }
991
992
993 void Buffer::writeDocBookSource(ostream & os, string const & fname,
994                              OutputParams const & runparams,
995                              bool const only_body)
996 {
997         LaTeXFeatures features(*this, params(), runparams);
998         validate(features);
999
1000         texrow().reset();
1001
1002         LyXTextClass const & tclass = params().getLyXTextClass();
1003         string const & top_element = tclass.latexname();
1004
1005         if (!only_body) {
1006                 if (runparams.flavor == OutputParams::XML)
1007                         os << "<?xml version=\"1.0\" encoding=\""
1008                             << params().language->encoding()->name() << "\"?>\n";
1009
1010                 os << "<!DOCTYPE " << top_element << " ";
1011
1012                 if (! tclass.class_header().empty()) os << tclass.class_header();
1013                 else if (runparams.flavor == OutputParams::XML)
1014                         os << "PUBLIC \"-//OASIS//DTD DocBook XML//EN\" "
1015                             << "\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\"";
1016                 else
1017                         os << " PUBLIC \"-//OASIS//DTD DocBook V4.2//EN\"";
1018
1019                 string preamble = params().preamble;
1020                 if (runparams.flavor != OutputParams::XML ) {
1021                         preamble += "<!ENTITY % output.print.png \"IGNORE\">\n";
1022                         preamble += "<!ENTITY % output.print.pdf \"IGNORE\">\n";
1023                         preamble += "<!ENTITY % output.print.eps \"IGNORE\">\n";
1024                         preamble += "<!ENTITY % output.print.bmp \"IGNORE\">\n";
1025                 }
1026
1027                 string const name = runparams.nice ? changeExtension(pimpl_->filename, ".sgml")
1028                          : fname;
1029                 preamble += features.getIncludedFiles(name);
1030                 preamble += features.getLyXSGMLEntities();
1031
1032                 if (!preamble.empty()) {
1033                         os << "\n [ " << preamble << " ]";
1034                 }
1035                 os << ">\n\n";
1036         }
1037
1038         string top = top_element;
1039         top += " lang=\"";
1040         if (runparams.flavor == OutputParams::XML)
1041                 top += params().language->code();
1042         else
1043                 top += params().language->code().substr(0,2);
1044         top += '"';
1045
1046         if (!params().options.empty()) {
1047                 top += ' ';
1048                 top += params().options;
1049         }
1050
1051         os << "<!-- " << ((runparams.flavor == OutputParams::XML)? "XML" : "SGML")
1052             << " file was created by LyX " << lyx_version
1053             << "\n  See http://www.lyx.org/ for more information -->\n";
1054
1055         params().getLyXTextClass().counters().reset();
1056
1057         sgml::openTag(os, top);
1058         os << '\n';
1059         docbookParagraphs(paragraphs(), *this, os, runparams);
1060         sgml::closeTag(os, top_element);
1061 }
1062
1063
1064 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1065 // Other flags: -wall -v0 -x
1066 int Buffer::runChktex()
1067 {
1068         busy(true);
1069
1070         // get LaTeX-Filename
1071         string const name = getLatexName();
1072         string const path = temppath();
1073         string const org_path = filePath();
1074
1075         Path p(path); // path to LaTeX file
1076         message(_("Running chktex..."));
1077
1078         // Generate the LaTeX file if neccessary
1079         OutputParams runparams;
1080         runparams.flavor = OutputParams::LATEX;
1081         runparams.nice = false;
1082         makeLaTeXFile(name, org_path, runparams);
1083
1084         TeXErrors terr;
1085         Chktex chktex(lyxrc.chktex_command, name, filePath());
1086         int const res = chktex.run(terr); // run chktex
1087
1088         if (res == -1) {
1089                 Alert::error(_("chktex failure"),
1090                              _("Could not run chktex successfully."));
1091         } else if (res > 0) {
1092                 // Fill-in the error list with the TeX errors
1093                 bufferErrors(*this, terr, errorLists_["ChkTex"]);
1094         }
1095
1096         busy(false);
1097
1098         errors("ChkTeX");
1099
1100         return res;
1101 }
1102
1103
1104 void Buffer::validate(LaTeXFeatures & features) const
1105 {
1106         LyXTextClass const & tclass = params().getLyXTextClass();
1107
1108         if (features.isAvailable("dvipost") && params().tracking_changes
1109             && params().output_changes)
1110                 features.require("dvipost");
1111
1112         // AMS Style is at document level
1113         if (params().use_amsmath == BufferParams::AMS_ON
1114             || tclass.provides(LyXTextClass::amsmath))
1115                 features.require("amsmath");
1116
1117         for_each(paragraphs().begin(), paragraphs().end(),
1118                  boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1119
1120         // the bullet shapes are buffer level not paragraph level
1121         // so they are tested here
1122         for (int i = 0; i < 4; ++i) {
1123                 if (params().user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
1124                         int const font = params().user_defined_bullet(i).getFont();
1125                         if (font == 0) {
1126                                 int const c = params()
1127                                         .user_defined_bullet(i)
1128                                         .getCharacter();
1129                                 if (c == 16
1130                                    || c == 17
1131                                    || c == 25
1132                                    || c == 26
1133                                    || c == 31) {
1134                                         features.require("latexsym");
1135                                 }
1136                         } else if (font == 1) {
1137                                 features.require("amssymb");
1138                         } else if ((font >= 2 && font <= 5)) {
1139                                 features.require("pifont");
1140                         }
1141                 }
1142         }
1143
1144         if (lyxerr.debugging(Debug::LATEX)) {
1145                 features.showStruct();
1146         }
1147 }
1148
1149
1150 void Buffer::getLabelList(vector<string> & list) const
1151 {
1152         /// if this is a child document and the parent is already loaded
1153         /// Use the parent's list instead  [ale990407]
1154         Buffer const * tmp = getMasterBuffer();
1155         if (!tmp) {
1156                 lyxerr << "getMasterBuffer() failed!" << endl;
1157                 BOOST_ASSERT(tmp);
1158         }
1159         if (tmp != this) {
1160                 tmp->getLabelList(list);
1161                 return;
1162         }
1163
1164         for (InsetIterator it = inset_iterator_begin(inset()); it; ++it)
1165                 it.nextInset()->getLabelList(*this, list);
1166 }
1167
1168
1169 // This is also a buffer property (ale)
1170 void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys)
1171         const
1172 {
1173         /// if this is a child document and the parent is already loaded
1174         /// use the parent's list instead  [ale990412]
1175         Buffer const * tmp = getMasterBuffer();
1176         BOOST_ASSERT(tmp);
1177         if (tmp != this) {
1178                 tmp->fillWithBibKeys(keys);
1179                 return;
1180         }
1181
1182         for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
1183                 if (it->lyxCode() == InsetBase::BIBTEX_CODE) {
1184                         InsetBibtex const & inset =
1185                                 dynamic_cast<InsetBibtex const &>(*it);
1186                         inset.fillWithBibKeys(*this, keys);
1187                 } else if (it->lyxCode() == InsetBase::INCLUDE_CODE) {
1188                         InsetInclude const & inset =
1189                                 dynamic_cast<InsetInclude const &>(*it);
1190                         inset.fillWithBibKeys(*this, keys);
1191                 } else if (it->lyxCode() == InsetBase::BIBITEM_CODE) {
1192                         InsetBibitem const & inset =
1193                                 dynamic_cast<InsetBibitem const &>(*it);
1194                         string const key = inset.getContents();
1195                         string const opt = inset.getOptions();
1196                         string const ref; // = pit->asString(this, false);
1197                         string const info = opt + "TheBibliographyRef" + ref;
1198                         keys.push_back(pair<string, string>(key, info));
1199                 }
1200         }
1201 }
1202
1203
1204 void Buffer::updateBibfilesCache()
1205 {
1206         // if this is a child document and the parent is already loaded
1207         // update the parent's cache instead
1208         Buffer * tmp = getMasterBuffer();
1209         BOOST_ASSERT(tmp);
1210         if (tmp != this) {
1211                 tmp->updateBibfilesCache();
1212                 return;
1213         }
1214
1215         bibfilesCache_.clear();
1216         for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
1217                 if (it->lyxCode() == InsetBase::BIBTEX_CODE) {
1218                         InsetBibtex const & inset =
1219                                 dynamic_cast<InsetBibtex const &>(*it);
1220                         vector<string> const bibfiles = inset.getFiles(*this);
1221                         bibfilesCache_.insert(bibfilesCache_.end(),
1222                                 bibfiles.begin(),
1223                                 bibfiles.end());
1224                 } else if (it->lyxCode() == InsetBase::INCLUDE_CODE) {
1225                         InsetInclude & inset =
1226                                 dynamic_cast<InsetInclude &>(*it);
1227                         inset.updateBibfilesCache(*this);
1228                         vector<string> const & bibfiles =
1229                                         inset.getBibfilesCache(*this);
1230                         bibfilesCache_.insert(bibfilesCache_.end(),
1231                                 bibfiles.begin(),
1232                                 bibfiles.end());
1233                 }
1234         }
1235 }
1236
1237
1238 vector<string> const & Buffer::getBibfilesCache() const
1239 {
1240         // if this is a child document and the parent is already loaded
1241         // use the parent's cache instead
1242         Buffer const * tmp = getMasterBuffer();
1243         BOOST_ASSERT(tmp);
1244         if (tmp != this)
1245                 return tmp->getBibfilesCache();
1246
1247         return bibfilesCache_;
1248 }
1249
1250
1251 bool Buffer::isDepClean(string const & name) const
1252 {
1253         DepClean::const_iterator const it = pimpl_->dep_clean.find(name);
1254         if (it == pimpl_->dep_clean.end())
1255                 return true;
1256         return it->second;
1257 }
1258
1259
1260 void Buffer::markDepClean(string const & name)
1261 {
1262         pimpl_->dep_clean[name] = true;
1263 }
1264
1265
1266 bool Buffer::dispatch(string const & command, bool * result)
1267 {
1268         return dispatch(lyxaction.lookupFunc(command), result);
1269 }
1270
1271
1272 bool Buffer::dispatch(FuncRequest const & func, bool * result)
1273 {
1274         bool dispatched = true;
1275
1276         switch (func.action) {
1277                 case LFUN_BUFFER_EXPORT: {
1278                         bool const tmp = Exporter::Export(this, lyx::to_utf8(func.argument()), false);
1279                         if (result)
1280                                 *result = tmp;
1281                         break;
1282                 }
1283
1284                 default:
1285                         dispatched = false;
1286         }
1287         return dispatched;
1288 }
1289
1290
1291 void Buffer::changeLanguage(Language const * from, Language const * to)
1292 {
1293         BOOST_ASSERT(from);
1294         BOOST_ASSERT(to);
1295
1296         // Take care of l10n/i18n
1297         updateDocLang(to);
1298
1299         for_each(par_iterator_begin(),
1300                  par_iterator_end(),
1301                  bind(&Paragraph::changeLanguage, _1, params(), from, to));
1302
1303         text().current_font.setLanguage(to);
1304         text().real_current_font.setLanguage(to);
1305 }
1306
1307
1308 void Buffer::updateDocLang(Language const * nlang)
1309 {
1310         BOOST_ASSERT(nlang);
1311
1312         pimpl_->messages.reset(new Messages(nlang->code()));
1313
1314         updateLabels(*this);
1315 }
1316
1317
1318 bool Buffer::isMultiLingual() const
1319 {
1320         ParConstIterator end = par_iterator_end();
1321         for (ParConstIterator it = par_iterator_begin(); it != end; ++it)
1322                 if (it->isMultiLingual(params()))
1323                         return true;
1324
1325         return false;
1326 }
1327
1328
1329 ParIterator Buffer::getParFromID(int const id) const
1330 {
1331         ParConstIterator it = par_iterator_begin();
1332         ParConstIterator const end = par_iterator_end();
1333
1334         if (id < 0) {
1335                 // John says this is called with id == -1 from undo
1336                 lyxerr << "getParFromID(), id: " << id << endl;
1337                 return end;
1338         }
1339
1340         for (; it != end; ++it)
1341                 if (it->id() == id)
1342                         return it;
1343
1344         return end;
1345 }
1346
1347
1348 bool Buffer::hasParWithID(int const id) const
1349 {
1350         ParConstIterator const it = getParFromID(id);
1351         return it != par_iterator_end();
1352 }
1353
1354
1355 ParIterator Buffer::par_iterator_begin()
1356 {
1357         return ::par_iterator_begin(inset());
1358 }
1359
1360
1361 ParIterator Buffer::par_iterator_end()
1362 {
1363         return ::par_iterator_end(inset());
1364 }
1365
1366
1367 ParConstIterator Buffer::par_iterator_begin() const
1368 {
1369         return ::par_const_iterator_begin(inset());
1370 }
1371
1372
1373 ParConstIterator Buffer::par_iterator_end() const
1374 {
1375         return ::par_const_iterator_end(inset());
1376 }
1377
1378
1379 Language const * Buffer::getLanguage() const
1380 {
1381         return params().language;
1382 }
1383
1384
1385 string const Buffer::B_(string const & l10n) const
1386 {
1387         if (pimpl_->messages.get()) {
1388                 return pimpl_->messages->get(l10n);
1389         }
1390
1391         return _(l10n);
1392 }
1393
1394
1395 bool Buffer::isClean() const
1396 {
1397         return pimpl_->lyx_clean;
1398 }
1399
1400
1401 bool Buffer::isBakClean() const
1402 {
1403         return pimpl_->bak_clean;
1404 }
1405
1406
1407 void Buffer::markClean() const
1408 {
1409         if (!pimpl_->lyx_clean) {
1410                 pimpl_->lyx_clean = true;
1411                 updateTitles();
1412         }
1413         // if the .lyx file has been saved, we don't need an
1414         // autosave
1415         pimpl_->bak_clean = true;
1416 }
1417
1418
1419 void Buffer::markBakClean()
1420 {
1421         pimpl_->bak_clean = true;
1422 }
1423
1424
1425 void Buffer::setUnnamed(bool flag)
1426 {
1427         pimpl_->unnamed = flag;
1428 }
1429
1430
1431 bool Buffer::isUnnamed() const
1432 {
1433         return pimpl_->unnamed;
1434 }
1435
1436
1437 #ifdef WITH_WARNINGS
1438 #warning this function should be moved to buffer_pimpl.C
1439 #endif
1440 void Buffer::markDirty()
1441 {
1442         if (pimpl_->lyx_clean) {
1443                 pimpl_->lyx_clean = false;
1444                 updateTitles();
1445         }
1446         pimpl_->bak_clean = false;
1447
1448         DepClean::iterator it = pimpl_->dep_clean.begin();
1449         DepClean::const_iterator const end = pimpl_->dep_clean.end();
1450
1451         for (; it != end; ++it) {
1452                 it->second = false;
1453         }
1454 }
1455
1456
1457 string const & Buffer::fileName() const
1458 {
1459         return pimpl_->filename;
1460 }
1461
1462
1463 string const & Buffer::filePath() const
1464 {
1465         return params().filepath;
1466 }
1467
1468
1469 bool Buffer::isReadonly() const
1470 {
1471         return pimpl_->read_only;
1472 }
1473
1474
1475 void Buffer::setParentName(string const & name)
1476 {
1477         params().parentname = name;
1478 }
1479
1480
1481 Buffer const * Buffer::getMasterBuffer() const
1482 {
1483         if (!params().parentname.empty()
1484             && bufferlist.exists(params().parentname)) {
1485                 Buffer const * buf = bufferlist.getBuffer(params().parentname);
1486                 if (buf)
1487                         return buf->getMasterBuffer();
1488         }
1489
1490         return this;
1491 }
1492
1493
1494 Buffer * Buffer::getMasterBuffer()
1495 {
1496         if (!params().parentname.empty()
1497             && bufferlist.exists(params().parentname)) {
1498                 Buffer * buf = bufferlist.getBuffer(params().parentname);
1499                 if (buf)
1500                         return buf->getMasterBuffer();
1501         }
1502
1503         return this;
1504 }
1505
1506
1507 MacroData const & Buffer::getMacro(std::string const & name) const
1508 {
1509         return pimpl_->macros.get(name);
1510 }
1511
1512
1513 bool Buffer::hasMacro(string const & name) const
1514 {
1515         return pimpl_->macros.has(name);
1516 }
1517
1518
1519 void Buffer::insertMacro(string const & name, MacroData const & data)
1520 {
1521         MacroTable::globalMacros().insert(name, data);
1522         pimpl_->macros.insert(name, data);
1523 }
1524
1525
1526 void Buffer::buildMacros()
1527 {
1528         // Start with global table.
1529         pimpl_->macros = MacroTable::globalMacros();
1530
1531         // Now add our own.
1532         ParagraphList const & pars = text().paragraphs();
1533         for (size_t i = 0, n = pars.size(); i != n; ++i) {
1534                 //lyxerr << "searching main par " << i
1535                 //      << " for macro definitions" << std::endl;
1536                 InsetList const & insets = pars[i].insetlist;
1537                 InsetList::const_iterator it = insets.begin();
1538                 InsetList::const_iterator end = insets.end();
1539                 for ( ; it != end; ++it) {
1540                         //lyxerr << "found inset code " << it->inset->lyxCode() << std::endl;
1541                         if (it->inset->lyxCode() == InsetBase::MATHMACRO_CODE) {
1542                                 MathMacroTemplate const & mac
1543                                         = static_cast<MathMacroTemplate const &>(*it->inset);
1544                                 insertMacro(mac.name(), mac.asMacroData());
1545                         }
1546                 }
1547         }
1548 }
1549
1550
1551 void Buffer::saveCursor(StableDocIterator cur, StableDocIterator anc)
1552 {
1553         cursor_ = cur;
1554         anchor_ = anc;
1555 }
1556
1557
1558 void Buffer::changeRefsIfUnique(string const & from, string const & to)
1559 {
1560         // Check if the label 'from' appears more than once
1561         vector<string> labels;
1562         getLabelList(labels);
1563
1564         if (lyx::count(labels.begin(), labels.end(), from) > 1)
1565                 return;
1566
1567         InsetBase::Code code = InsetBase::REF_CODE;
1568
1569         ParIterator it = par_iterator_begin();
1570         ParIterator end = par_iterator_end();
1571         for ( ; it != end; ++it) {
1572                 bool changed_inset = false;
1573                 for (InsetList::iterator it2 = it->insetlist.begin();
1574                      it2 != it->insetlist.end(); ++it2) {
1575                         if (it2->inset->lyxCode() == code) {
1576                                 InsetCommand * inset = static_cast<InsetCommand *>(it2->inset);
1577                                 if (inset->getContents() == from) {
1578                                         inset->setContents(to);
1579                                         //inset->setButtonLabel();
1580                                         changed_inset = true;
1581                                 }
1582                         }
1583                 }
1584         }
1585 }
1586
1587
1588 void Buffer::getSourceCode(ostream & os, lyx::pit_type par_begin, lyx::pit_type par_end, bool full_source)
1589 {
1590         OutputParams runparams;
1591         runparams.nice = true;
1592         runparams.flavor = OutputParams::LATEX;
1593         runparams.linelen = lyxrc.ascii_linelen;
1594         // No side effect of file copying and image conversion
1595         runparams.dryrun = true;
1596
1597         if (full_source) {
1598                 os << "% Preview source code\n\n";
1599                 if (isLatex()) 
1600                         writeLaTeXSource(os, filePath(), runparams, true, true);
1601                 else 
1602                         writeDocBookSource(os, fileName(), runparams, false);
1603         } else {
1604                 runparams.par_begin = par_begin;
1605                 runparams.par_end = par_end;
1606                 if (par_begin + 1 == par_end)
1607                         os << "% Preview source code for paragraph " << par_begin << "\n\n";
1608                 else
1609                         os << "% Preview source code from paragraph " << par_begin << " to " << par_end - 1 << "\n\n";
1610                 // output paragraphs
1611                 if (isLatex()) {
1612                         texrow().reset();
1613                         latexParagraphs(*this, paragraphs(), os, texrow(), runparams);
1614                 } else // DocBook
1615                         docbookParagraphs(paragraphs(), *this, os, runparams);
1616         }
1617 }
1618
1619
1620 ErrorList const & Buffer::errorList(string const & type) const
1621 {
1622         static ErrorList const emptyErrorList;
1623         std::map<std::string, ErrorList>::const_iterator I = errorLists_.find(type);
1624         if (I == errorLists_.end())
1625                 return emptyErrorList;
1626
1627         return I->second;
1628 }
1629
1630
1631 ErrorList & Buffer::errorList(string const & type)
1632 {
1633         return errorLists_[type];
1634 }