1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * This file is Copyright 1996-1999
12 * ======================================================
24 #include <sys/types.h>
34 #pragma implementation "buffer.h"
38 #include "bufferlist.h"
40 #include "lyx_gui_misc.h"
41 #include "LyXAction.h"
44 #include "tex-strings.h"
46 #include "bufferview_funcs.h"
47 #include "minibuffer.h"
50 #include "mathed/formulamacro.h"
51 #include "insets/lyxinset.h"
52 #include "insets/inseterror.h"
53 #include "insets/insetlabel.h"
54 #include "insets/insetref.h"
55 #include "insets/inseturl.h"
56 #include "insets/insetinfo.h"
57 #include "insets/insetquotes.h"
58 #include "insets/insetlatexaccent.h"
59 #include "insets/insetbib.h"
60 #include "insets/insetcite.h"
61 #include "insets/insetexternal.h"
62 #include "insets/insetindex.h"
63 #include "insets/insetinclude.h"
64 #include "insets/insettoc.h"
65 #include "insets/insetparent.h"
66 #include "insets/insetspecialchar.h"
67 #include "insets/figinset.h"
68 #include "insets/insettext.h"
69 #include "insets/insetert.h"
70 #include "insets/insetgraphics.h"
71 #include "insets/insetfoot.h"
72 #include "insets/insetmarginal.h"
73 #include "insets/insetminipage.h"
74 #include "insets/insetfloat.h"
75 #include "insets/insetlist.h"
76 #include "insets/insettabular.h"
77 #include "insets/insettheorem.h"
78 #include "insets/insetcaption.h"
79 #include "support/filetools.h"
80 #include "support/path.h"
85 #include "LaTeXFeatures.h"
86 #include "support/syscall.h"
87 #include "support/lyxlib.h"
88 #include "support/FileInfo.h"
89 #include "support/lyxmanip.h"
93 #include "lyx_gui_misc.h" // WarnReadonly()
94 #include "frontends/Dialogs.h"
98 #include "converter.h"
108 using std::make_pair;
113 // all these externs should eventually be removed.
114 extern BufferList bufferlist;
116 extern LyXAction lyxaction;
119 static const int LYX_FORMAT = 218;
121 extern int tex_code_break_column;
124 Buffer::Buffer(string const & file, bool ronly)
126 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
128 filepath = OnlyPath(file);
137 if (read_only || (lyxrc.use_tempdir)) {
138 tmppath = CreateBufferTmpDir();
139 } else tmppath.erase();
145 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
146 // here the buffer should take care that it is
147 // saved properly, before it goes into the void.
149 // make sure that views using this buffer
154 if (!tmppath.empty()) {
155 DestroyBufferTmpDir(tmppath);
158 LyXParagraph * par = paragraph;
159 LyXParagraph * tmppar;
168 tmppar = par->next();
177 string const Buffer::getLatexName(bool no_path) const
180 return OnlyFilename(ChangeExtension(MakeLatexName(filename),
183 return ChangeExtension(MakeLatexName(filename),
187 pair<Buffer::LogType, string> const Buffer::getLogName(void) const
189 string filename, fname, bname, path;
191 filename = getLatexName(false);
193 if (filename.empty())
194 return make_pair(Buffer::latexlog, string());
196 path = OnlyPath(filename);
198 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1))
201 fname = AddName(path, OnlyFilename(ChangeExtension(filename, ".log")));
202 bname = AddName(path, OnlyFilename(ChangeExtension(filename,
203 formats.Extension("literate") + ".out")));
205 // If no Latex log or Build log is newer, show Build log
207 FileInfo f_fi(fname), b_fi(bname);
210 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
211 lyxerr[Debug::FILES] << "Log name calculated as : " << bname << endl;
212 return make_pair(Buffer::buildlog, bname);
214 lyxerr[Debug::FILES] << "Log name calculated as : " << fname << endl;
215 return make_pair(Buffer::latexlog, fname);
218 void Buffer::setReadonly(bool flag)
220 if (read_only != flag) {
223 users->owner()->getDialogs()->updateBufferDependent(false);
226 WarnReadonly(filename);
231 bool Buffer::saveParamsAsDefaults() // const
233 string const fname = AddName(AddPath(user_lyxdir, "templates/"),
235 Buffer defaults = Buffer(fname);
237 // Use the current buffer's parameters as default
238 defaults.params = params;
240 // add an empty paragraph. Is this enough?
241 defaults.paragraph = new LyXParagraph;
243 return defaults.writeFile(defaults.filename, false);
247 /// Update window titles of all users
248 // Should work on a list
249 void Buffer::updateTitles() const
251 if (users) users->owner()->updateWindowTitle();
255 /// Reset autosave timer of all users
256 // Should work on a list
257 void Buffer::resetAutosaveTimers() const
259 if (users) users->owner()->resetAutosaveTimer();
263 void Buffer::setFileName(string const & newfile)
265 filename = MakeAbsPath(newfile);
266 filepath = OnlyPath(filename);
267 setReadonly(IsFileWriteable(filename) == 0);
272 // candidate for move to BufferView
273 // (at least some parts in the beginning of the func)
276 // changed to be public and have one parameter
277 // if par = 0 normal behavior
278 // else insert behavior
279 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
280 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
283 char depth = 0; // signed or unsigned?
285 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
286 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
288 bool the_end_read = false;
290 LyXParagraph * return_par = 0;
291 LyXFont font(LyXFont::ALL_INHERIT, params.language);
292 if (file_format < 216 && params.language->lang() == "hebrew")
293 font.setLanguage(default_language);
294 // If we are inserting, we cheat and get a token in advance
295 bool has_token = false;
299 par = new LyXParagraph;
301 users->text->BreakParagraph(users);
302 return_par = users->text->FirstParagraph();
305 // We don't want to adopt the parameters from the
306 // document we insert, so we skip until the text begins:
309 pretoken = lex.GetString();
310 if (pretoken == "\\layout") {
322 pretoken = lex.GetString();
325 if (pretoken.empty()) continue;
328 parseSingleLyXformat2Token(lex, par, return_par,
329 pretoken, pos, depth,
341 paragraph = return_par;
347 // We'll remove this later. (Lgb)
348 static string last_inset_read;
352 Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
353 LyXParagraph *& return_par,
354 string const & token, int & pos,
355 char & depth, LyXFont & font
357 , LyXParagraph::footnote_flag & footnoteflag,
358 LyXParagraph::footnote_kind & footnotekind
362 bool the_end_read = false;
364 if (token[0] != '\\') {
365 for (string::const_iterator cit = token.begin();
366 cit != token.end(); ++cit) {
367 par->InsertChar(pos, (*cit), font);
370 } else if (token == "\\i") {
371 Inset * inset = new InsetLatexAccent;
372 inset->Read(this, lex);
373 par->InsertInset(pos, inset, font);
375 } else if (token == "\\layout") {
381 par = new LyXParagraph(par);
385 string const layoutname = lex.GetString();
386 pair<bool, LyXTextClass::LayoutList::size_type> pp
387 = textclasslist.NumberOfLayout(params.textclass,
390 par->layout = pp.second;
391 } else { // layout not found
392 // use default layout "Standard" (0)
395 // Test whether the layout is obsolete.
396 LyXLayout const & layout =
397 textclasslist.Style(params.textclass,
399 if (!layout.obsoleted_by().empty())
401 textclasslist.NumberOfLayout(params.textclass,
402 layout.obsoleted_by()).second;
403 par->footnoteflag = footnoteflag;
404 par->footnotekind = footnotekind;
405 par->params.depth(depth);
406 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
407 if (file_format < 216 && params.language->lang() == "hebrew")
408 font.setLanguage(default_language);
411 string const layoutname = lex.GetString();
412 pair<bool, LyXTextClass::LayoutList::size_type> pp
413 = textclasslist.NumberOfLayout(params.textclass,
417 // The is the compability reading of layout caption.
418 // It can be removed in LyX version 1.3.0. (Lgb)
419 if (compare_no_case(layoutname, "caption") == 0) {
420 // We expect that the par we are now working on is
421 // really inside a InsetText inside a InsetFloat.
422 // We also know that captions can only be
423 // one paragraph. (Lgb)
425 // We should now read until the next "\layout"
427 // This is probably not good enough, what if the
428 // caption is the last par in the document (Lgb)
429 istream & ist = lex.getStream();
435 if (prefixIs(line, "\\layout")) {
439 if (prefixIs(line, "\\begin_inset"))
441 if (prefixIs(line, "\\end_inset")) {
452 // Now we should have the whole layout in ss
453 // we should now be able to give this to the
455 ss << "\\end_inset\n";
457 // This seems like a bug in stringstream.
458 // We really should be able to use ss
460 istringstream is(ss.str());
462 tmplex.setStream(is);
463 Inset * inset = new InsetCaption;
464 inset->Read(this, tmplex);
465 par->InsertInset(pos, inset, font);
469 // BEGIN pextra_minipage compability
470 // This should be removed in 1.3.x (Lgb)
472 // This compability code is not perfect. In a couple
473 // of rand cases it fails. When the minipage par is
474 // the first par in the document, and when there are
475 // none or only one regular paragraphs after the
476 // minipage. Currently I am not investing any effort
477 // in fixing those cases.
478 static LyXParagraph * minipar = 0;
481 && par->params.pextraType() == LyXParagraph::PEXTRA_MINIPAGE) {
482 lyxerr << "minipages in a row" << endl;
483 if (par->params.pextraStartMinipage()) {
484 lyxerr << "start new minipage" << endl;
485 // minipages in a row
486 minipar->previous()->next(par);
487 par->previous()->next(0);
488 par->previous(minipar->previous());
489 InsetMinipage * mini = new InsetMinipage;
490 // Before we insert the list of
491 // minipages into the inset we have
492 // to clean up a bit.
493 // This is not quite correct yet since
494 // we do want to use some of these
495 // parameters to set options in the
497 LyXParagraph * tmp = minipar;
499 tmp->params.pextraType(0);
500 tmp->params.pextraWidth(string());
501 tmp->params.pextraWidthp(string());
502 tmp->params.pextraAlignment(0);
503 tmp->params.pextraHfill(false);
504 tmp->params.pextraStartMinipage(false);
508 mini->inset->par = minipar;
509 par->previous()->InsertInset(par->previous()->size(), mini);
512 lyxerr << "new minipage par" << endl;
513 //nothing to do just continue reading
516 } else if (minipar) {
517 lyxerr << "last minipage par read" << endl;
518 // The last paragraph read was not part of a
519 // minipage but the par linked list is...
520 // So we need to remove the last par from the
521 // rest, insert the rest of the paragraphs into
522 // a InsetMinipage, insert this minipage into
523 // prevpar, append the current par to prevpar
525 par->previous()->next(0);
526 par->previous(minipar->previous());
527 minipar->previous()->next(par);
528 minipar->previous(0);
529 InsetMinipage * mini = new InsetMinipage;
531 // Before we insert the list of
532 // minipages into the inset we have
533 // to clean up a bit.
534 // This is not quite correct yet since we
535 // do want to use some of these parameters
536 // to set options in the minipage isnet.
537 LyXParagraph * tmp = minipar;
539 tmp->params.pextraType(0);
540 tmp->params.pextraWidth(string());
541 tmp->params.pextraWidthp(string());
542 tmp->params.pextraAlignment(0);
543 tmp->params.pextraHfill(false);
544 tmp->params.pextraStartMinipage(false);
548 mini->inset->par = minipar;
549 par->previous()->InsertInset(par->previous()->size(), mini);
551 } else if (par->params.pextraType() == LyXParagraph::PEXTRA_MINIPAGE) {
553 // par is the first paragraph in a minipage
554 lyxerr << "begin minipage" << endl;
558 // End of pextra_minipage compability
564 par = new LyXParagraph(par);
568 par->layout = pp.second;
571 // use default layout "Standard" (0)
574 // Test whether the layout is obsolete.
575 LyXLayout const & layout =
576 textclasslist.Style(params.textclass,
578 if (!layout.obsoleted_by().empty())
579 par->layout = textclasslist
580 .NumberOfLayout(params.textclass,
581 layout.obsoleted_by())
583 par->params.depth(depth);
584 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
585 if (file_format < 216
586 && params.language->lang() == "hebrew")
587 font.setLanguage(default_language);
593 } else if (token == "\\end_float") {
598 par = new LyXParagraph(par);
600 footnotekind = LyXParagraph::FOOTNOTE;
601 footnoteflag = LyXParagraph::NO_FOOTNOTE;
604 par->layout = LYX_DUMMY_LAYOUT;
605 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
606 if (file_format < 216 && params.language->lang() == "hebrew")
607 font.setLanguage(default_language);
608 } else if (token == "\\begin_float") {
609 int tmpret = lex.FindToken(string_footnotekinds);
610 if (tmpret == -1) ++tmpret;
611 if (tmpret != LYX_LAYOUT_DEFAULT)
612 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
613 if (footnotekind == LyXParagraph::FOOTNOTE
614 || footnotekind == LyXParagraph::MARGIN)
615 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
617 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
619 } else if (token == "\\begin_float") {
620 // This is the compability reader. It can be removed in
621 // LyX version 1.3.0. (Lgb)
623 string const tmptok = lex.GetString();
624 //lyxerr << "old float: " << tmptok << endl;
627 stringstream old_float;
629 if (tmptok == "footnote") {
630 inset = new InsetFoot;
631 } else if (tmptok == "margin") {
632 inset = new InsetMarginal;
633 } else if (tmptok == "fig") {
634 inset = new InsetFloat("figure");
635 old_float << "placement htbp\n";
636 } else if (tmptok == "tab") {
637 inset = new InsetFloat("table");
638 old_float << "placement htbp\n";
639 } else if (tmptok == "alg") {
640 inset = new InsetFloat("algorithm");
641 old_float << "placement htbp\n";
642 } else if (tmptok == "wide-fig") {
643 InsetFloat * tmp = new InsetFloat("figure");
646 old_float << "placement htbp\n";
647 } else if (tmptok == "wide-tab") {
648 InsetFloat * tmp = new InsetFloat("table");
651 old_float << "placement htbp\n";
654 if (!inset) return false; // no end read yet
656 old_float << "collapsed true\n";
658 // Here we need to check for \end_deeper and handle that
659 // before we do the footnote parsing.
660 // This _is_ a hack! (Lgb)
663 string const tmp = lex.GetString();
664 if (tmp == "\\end_deeper") {
665 //lyxerr << "\\end_deeper caught!" << endl;
667 lex.printError("\\end_deeper: "
668 "depth is already null");
673 old_float << tmp << ' ';
678 old_float << lex.getLongString("\\end_float")
679 << "\n\\end_inset\n";
680 //lyxerr << "Float Body:\n" << old_float.str() << endl;
681 // That this does not work seems like a bug
682 // in stringstream. (Lgb)
683 istringstream istr(old_float.str());
685 nylex.setStream(istr);
686 inset->Read(this, nylex);
687 par->InsertInset(pos, inset, font);
690 } else if (token == "\\begin_deeper") {
692 } else if (token == "\\end_deeper") {
694 lex.printError("\\end_deeper: "
695 "depth is already null");
699 } else if (token == "\\begin_preamble") {
700 params.readPreamble(lex);
701 } else if (token == "\\textclass") {
703 pair<bool, LyXTextClassList::size_type> pp =
704 textclasslist.NumberOfClass(lex.GetString());
706 params.textclass = pp.second;
708 WriteAlert(string(_("Textclass error")),
709 string(_("The document uses an unknown textclass \"")) +
710 lex.GetString() + string("\"."),
711 string(_("LyX will not be able to produce output correctly.")));
712 params.textclass = 0;
714 if (!textclasslist.Load(params.textclass)) {
715 // if the textclass wasn't loaded properly
716 // we need to either substitute another
717 // or stop loading the file.
718 // I can substitute but I don't see how I can
719 // stop loading... ideas?? ARRae980418
720 WriteAlert(_("Textclass Loading Error!"),
721 string(_("Can't load textclass ")) +
722 textclasslist.NameOfClass(params.textclass),
723 _("-- substituting default"));
724 params.textclass = 0;
726 } else if (token == "\\options") {
728 params.options = lex.GetString();
729 } else if (token == "\\language") {
730 params.readLanguage(lex);
731 } else if (token == "\\fontencoding") {
733 } else if (token == "\\inputencoding") {
735 params.inputenc = lex.GetString();
736 } else if (token == "\\graphics") {
737 params.readGraphicsDriver(lex);
738 } else if (token == "\\fontscheme") {
740 params.fonts = lex.GetString();
741 } else if (token == "\\noindent") {
742 par->params.noindent(true);
743 } else if (token == "\\fill_top") {
744 par->params.spaceTop(VSpace(VSpace::VFILL));
745 } else if (token == "\\fill_bottom") {
746 par->params.spaceBottom(VSpace(VSpace::VFILL));
747 } else if (token == "\\line_top") {
748 par->params.lineTop(true);
749 } else if (token == "\\line_bottom") {
750 par->params.lineBottom(true);
751 } else if (token == "\\pagebreak_top") {
752 par->params.pagebreakTop(true);
753 } else if (token == "\\pagebreak_bottom") {
754 par->params.pagebreakBottom(true);
755 } else if (token == "\\start_of_appendix") {
756 par->params.startOfAppendix(true);
757 } else if (token == "\\paragraph_separation") {
758 int tmpret = lex.FindToken(string_paragraph_separation);
759 if (tmpret == -1) ++tmpret;
760 if (tmpret != LYX_LAYOUT_DEFAULT)
761 params.paragraph_separation =
762 static_cast<BufferParams::PARSEP>(tmpret);
763 } else if (token == "\\defskip") {
765 params.defskip = VSpace(lex.GetString());
766 } else if (token == "\\epsfig") { // obsolete
767 // Indeed it is obsolete, but we HAVE to be backwards
768 // compatible until 0.14, because otherwise all figures
769 // in existing documents are irretrivably lost. (Asger)
770 params.readGraphicsDriver(lex);
771 } else if (token == "\\quotes_language") {
772 int tmpret = lex.FindToken(string_quotes_language);
773 if (tmpret == -1) ++tmpret;
774 if (tmpret != LYX_LAYOUT_DEFAULT) {
775 InsetQuotes::quote_language tmpl =
776 InsetQuotes::EnglishQ;
779 tmpl = InsetQuotes::EnglishQ;
782 tmpl = InsetQuotes::SwedishQ;
785 tmpl = InsetQuotes::GermanQ;
788 tmpl = InsetQuotes::PolishQ;
791 tmpl = InsetQuotes::FrenchQ;
794 tmpl = InsetQuotes::DanishQ;
797 params.quotes_language = tmpl;
799 } else if (token == "\\quotes_times") {
801 switch (lex.GetInteger()) {
803 params.quotes_times = InsetQuotes::SingleQ;
806 params.quotes_times = InsetQuotes::DoubleQ;
809 } else if (token == "\\papersize") {
810 int tmpret = lex.FindToken(string_papersize);
814 params.papersize2 = tmpret;
815 } else if (token == "\\paperpackage") {
816 int tmpret = lex.FindToken(string_paperpackages);
819 params.paperpackage = BufferParams::PACKAGE_NONE;
821 params.paperpackage = tmpret;
822 } else if (token == "\\use_geometry") {
824 params.use_geometry = lex.GetInteger();
825 } else if (token == "\\use_amsmath") {
827 params.use_amsmath = lex.GetInteger();
828 } else if (token == "\\paperorientation") {
829 int tmpret = lex.FindToken(string_orientation);
830 if (tmpret == -1) ++tmpret;
831 if (tmpret != LYX_LAYOUT_DEFAULT)
832 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
833 } else if (token == "\\paperwidth") {
835 params.paperwidth = lex.GetString();
836 } else if (token == "\\paperheight") {
838 params.paperheight = lex.GetString();
839 } else if (token == "\\leftmargin") {
841 params.leftmargin = lex.GetString();
842 } else if (token == "\\topmargin") {
844 params.topmargin = lex.GetString();
845 } else if (token == "\\rightmargin") {
847 params.rightmargin = lex.GetString();
848 } else if (token == "\\bottommargin") {
850 params.bottommargin = lex.GetString();
851 } else if (token == "\\headheight") {
853 params.headheight = lex.GetString();
854 } else if (token == "\\headsep") {
856 params.headsep = lex.GetString();
857 } else if (token == "\\footskip") {
859 params.footskip = lex.GetString();
860 } else if (token == "\\paperfontsize") {
862 params.fontsize = strip(lex.GetString());
863 } else if (token == "\\papercolumns") {
865 params.columns = lex.GetInteger();
866 } else if (token == "\\papersides") {
868 switch (lex.GetInteger()) {
870 case 1: params.sides = LyXTextClass::OneSide; break;
871 case 2: params.sides = LyXTextClass::TwoSides; break;
873 } else if (token == "\\paperpagestyle") {
875 params.pagestyle = strip(lex.GetString());
876 } else if (token == "\\bullet") {
878 int const index = lex.GetInteger();
880 int temp_int = lex.GetInteger();
881 params.user_defined_bullets[index].setFont(temp_int);
882 params.temp_bullets[index].setFont(temp_int);
884 temp_int = lex.GetInteger();
885 params.user_defined_bullets[index].setCharacter(temp_int);
886 params.temp_bullets[index].setCharacter(temp_int);
888 temp_int = lex.GetInteger();
889 params.user_defined_bullets[index].setSize(temp_int);
890 params.temp_bullets[index].setSize(temp_int);
892 string const temp_str = lex.GetString();
893 if (temp_str != "\\end_bullet") {
894 // this element isn't really necessary for
895 // parsing but is easier for humans
896 // to understand bullets. Put it back and
897 // set a debug message?
898 lex.printError("\\end_bullet expected, got" + temp_str);
899 //how can I put it back?
901 } else if (token == "\\bulletLaTeX") {
903 int const index = lex.GetInteger();
905 string temp_str = lex.GetString();
907 while (temp_str != "\\end_bullet") {
908 // this loop structure is needed when user
909 // enters an empty string since the first
910 // thing returned will be the \\end_bullet
912 // if the LaTeX entry has spaces. Each element
913 // therefore needs to be read in turn
916 temp_str = lex.GetString();
918 params.user_defined_bullets[index].setText(sum_str);
919 params.temp_bullets[index].setText(sum_str);
920 } else if (token == "\\secnumdepth") {
922 params.secnumdepth = lex.GetInteger();
923 } else if (token == "\\tocdepth") {
925 params.tocdepth = lex.GetInteger();
926 } else if (token == "\\spacing") {
928 string const tmp = strip(lex.GetString());
929 Spacing::Space tmp_space = Spacing::Default;
931 if (tmp == "single") {
932 tmp_space = Spacing::Single;
933 } else if (tmp == "onehalf") {
934 tmp_space = Spacing::Onehalf;
935 } else if (tmp == "double") {
936 tmp_space = Spacing::Double;
937 } else if (tmp == "other") {
939 tmp_space = Spacing::Other;
940 tmp_val = lex.GetFloat();
942 lex.printError("Unknown spacing token: '$$Token'");
944 // Small hack so that files written with klyx will be
947 par->params.spacing(Spacing(tmp_space, tmp_val));
949 params.spacing.set(tmp_space, tmp_val);
951 } else if (token == "\\paragraph_spacing") {
953 string const tmp = strip(lex.GetString());
954 if (tmp == "single") {
955 par->params.spacing(Spacing(Spacing::Single));
956 } else if (tmp == "onehalf") {
957 par->params.spacing(Spacing(Spacing::Onehalf));
958 } else if (tmp == "double") {
959 par->params.spacing(Spacing(Spacing::Double));
960 } else if (tmp == "other") {
962 par->params.spacing(Spacing(Spacing::Other,
965 lex.printError("Unknown spacing token: '$$Token'");
967 } else if (token == "\\float_placement") {
969 params.float_placement = lex.GetString();
970 } else if (token == "\\family") {
972 font.setLyXFamily(lex.GetString());
973 } else if (token == "\\series") {
975 font.setLyXSeries(lex.GetString());
976 } else if (token == "\\shape") {
978 font.setLyXShape(lex.GetString());
979 } else if (token == "\\size") {
981 font.setLyXSize(lex.GetString());
982 } else if (token == "\\latex") {
984 string const tok = lex.GetString();
985 // This is dirty, but gone with LyX3. (Asger)
986 if (tok == "no_latex")
987 font.setLatex(LyXFont::OFF);
988 else if (tok == "latex")
989 font.setLatex(LyXFont::ON);
990 else if (tok == "default")
991 font.setLatex(LyXFont::INHERIT);
993 lex.printError("Unknown LaTeX font flag "
995 } else if (token == "\\lang") {
997 string const tok = lex.GetString();
998 Language const * lang = languages.getLanguage(tok);
1000 font.setLanguage(lang);
1002 font.setLanguage(params.language);
1003 lex.printError("Unknown language `$$Token'");
1005 } else if (token == "\\numeric") {
1007 font.setNumber(font.setLyXMisc(lex.GetString()));
1008 } else if (token == "\\emph") {
1010 font.setEmph(font.setLyXMisc(lex.GetString()));
1011 } else if (token == "\\bar") {
1013 string const tok = lex.GetString();
1014 // This is dirty, but gone with LyX3. (Asger)
1016 font.setUnderbar(LyXFont::ON);
1017 else if (tok == "no")
1018 font.setUnderbar(LyXFont::OFF);
1019 else if (tok == "default")
1020 font.setUnderbar(LyXFont::INHERIT);
1022 lex.printError("Unknown bar font flag "
1024 } else if (token == "\\noun") {
1026 font.setNoun(font.setLyXMisc(lex.GetString()));
1027 } else if (token == "\\color") {
1029 font.setLyXColor(lex.GetString());
1030 } else if (token == "\\align") {
1031 int tmpret = lex.FindToken(string_align);
1032 if (tmpret == -1) ++tmpret;
1033 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
1034 int const tmpret2 = int(pow(2.0, tmpret));
1035 //lyxerr << "Tmpret2 = " << tmpret2 << endl;
1036 par->params.align(LyXAlignment(tmpret2));
1038 } else if (token == "\\added_space_top") {
1040 par->params.spaceTop(VSpace(lex.GetString()));
1041 } else if (token == "\\added_space_bottom") {
1043 par->params.spaceBottom(VSpace(lex.GetString()));
1044 } else if (token == "\\pextra_type") {
1046 par->params.pextraType(lex.GetInteger());
1047 } else if (token == "\\pextra_width") {
1049 par->params.pextraWidth(lex.GetString());
1050 } else if (token == "\\pextra_widthp") {
1052 par->params.pextraWidthp(lex.GetString());
1053 } else if (token == "\\pextra_alignment") {
1055 par->params.pextraAlignment(lex.GetInteger());
1056 } else if (token == "\\pextra_hfill") {
1058 par->params.pextraHfill(lex.GetInteger());
1059 } else if (token == "\\pextra_start_minipage") {
1061 par->params.pextraStartMinipage(lex.GetInteger());
1062 } else if (token == "\\labelwidthstring") {
1064 par->params.labelWidthString(lex.GetString());
1065 // do not delete this token, it is still needed!
1066 } else if (token == "\\end_inset") {
1067 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
1068 << "Last inset read was: " << last_inset_read
1070 // Simply ignore this. The insets do not have
1072 // But insets should read it, it is a part of
1073 // the inset isn't it? Lgb.
1074 } else if (token == "\\begin_inset") {
1075 readInset(lex, par, pos, font);
1076 } else if (token == "\\SpecialChar") {
1077 LyXLayout const & layout =
1078 textclasslist.Style(params.textclass,
1081 // Insets don't make sense in a free-spacing context! ---Kayvan
1082 if (layout.free_spacing) {
1085 string next_token = lex.GetString();
1086 if (next_token == "\\-") {
1087 par->InsertChar(pos, '-', font);
1088 } else if (next_token == "\\protected_separator"
1089 || next_token == "~") {
1090 par->InsertChar(pos, ' ', font);
1092 lex.printError("Token `$$Token' "
1094 "paragraph layout!");
1099 Inset * inset = new InsetSpecialChar;
1100 inset->Read(this, lex);
1101 par->InsertInset(pos, inset, font);
1104 } else if (token == "\\newline") {
1105 par->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
1107 } else if (token == "\\LyXTable") {
1108 Inset * inset = new InsetTabular(*this);
1109 inset->Read(this, lex);
1110 par->InsertInset(pos, inset, font);
1112 } else if (token == "\\hfill") {
1113 par->InsertChar(pos, LyXParagraph::META_HFILL, font);
1115 } else if (token == "\\protected_separator") { // obsolete
1116 // This is a backward compability thingie. (Lgb)
1117 // Remove it later some time...introduced with fileformat
1119 LyXLayout const & layout =
1120 textclasslist.Style(params.textclass,
1123 if (layout.free_spacing) {
1124 par->InsertChar(pos, ' ', font);
1126 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1127 par->InsertInset(pos, inset, font);
1130 } else if (token == "\\bibitem") { // ale970302
1132 InsetCommandParams p("bibitem", "dummy");
1133 par->bibkey = new InsetBibKey(p);
1135 par->bibkey->Read(this, lex);
1136 } else if (token == "\\backslash") {
1137 par->InsertChar(pos, '\\', font);
1139 } else if (token == "\\the_end") {
1140 the_end_read = true;
1142 // This should be insurance for the future: (Asger)
1143 lex.printError("Unknown token `$$Token'. "
1144 "Inserting as text.");
1145 string::const_iterator cit = token.begin();
1146 string::const_iterator end = token.end();
1147 for (; cit != end; ++cit) {
1148 par->InsertChar(pos, (*cit), font);
1152 return the_end_read;
1156 void Buffer::readInset(LyXLex & lex, LyXParagraph *& par,
1157 int & pos, LyXFont & font)
1159 // consistency check
1160 if (lex.GetString() != "\\begin_inset") {
1161 lyxerr << "Buffer::readInset: Consistency check failed."
1168 string const tmptok = lex.GetString();
1169 last_inset_read = tmptok;
1171 // test the different insets
1172 if (tmptok == "LatexCommand") {
1173 InsetCommandParams inscmd;
1176 if (inscmd.getCmdName() == "cite") {
1177 inset = new InsetCitation(inscmd);
1178 } else if (inscmd.getCmdName() == "bibitem") {
1179 lex.printError("Wrong place for bibitem");
1180 inset = new InsetBibKey(inscmd);
1181 } else if (inscmd.getCmdName() == "BibTeX") {
1182 inset = new InsetBibtex(inscmd);
1183 } else if (inscmd.getCmdName() == "index") {
1184 inset = new InsetIndex(inscmd);
1185 } else if (inscmd.getCmdName() == "include") {
1186 inset = new InsetInclude(inscmd, *this);
1187 } else if (inscmd.getCmdName() == "label") {
1188 inset = new InsetLabel(inscmd);
1189 } else if (inscmd.getCmdName() == "url"
1190 || inscmd.getCmdName() == "htmlurl") {
1191 inset = new InsetUrl(inscmd);
1192 } else if (inscmd.getCmdName() == "ref"
1193 || inscmd.getCmdName() == "pageref"
1194 || inscmd.getCmdName() == "vref"
1195 || inscmd.getCmdName() == "vpageref"
1196 || inscmd.getCmdName() == "prettyref") {
1197 if (!inscmd.getOptions().empty()
1198 || !inscmd.getContents().empty()) {
1199 inset = new InsetRef(inscmd, *this);
1201 } else if (inscmd.getCmdName() == "tableofcontents"
1202 || inscmd.getCmdName() == "listofalgorithms"
1203 || inscmd.getCmdName() == "listoffigures"
1204 || inscmd.getCmdName() == "listoftables") {
1205 inset = new InsetTOC(inscmd);
1206 } else if (inscmd.getCmdName() == "printindex") {
1207 inset = new InsetPrintIndex(inscmd);
1208 } else if (inscmd.getCmdName() == "lyxparent") {
1209 inset = new InsetParent(inscmd, *this);
1212 if (tmptok == "Quotes") {
1213 inset = new InsetQuotes;
1214 } else if (tmptok == "External") {
1215 inset = new InsetExternal;
1216 } else if (tmptok == "FormulaMacro") {
1217 inset = new InsetFormulaMacro;
1218 } else if (tmptok == "Formula") {
1219 inset = new InsetFormula;
1220 } else if (tmptok == "Figure") {
1221 inset = new InsetFig(100, 100, *this);
1222 } else if (tmptok == "Info") {
1223 inset = new InsetInfo;
1224 } else if (tmptok == "Include") {
1225 InsetCommandParams p( "Include" );
1226 inset = new InsetInclude(p, *this);
1227 } else if (tmptok == "ERT") {
1228 inset = new InsetERT;
1229 } else if (tmptok == "Tabular") {
1230 inset = new InsetTabular(*this);
1231 } else if (tmptok == "Text") {
1232 inset = new InsetText;
1233 } else if (tmptok == "Foot") {
1234 inset = new InsetFoot;
1235 } else if (tmptok == "Marginal") {
1236 inset = new InsetMarginal;
1237 } else if (tmptok == "Minipage") {
1238 inset = new InsetMinipage;
1239 } else if (tmptok == "Float") {
1241 string tmptok = lex.GetString();
1242 inset = new InsetFloat(tmptok);
1243 } else if (tmptok == "List") {
1244 inset = new InsetList;
1245 } else if (tmptok == "Theorem") {
1246 inset = new InsetList;
1247 } else if (tmptok == "Caption") {
1248 inset = new InsetCaption;
1249 } else if (tmptok == "GRAPHICS") {
1250 inset = new InsetGraphics;
1253 if (inset) inset->Read(this, lex);
1257 par->InsertInset(pos, inset, font);
1263 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1267 string const token(lex.GetString());
1268 if (token == "\\lyxformat") { // the first token _must_ be...
1270 string tmp_format = lex.GetString();
1271 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1272 // if present remove ".," from string.
1273 string::size_type dot = tmp_format.find_first_of(".,");
1274 //lyxerr << " dot found at " << dot << endl;
1275 if (dot != string::npos)
1276 tmp_format.erase(dot, 1);
1277 file_format = strToInt(tmp_format);
1278 if (file_format == LYX_FORMAT) {
1280 } else if (file_format > LYX_FORMAT) {
1282 WriteAlert(_("Warning!"),
1283 _("LyX file format is newer that what"),
1284 _("is supported in this LyX version. Expect some problems."));
1286 } else if (file_format < LYX_FORMAT) {
1288 if (file_format < 200) {
1289 WriteAlert(_("ERROR!"),
1290 _("Old LyX file format found. "
1291 "Use LyX 0.10.x to read this!"));
1295 bool the_end = readLyXformat2(lex, par);
1297 // the_end was added in 213
1298 if (file_format < 213)
1302 WriteAlert(_("Warning!"),
1303 _("Reading of document is not complete"),
1304 _("Maybe the document is truncated"));
1306 } else { // "\\lyxformat" not found
1307 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1310 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1316 // Should probably be moved to somewhere else: BufferView? LyXView?
1317 bool Buffer::save() const
1319 // We don't need autosaves in the immediate future. (Asger)
1320 resetAutosaveTimers();
1324 if (lyxrc.make_backup) {
1325 s = fileName() + '~';
1326 if (!lyxrc.backupdir_path.empty())
1327 s = AddName(lyxrc.backupdir_path,
1328 subst(CleanupPath(s),'/','!'));
1330 // Rename is the wrong way of making a backup,
1331 // this is the correct way.
1332 /* truss cp fil fil2:
1333 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1334 stat("LyXVC.lyx", 0xEFFFF688) = 0
1335 open("LyXVC.lyx", O_RDONLY) = 3
1336 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1337 fstat(4, 0xEFFFF508) = 0
1338 fstat(3, 0xEFFFF508) = 0
1339 read(3, " # T h i s f i l e w".., 8192) = 5579
1340 write(4, " # T h i s f i l e w".., 5579) = 5579
1341 read(3, 0xEFFFD4A0, 8192) = 0
1344 chmod("LyXVC3.lyx", 0100644) = 0
1345 lseek(0, 0, SEEK_CUR) = 46440
1349 // Should proabaly have some more error checking here.
1350 // Should be cleaned up in 0.13, at least a bit.
1351 // Doing it this way, also makes the inodes stay the same.
1352 // This is still not a very good solution, in particular we
1353 // might loose the owner of the backup.
1354 FileInfo finfo(fileName());
1355 if (finfo.exist()) {
1356 mode_t fmode = finfo.getMode();
1357 struct utimbuf times = {
1358 finfo.getAccessTime(),
1359 finfo.getModificationTime() };
1361 ifstream ifs(fileName().c_str());
1362 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1367 ::chmod(s.c_str(), fmode);
1369 if (::utime(s.c_str(), ×)) {
1370 lyxerr << "utime error." << endl;
1373 lyxerr << "LyX was not able to make "
1374 "backupcopy. Beware." << endl;
1379 if (writeFile(fileName(), false)) {
1381 removeAutosaveFile(fileName());
1383 // Saving failed, so backup is not backup
1384 if (lyxrc.make_backup) {
1385 lyx::rename(s, fileName());
1393 // Returns false if unsuccesful
1394 bool Buffer::writeFile(string const & fname, bool flag) const
1396 // if flag is false writeFile will not create any GUI
1397 // warnings, only cerr.
1398 // Needed for autosave in background or panic save (Matthias 120496)
1400 if (read_only && (fname == filename)) {
1401 // Here we should come with a question if we should
1402 // perform the write anyway.
1404 lyxerr << _("Error! Document is read-only: ")
1407 WriteAlert(_("Error! Document is read-only: "),
1412 FileInfo finfo(fname);
1413 if (finfo.exist() && !finfo.writable()) {
1414 // Here we should come with a question if we should
1415 // try to do the save anyway. (i.e. do a chmod first)
1417 lyxerr << _("Error! Cannot write file: ")
1420 WriteFSAlert(_("Error! Cannot write file: "),
1425 ofstream ofs(fname.c_str());
1428 lyxerr << _("Error! Cannot open file: ")
1431 WriteFSAlert(_("Error! Cannot open file: "),
1437 // Use the standard "C" locale for file output.
1438 ofs.imbue(std::locale::classic());
1441 // The top of the file should not be written by params.
1443 // write out a comment in the top of the file
1444 ofs << '#' << LYX_DOCVERSION
1445 << " created this file. For more info see http://www.lyx.org/\n"
1446 << "\\lyxformat " << LYX_FORMAT << "\n";
1448 // now write out the buffer paramters.
1449 params.writeFile(ofs);
1451 char footnoteflag = 0;
1454 // this will write out all the paragraphs
1455 // using recursive descent.
1456 paragraph->writeFile(this, ofs, params, footnoteflag, depth);
1458 // Write marker that shows file is complete
1459 ofs << "\n\\the_end" << endl;
1463 // how to check if close went ok?
1464 // Following is an attempt... (BE 20001011)
1466 // good() returns false if any error occured, including some
1467 // formatting error.
1468 // bad() returns true if something bad happened in the buffer,
1469 // which should include file system full errors.
1476 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1478 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1488 string const Buffer::asciiParagraph(LyXParagraph const * par,
1489 unsigned int linelen) const
1491 ostringstream buffer;
1494 Inset const * inset;
1497 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
1501 int ltype_depth = 0;
1502 unsigned int currlinelen = 0;
1503 bool ref_printed = false;
1508 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1510 || par->previous()->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
1511 /* begins a footnote environment ? */
1512 if (footnoteflag != par->footnoteflag) {
1513 footnoteflag = par->footnoteflag;
1515 size_t const j = strlen(string_footnotekinds[par->footnotekind]) + 4;
1516 if ((linelen > 0) &&
1517 ((currlinelen + j) > linelen)) {
1522 << string_footnotekinds[par->footnotekind]
1528 if (!par->previous()) {
1530 /* begins or ends a deeper area ?*/
1531 if (depth != par->params.depth()) {
1532 if (par->params.depth() > depth) {
1533 while (par->params.depth() > depth) {
1537 while (par->params.depth() < depth) {
1543 /* First write the layout */
1544 string const tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1545 if (tmp == "Itemize") {
1547 ltype_depth = depth + 1;
1548 } else if (tmp == "Enumerate") {
1550 ltype_depth = depth + 1;
1551 } else if (strstr(tmp.c_str(), "ection")) {
1553 ltype_depth = depth + 1;
1554 } else if (strstr(tmp.c_str(), "aragraph")) {
1556 ltype_depth = depth + 1;
1557 } else if (tmp == "Description") {
1559 ltype_depth = depth + 1;
1560 } else if (tmp == "Abstract") {
1563 } else if (tmp == "Bibliography") {
1571 /* maybe some vertical spaces */
1573 /* the labelwidthstring used in lists */
1577 /* some pagebreaks? */
1581 /* what about the alignment */
1584 /* dummy layout, that means a footnote ended */
1585 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1589 lyxerr << "Should this ever happen?" << endl;
1593 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language);
1594 for (LyXParagraph::size_type i = 0; i < par->size(); ++i) {
1602 for (char j = 0; j < depth; ++j)
1604 currlinelen = depth * 2;
1606 case 0: /* Standard */
1607 case 4: /* (Sub)Paragraph */
1608 case 5: /* Description */
1610 case 6: /* Abstract */
1612 buffer << "Abstract\n\n";
1614 buffer << "Abstract: ";
1616 case 7: /* Bibliography */
1619 buffer << "References\n\n";
1621 buffer << "References: ";
1626 buffer << par->params.labelString() << " ";
1629 if (ltype_depth > depth) {
1630 for (char j = ltype_depth - 1; j > depth; --j)
1632 currlinelen += (ltype_depth-depth)*2;
1635 font2 = par->GetFontSettings(params, i);
1636 if (font1.latex() != font2.latex()) {
1637 if (font2.latex() == LyXFont::OFF)
1644 c = par->GetUChar(params, i);
1648 case LyXParagraph::META_INSET:
1649 if ((inset = par->GetInset(i))) {
1650 if (!inset->Ascii(this, buffer)) {
1652 string s = rsplit(buffer.str().c_str(),
1654 currlinelen += s.length();
1656 // to be sure it breaks paragraph
1657 currlinelen += linelen;
1661 case LyXParagraph::META_NEWLINE:
1664 for (char j = 0; j < depth; ++j)
1667 currlinelen = depth * 2;
1668 if (ltype_depth > depth) {
1669 for (char j = ltype_depth;
1672 currlinelen += (ltype_depth - depth) * 2;
1675 case LyXParagraph::META_HFILL:
1682 if ((linelen > 0) && (currlinelen > (linelen - 10)) &&
1683 (c == ' ') && ((i + 2) < par->size()))
1686 for (char j = 0; j < depth; ++j)
1688 currlinelen = depth * 2;
1689 if (ltype_depth > depth) {
1690 for (char j = ltype_depth;
1693 currlinelen += (ltype_depth-depth)*2;
1695 } else if (c != '\0')
1698 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1703 return buffer.str().c_str();
1707 void Buffer::writeFileAscii(string const & fname, int linelen)
1709 ofstream ofs(fname.c_str());
1711 WriteFSAlert(_("Error: Cannot write file:"), fname);
1714 writeFileAscii(ofs, linelen);
1718 void Buffer::writeFileAscii(ostream & ofs, int linelen)
1720 LyXParagraph * par = paragraph;
1722 ofs << asciiParagraph(par, linelen);
1730 void Buffer::makeLaTeXFile(string const & fname,
1731 string const & original_path,
1732 bool nice, bool only_body)
1734 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1736 niceFile = nice; // this will be used by Insetincludes.
1738 tex_code_break_column = lyxrc.ascii_linelen;
1740 LyXTextClass const & tclass =
1741 textclasslist.TextClass(params.textclass);
1743 ofstream ofs(fname.c_str());
1745 WriteFSAlert(_("Error: Cannot open file: "), fname);
1749 // validate the buffer.
1750 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1751 LaTeXFeatures features(params, tclass.numLayouts());
1753 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1756 // The starting paragraph of the coming rows is the
1757 // first paragraph of the document. (Asger)
1758 texrow.start(paragraph, 0);
1760 if (!only_body && nice) {
1761 ofs << "%% " LYX_DOCVERSION " created this file. "
1762 "For more info, see http://www.lyx.org/.\n"
1763 "%% Do not edit unless you really know what "
1768 lyxerr.debug() << "lyx header finished" << endl;
1769 // There are a few differences between nice LaTeX and usual files:
1770 // usual is \batchmode and has a
1771 // special input@path to allow the including of figures
1772 // with either \input or \includegraphics (what figinsets do).
1773 // batchmode is not set if there is a tex_code_break_column.
1774 // In this case somebody is interested in the generated LaTeX,
1775 // so this is OK. input@path is set when the actual parameter
1776 // original_path is set. This is done for usual tex-file, but not
1777 // for nice-latex-file. (Matthias 250696)
1780 // code for usual, NOT nice-latex-file
1781 ofs << "\\batchmode\n"; // changed
1782 // from \nonstopmode
1785 if (!original_path.empty()) {
1786 ofs << "\\makeatletter\n"
1787 << "\\def\\input@path{{"
1788 << original_path << "/}}\n"
1789 << "\\makeatother\n";
1795 ofs << "\\documentclass";
1797 string options; // the document class options.
1799 if (tokenPos(tclass.opt_fontsize(),
1800 '|', params.fontsize) >= 0) {
1801 // only write if existing in list (and not default)
1802 options += params.fontsize;
1807 if (!params.use_geometry &&
1808 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1809 switch (params.papersize) {
1810 case BufferParams::PAPER_A4PAPER:
1811 options += "a4paper,";
1813 case BufferParams::PAPER_USLETTER:
1814 options += "letterpaper,";
1816 case BufferParams::PAPER_A5PAPER:
1817 options += "a5paper,";
1819 case BufferParams::PAPER_B5PAPER:
1820 options += "b5paper,";
1822 case BufferParams::PAPER_EXECUTIVEPAPER:
1823 options += "executivepaper,";
1825 case BufferParams::PAPER_LEGALPAPER:
1826 options += "legalpaper,";
1832 if (params.sides != tclass.sides()) {
1833 switch (params.sides) {
1834 case LyXTextClass::OneSide:
1835 options += "oneside,";
1837 case LyXTextClass::TwoSides:
1838 options += "twoside,";
1845 if (params.columns != tclass.columns()) {
1846 if (params.columns == 2)
1847 options += "twocolumn,";
1849 options += "onecolumn,";
1852 if (!params.use_geometry
1853 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1854 options += "landscape,";
1856 // language should be a parameter to \documentclass
1858 string language_options;
1859 if (params.language->babel() == "hebrew"
1860 && default_language->babel() != "hebrew")
1861 // This seems necessary
1862 features.UsedLanguages.insert(default_language);
1864 if (lyxrc.language_use_babel ||
1865 params.language->lang() != lyxrc.default_language ||
1866 !features.UsedLanguages.empty()) {
1868 for (LaTeXFeatures::LanguageList::const_iterator cit =
1869 features.UsedLanguages.begin();
1870 cit != features.UsedLanguages.end(); ++cit)
1871 language_options += (*cit)->babel() + ',';
1872 language_options += params.language->babel();
1873 if (lyxrc.language_global_options)
1874 options += language_options + ',';
1877 // the user-defined options
1878 if (!params.options.empty()) {
1879 options += params.options + ',';
1882 if (!options.empty()){
1883 options = strip(options, ',');
1884 ofs << '[' << options << ']';
1888 << textclasslist.LatexnameOfClass(params.textclass)
1891 // end of \documentclass defs
1893 // font selection must be done before loading fontenc.sty
1894 // The ae package is not needed when using OT1 font encoding.
1895 if (params.fonts != "default" &&
1896 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
1897 ofs << "\\usepackage{" << params.fonts << "}\n";
1899 if (params.fonts == "ae") {
1900 ofs << "\\usepackage{aecompl}\n";
1904 // this one is not per buffer
1905 if (lyxrc.fontenc != "default") {
1906 ofs << "\\usepackage[" << lyxrc.fontenc
1911 if (params.inputenc == "auto") {
1912 string const doc_encoding =
1913 params.language->encoding()->LatexName();
1915 // Create a list with all the input encodings used
1917 set<string> encodings;
1918 for (LaTeXFeatures::LanguageList::const_iterator it =
1919 features.UsedLanguages.begin();
1920 it != features.UsedLanguages.end(); ++it)
1921 if ((*it)->encoding()->LatexName() != doc_encoding)
1922 encodings.insert((*it)->encoding()->LatexName());
1924 ofs << "\\usepackage[";
1925 std::copy(encodings.begin(), encodings.end(),
1926 std::ostream_iterator<string>(ofs, ","));
1927 ofs << doc_encoding << "]{inputenc}\n";
1929 } else if (params.inputenc != "default") {
1930 ofs << "\\usepackage[" << params.inputenc
1935 // At the very beginning the text parameters.
1936 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
1937 switch (params.paperpackage) {
1938 case BufferParams::PACKAGE_A4:
1939 ofs << "\\usepackage{a4}\n";
1942 case BufferParams::PACKAGE_A4WIDE:
1943 ofs << "\\usepackage{a4wide}\n";
1946 case BufferParams::PACKAGE_WIDEMARGINSA4:
1947 ofs << "\\usepackage[widemargins]{a4}\n";
1952 if (params.use_geometry) {
1953 ofs << "\\usepackage{geometry}\n";
1955 ofs << "\\geometry{verbose";
1956 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1957 ofs << ",landscape";
1958 switch (params.papersize2) {
1959 case BufferParams::VM_PAPER_CUSTOM:
1960 if (!params.paperwidth.empty())
1961 ofs << ",paperwidth="
1962 << params.paperwidth;
1963 if (!params.paperheight.empty())
1964 ofs << ",paperheight="
1965 << params.paperheight;
1967 case BufferParams::VM_PAPER_USLETTER:
1968 ofs << ",letterpaper";
1970 case BufferParams::VM_PAPER_USLEGAL:
1971 ofs << ",legalpaper";
1973 case BufferParams::VM_PAPER_USEXECUTIVE:
1974 ofs << ",executivepaper";
1976 case BufferParams::VM_PAPER_A3:
1979 case BufferParams::VM_PAPER_A4:
1982 case BufferParams::VM_PAPER_A5:
1985 case BufferParams::VM_PAPER_B3:
1988 case BufferParams::VM_PAPER_B4:
1991 case BufferParams::VM_PAPER_B5:
1995 // default papersize ie BufferParams::VM_PAPER_DEFAULT
1996 switch (lyxrc.default_papersize) {
1997 case BufferParams::PAPER_DEFAULT: // keep compiler happy
1998 case BufferParams::PAPER_USLETTER:
1999 ofs << ",letterpaper";
2001 case BufferParams::PAPER_LEGALPAPER:
2002 ofs << ",legalpaper";
2004 case BufferParams::PAPER_EXECUTIVEPAPER:
2005 ofs << ",executivepaper";
2007 case BufferParams::PAPER_A3PAPER:
2010 case BufferParams::PAPER_A4PAPER:
2013 case BufferParams::PAPER_A5PAPER:
2016 case BufferParams::PAPER_B5PAPER:
2021 if (!params.topmargin.empty())
2022 ofs << ",tmargin=" << params.topmargin;
2023 if (!params.bottommargin.empty())
2024 ofs << ",bmargin=" << params.bottommargin;
2025 if (!params.leftmargin.empty())
2026 ofs << ",lmargin=" << params.leftmargin;
2027 if (!params.rightmargin.empty())
2028 ofs << ",rmargin=" << params.rightmargin;
2029 if (!params.headheight.empty())
2030 ofs << ",headheight=" << params.headheight;
2031 if (!params.headsep.empty())
2032 ofs << ",headsep=" << params.headsep;
2033 if (!params.footskip.empty())
2034 ofs << ",footskip=" << params.footskip;
2038 if (features.amsstyle
2039 && !tclass.provides(LyXTextClass::amsmath)) {
2040 ofs << "\\usepackage{amsmath}\n";
2044 if (tokenPos(tclass.opt_pagestyle(),
2045 '|', params.pagestyle) >= 0) {
2046 if (params.pagestyle == "fancy") {
2047 ofs << "\\usepackage{fancyhdr}\n";
2050 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
2054 // We try to load babel late, in case it interferes
2055 // with other packages.
2057 string tmp = lyxrc.language_package;
2058 if (!lyxrc.language_global_options
2059 && tmp == "\\usepackage{babel}")
2060 tmp = "\\usepackage[" +
2061 language_options + "]{babel}";
2066 if (params.secnumdepth != tclass.secnumdepth()) {
2067 ofs << "\\setcounter{secnumdepth}{"
2068 << params.secnumdepth
2072 if (params.tocdepth != tclass.tocdepth()) {
2073 ofs << "\\setcounter{tocdepth}{"
2079 if (params.paragraph_separation) {
2080 switch (params.defskip.kind()) {
2081 case VSpace::SMALLSKIP:
2082 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
2084 case VSpace::MEDSKIP:
2085 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2087 case VSpace::BIGSKIP:
2088 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
2090 case VSpace::LENGTH:
2091 ofs << "\\setlength\\parskip{"
2092 << params.defskip.length().asLatexString()
2095 default: // should never happen // Then delete it.
2096 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2101 ofs << "\\setlength\\parindent{0pt}\n";
2105 // Now insert the LyX specific LaTeX commands...
2107 // The optional packages;
2108 string preamble(features.getPackages());
2110 // this might be useful...
2111 preamble += "\n\\makeatletter\n";
2113 // Some macros LyX will need
2114 string tmppreamble(features.getMacros());
2116 if (!tmppreamble.empty()) {
2117 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2118 "LyX specific LaTeX commands.\n"
2119 + tmppreamble + '\n';
2122 // the text class specific preamble
2123 tmppreamble = features.getTClassPreamble();
2124 if (!tmppreamble.empty()) {
2125 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2126 "Textclass specific LaTeX commands.\n"
2127 + tmppreamble + '\n';
2130 /* the user-defined preamble */
2131 if (!params.preamble.empty()) {
2132 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2133 "User specified LaTeX commands.\n"
2134 + params.preamble + '\n';
2137 preamble += "\\makeatother\n";
2139 // Itemize bullet settings need to be last in case the user
2140 // defines their own bullets that use a package included
2141 // in the user-defined preamble -- ARRae
2142 // Actually it has to be done much later than that
2143 // since some packages like frenchb make modifications
2144 // at \begin{document} time -- JMarc
2146 for (int i = 0; i < 4; ++i) {
2147 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2148 if (bullets_def.empty())
2149 bullets_def="\\AtBeginDocument{\n";
2150 bullets_def += " \\renewcommand{\\labelitemi";
2152 // `i' is one less than the item to modify
2159 bullets_def += "ii";
2165 bullets_def += "}{" +
2166 params.user_defined_bullets[i].getText()
2171 if (!bullets_def.empty())
2172 preamble += bullets_def + "}\n\n";
2174 for (int j = countChar(preamble, '\n'); j-- ;) {
2181 ofs << "\\begin{document}\n";
2184 lyxerr.debug() << "preamble finished, now the body." << endl;
2186 if (!lyxrc.language_auto_begin) {
2187 ofs << subst(lyxrc.language_command_begin, "$$lang",
2188 params.language->babel())
2193 latexParagraphs(ofs, paragraph, 0, texrow);
2195 // add this just in case after all the paragraphs
2199 if (!lyxrc.language_auto_end) {
2200 ofs << subst(lyxrc.language_command_end, "$$lang",
2201 params.language->babel())
2207 ofs << "\\end{document}\n";
2210 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2212 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2216 // Just to be sure. (Asger)
2219 // tex_code_break_column's value is used to decide
2220 // if we are in batchmode or not (within mathed_write()
2221 // in math_write.C) so we must set it to a non-zero
2222 // value when we leave otherwise we save incorrect .lyx files.
2223 tex_code_break_column = lyxrc.ascii_linelen;
2227 lyxerr << "File was not closed properly." << endl;
2230 lyxerr.debug() << "Finished making latex file." << endl;
2235 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2237 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par,
2238 LyXParagraph * endpar, TexRow & texrow) const
2240 bool was_title = false;
2241 bool already_title = false;
2242 std::ostringstream ftnote;
2247 while (par != endpar) {
2250 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2253 LyXLayout const & layout =
2254 textclasslist.Style(params.textclass,
2257 if (layout.intitle) {
2258 if (already_title) {
2259 lyxerr <<"Error in latexParagraphs: You"
2260 " should not mix title layouts"
2261 " with normal ones." << endl;
2264 } else if (was_title && !already_title) {
2265 ofs << "\\maketitle\n";
2267 already_title = true;
2270 // We are at depth 0 so we can just use
2271 // ordinary \footnote{} generation
2272 // flag this with ftcount
2274 if (layout.isEnvironment()
2275 || par->params.pextraType() != LyXParagraph::PEXTRA_NONE) {
2276 par = par->TeXEnvironment(this, params, ofs, texrow
2278 ,ftnote, ft_texrow, ftcount
2282 par = par->TeXOnePar(this, params, ofs, texrow, false
2285 ftnote, ft_texrow, ftcount
2290 // Write out what we've generated...
2293 ofs << "\\addtocounter{footnote}{-"
2297 ofs << ftnote.str();
2298 texrow += ft_texrow;
2300 // The extra .c_str() is needed when we use
2301 // lyxstring instead of the STL string class.
2302 ftnote.str(string().c_str());
2307 // It might be that we only have a title in this document
2308 if (was_title && !already_title) {
2309 ofs << "\\maketitle\n";
2315 bool Buffer::isLatex() const
2317 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2321 bool Buffer::isLinuxDoc() const
2323 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2327 bool Buffer::isLiterate() const
2329 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2333 bool Buffer::isDocBook() const
2335 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2339 bool Buffer::isSGML() const
2341 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2342 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2346 void Buffer::sgmlOpenTag(ostream & os, int depth,
2347 string const & latexname) const
2349 if (latexname != "!-- --")
2350 os << string(depth, ' ') << "<" << latexname << ">\n";
2354 void Buffer::sgmlCloseTag(ostream & os, int depth,
2355 string const & latexname) const
2357 if (latexname != "!-- --")
2358 os << string(depth, ' ') << "</" << latexname << ">\n";
2362 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2364 LyXParagraph * par = paragraph;
2366 niceFile = nice; // this will be used by Insetincludes.
2368 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2369 string environment_stack[10];
2372 int depth = 0; // paragraph depth
2374 ofstream ofs(fname.c_str());
2377 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2381 LyXTextClass const & tclass =
2382 textclasslist.TextClass(params.textclass);
2384 LaTeXFeatures features(params, tclass.numLayouts());
2388 tex_code_break_column = lyxrc.ascii_linelen;
2390 //tex_code_break_column = 0;
2395 string sgml_includedfiles=features.getIncludedFiles(fname);
2397 if (params.preamble.empty() && sgml_includedfiles.empty()) {
2398 ofs << "<!doctype linuxdoc system>\n\n";
2400 ofs << "<!doctype linuxdoc system [ "
2401 << params.preamble << sgml_includedfiles << " \n]>\n\n";
2404 if (params.options.empty())
2405 sgmlOpenTag(ofs, 0, top_element);
2407 string top = top_element;
2409 top += params.options;
2410 sgmlOpenTag(ofs, 0, top);
2414 ofs << "<!-- " << LYX_DOCVERSION
2415 << " created this file. For more info see http://www.lyx.org/"
2419 int desc_on = 0; // description mode
2420 LyXLayout const & style =
2421 textclasslist.Style(params.textclass,
2424 // treat <toc> as a special case for compatibility with old code
2425 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2426 Inset * inset = par->GetInset(0);
2427 Inset::Code lyx_code = inset->LyxCode();
2428 if (lyx_code == Inset::TOC_CODE){
2429 string const temp = "toc";
2430 sgmlOpenTag(ofs, depth, temp);
2434 linuxDocHandleFootnote(ofs, par, depth);
2442 // environment tag closing
2443 for (; depth > par->params.depth(); --depth) {
2444 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2445 environment_stack[depth].erase();
2448 // write opening SGML tags
2449 switch (style.latextype) {
2450 case LATEX_PARAGRAPH:
2451 if (depth == par->params.depth()
2452 && !environment_stack[depth].empty()) {
2453 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2454 environment_stack[depth].erase();
2460 sgmlOpenTag(ofs, depth, style.latexname());
2465 LinuxDocError(par, 0,
2466 _("Error : Wrong depth for"
2467 " LatexType Command.\n"));
2469 if (!environment_stack[depth].empty()){
2470 sgmlCloseTag(ofs, depth,
2471 environment_stack[depth]);
2475 environment_stack[depth].erase();
2476 sgmlOpenTag(ofs, depth, style.latexname());
2479 case LATEX_ENVIRONMENT:
2480 case LATEX_ITEM_ENVIRONMENT:
2481 if (depth == par->params.depth()
2482 && environment_stack[depth] != style.latexname()
2483 && !environment_stack[depth].empty()) {
2485 sgmlCloseTag(ofs, depth,
2486 environment_stack[depth]);
2487 environment_stack[depth].erase();
2489 if (depth < par->params.depth()) {
2490 depth = par->params.depth();
2491 environment_stack[depth].erase();
2493 if (environment_stack[depth] != style.latexname()) {
2495 string const temp = "p";
2496 sgmlOpenTag(ofs, depth, temp);
2498 environment_stack[depth] = style.latexname();
2499 sgmlOpenTag(ofs, depth,
2500 environment_stack[depth]);
2502 if (style.latextype == LATEX_ENVIRONMENT) break;
2504 desc_on = (style.labeltype == LABEL_MANUAL);
2511 sgmlOpenTag(ofs, depth + 1, item_name);
2514 sgmlOpenTag(ofs, depth, style.latexname());
2520 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2523 linuxDocHandleFootnote(ofs, par, depth);
2525 while(par && par->IsDummy());
2527 SimpleLinuxDocOnePar(ofs, par, desc_on, depth);
2533 // write closing SGML tags
2534 switch (style.latextype) {
2536 case LATEX_ENVIRONMENT:
2537 case LATEX_ITEM_ENVIRONMENT:
2540 sgmlCloseTag(ofs, depth, style.latexname());
2546 for (; depth > 0; --depth)
2547 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2549 if (!environment_stack[depth].empty())
2550 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2554 sgmlCloseTag(ofs, 0, top_element);
2558 // How to check for successful close
2563 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2566 string const tag = "footnote";
2568 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2569 sgmlOpenTag(os, depth + 1, tag);
2570 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2571 sgmlCloseTag(os, depth + 1, tag);
2578 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2579 int depth, int desc_on,
2580 LyXParagraph * & par)
2582 LyXParagraph * tpar = par;
2585 && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE)
2586 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2591 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2593 tpar = tpar->next();
2596 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2597 "Caption").second) {
2598 sgmlOpenTag(os, depth + 1, inner_tag);
2600 SimpleDocBookOnePar(os, extra_par, tpar,
2601 desc_on, depth + 2);
2602 sgmlCloseTag(os, depth+1, inner_tag);
2603 if (!extra_par.empty())
2610 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2613 string tag, inner_tag;
2614 string tmp_par, extra_par;
2615 bool inner_span = false;
2618 // Someone should give this enum a proper name (Lgb)
2626 SOME_ENUM last = NO_ONE;
2627 SOME_ENUM present = FOOTNOTE_LIKE;
2629 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2630 if (last == present) {
2632 if (!tmp_par.empty()) {
2635 sgmlCloseTag(os, depth + 1, inner_tag);
2636 sgmlOpenTag(os, depth + 1, inner_tag);
2643 if (!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2645 if (!extra_par.empty()) os << extra_par;
2646 if (!tag.empty()) sgmlCloseTag(os, depth, tag);
2649 switch (par->footnotekind) {
2650 case LyXParagraph::FOOTNOTE:
2651 case LyXParagraph::ALGORITHM:
2654 present = FOOTNOTE_LIKE;
2657 case LyXParagraph::MARGIN:
2660 present = MARGIN_LIKE;
2663 case LyXParagraph::FIG:
2664 case LyXParagraph::WIDE_FIG:
2666 inner_tag = "title";
2670 case LyXParagraph::TAB:
2671 case LyXParagraph::WIDE_TAB:
2673 inner_tag = "title";
2678 sgmlOpenTag(os, depth, tag);
2679 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2680 DocBookHandleCaption(os, inner_tag, depth,
2684 sgmlOpenTag(os, depth + 1, inner_tag);
2687 // ignore all caption here, we processed them above!!!
2688 if (par->layout != textclasslist
2689 .NumberOfLayout(params.textclass,
2690 "Caption").second) {
2691 std::ostringstream ost;
2692 SimpleDocBookOnePar(ost, extra_par, par,
2693 desc_on, depth + 2);
2694 tmp_par += ost.str().c_str();
2696 tmp_par = frontStrip(strip(tmp_par));
2702 if (!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2703 if (!extra_par.empty()) os << extra_par;
2704 if (!tag.empty()) sgmlCloseTag(os, depth, tag);
2709 // push a tag in a style stack
2710 void Buffer::push_tag(ostream & os, string const & tag,
2711 int & pos, char stack[5][3])
2713 #ifdef WITH_WARNINGS
2714 #warning Use a real stack! (Lgb)
2716 // pop all previous tags
2717 for (int j = pos; j >= 0; --j)
2718 os << "</" << stack[j] << ">";
2721 sprintf(stack[++pos], "%s", tag.c_str());
2724 for (int i = 0; i <= pos; ++i)
2725 os << "<" << stack[i] << ">";
2729 void Buffer::pop_tag(ostream & os, string const & tag,
2730 int & pos, char stack[5][3])
2732 #ifdef WITH_WARNINGS
2733 #warning Use a real stack! (Lgb)
2735 // Please, Lars, do not remove the global variable. I already
2736 // had to reintroduce it twice! (JMarc)
2737 // but...but... I'll remove it anyway. (well not quite) (Lgb)
2741 // pop all tags till specified one
2742 for (j = pos; (j >= 0) && tag != stack[j]; --j)
2743 os << "</" << stack[j] << ">";
2746 os << "</" << tag << ">";
2748 // push all tags, but the specified one
2749 for (j = j + 1; j <= pos; ++j) {
2750 os << "<" << stack[j] << ">";
2751 strcpy(stack[j - 1], stack[j]);
2755 // pop all tags till specified one
2757 for (int j = pos; (j >= 0) && tag != stack[j]; --j)
2758 os << "</" << stack[j] << ">";
2761 os << "</" << tag << ">";
2763 // push all tags, but the specified one
2764 for (int i = j + 1; i <= pos; ++i) {
2765 os << "<" << stack[i] << ">";
2766 strcpy(stack[i - 1], stack[i]);
2773 // Handle internal paragraph parsing -- layout already processed.
2775 // checks, if newcol chars should be put into this line
2776 // writes newline, if necessary.
2778 void linux_doc_line_break(ostream & os, string::size_type & colcount,
2779 string::size_type newcol)
2782 if (colcount > lyxrc.ascii_linelen) {
2784 colcount = newcol; // assume write after this call
2789 void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
2790 int desc_on, int /*depth*/)
2795 LyXParagraph::size_type main_body;
2797 LyXLayout const & style = textclasslist.Style(params.textclass,
2800 char family_type = 0; // family font flag
2801 bool is_bold = false; // series font flag
2802 char shape_type = 0; // shape font flag
2803 bool is_em = false; // emphasis (italic) font flag
2805 int stack_num = -1; // style stack position
2806 // Can this be rewritten to use a std::stack, please. (Lgb)
2807 char stack[5][3]; // style stack
2808 string::size_type char_line_count = 5; // Heuristic choice ;-)
2810 if (style.labeltype != LABEL_MANUAL)
2813 main_body = par->BeginningOfMainBody();
2815 // gets paragraph main font
2817 font1 = style.labelfont;
2822 // parsing main loop
2823 for (LyXParagraph::size_type i = 0;
2824 i < par->size(); ++i) {
2836 LyXFont const font2 = par->getFont(params, i);
2838 if (font1.family() != font2.family()) {
2839 switch (family_type) {
2841 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2842 push_tag(os, "tt", stack_num, stack);
2845 else if (font2.family() == LyXFont::SANS_FAMILY) {
2846 push_tag(os, "sf", stack_num, stack);
2851 pop_tag(os, "tt", stack_num, stack);
2852 if (font2.family() == LyXFont::SANS_FAMILY) {
2853 push_tag(os, "sf", stack_num, stack);
2860 pop_tag(os, "sf", stack_num, stack);
2861 if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
2862 push_tag(os, "tt", stack_num, stack);
2871 if (font1.series() != font2.series()) {
2872 if (font2.series() == LyXFont::BOLD_SERIES) {
2873 push_tag(os, "bf", stack_num, stack);
2875 } else if (is_bold) {
2876 pop_tag(os, "bf", stack_num, stack);
2881 // handle italic and slanted fonts
2882 if (font1.shape() != font2.shape()) {
2883 switch (shape_type) {
2885 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2886 push_tag(os, "it", stack_num, stack);
2888 } else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2889 push_tag(os, "sl", stack_num, stack);
2894 pop_tag(os, "it", stack_num, stack);
2895 if (font2.shape() == LyXFont::SLANTED_SHAPE) {
2896 push_tag(os, "sl", stack_num, stack);
2903 pop_tag(os, "sl", stack_num, stack);
2904 if (font2.shape() == LyXFont::ITALIC_SHAPE) {
2905 push_tag(os, "it", stack_num, stack);
2913 if (font1.emph() != font2.emph()) {
2914 if (font2.emph() == LyXFont::ON) {
2915 push_tag(os, "em", stack_num, stack);
2918 pop_tag(os, "em", stack_num, stack);
2923 c = par->GetChar(i);
2925 if (c == LyXParagraph::META_INSET) {
2926 inset = par->GetInset(i);
2927 inset->Linuxdoc(this, os);
2930 if (font2.latex() == LyXFont::ON) {
2931 // "TeX"-Mode on == > SGML-Mode on.
2933 os << c; // see LaTeX-Generation...
2937 if (par->linuxDocConvertChar(c, sgml_string)
2938 && !style.free_spacing) { // in freespacing
2940 // non-breaking characters
2944 linux_doc_line_break(os, char_line_count, 6);
2948 linux_doc_line_break(os, char_line_count, 1);
2953 char_line_count += sgml_string.length();
2959 // needed if there is an optional argument but no contents
2960 if (main_body > 0 && main_body == par->size()) {
2964 // pop all defined Styles
2965 for (j = stack_num; j >= 0; --j) {
2966 linux_doc_line_break(os,
2968 3 + strlen(stack[j]));
2969 os << "</" << stack[j] << ">";
2972 // resets description flag correctly
2975 // <tag> not closed...
2976 linux_doc_line_break(os, char_line_count, 6);
2980 // fprintf(file, "</p>");
2986 // Print an error message.
2987 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
2988 string const & message)
2990 // insert an error marker in text
2991 InsetError * new_inset = new InsetError(message);
2992 par->InsertInset(pos, new_inset);
2995 // This constant defines the maximum number of
2996 // environment layouts that can be nesteded.
2997 // The same applies for command layouts.
2998 // These values should be more than enough.
2999 // José Matos (1999/07/22)
3001 enum { MAX_NEST_LEVEL = 25};
3003 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3005 LyXParagraph * par = paragraph;
3007 niceFile = nice; // this will be used by Insetincludes.
3009 string top_element= textclasslist.LatexnameOfClass(params.textclass);
3010 // Please use a real stack.
3011 string environment_stack[MAX_NEST_LEVEL];
3012 string environment_inner[MAX_NEST_LEVEL];
3013 // Please use a real stack.
3014 string command_stack[MAX_NEST_LEVEL];
3015 bool command_flag= false;
3016 int command_depth= 0, command_base= 0, cmd_depth= 0;
3018 string item_name, command_name;
3019 string c_depth, c_params, tmps;
3021 int depth = 0; // paragraph depth
3022 LyXTextClass const & tclass =
3023 textclasslist.TextClass(params.textclass);
3025 LaTeXFeatures features(params, tclass.numLayouts());
3029 tex_code_break_column = lyxrc.ascii_linelen;
3031 //tex_code_break_column = 0;
3033 ofstream ofs(fname.c_str());
3035 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3042 string sgml_includedfiles=features.getIncludedFiles(fname);
3044 ofs << "<!doctype " << top_element
3045 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
3047 if (params.preamble.empty() && sgml_includedfiles.empty())
3050 ofs << "\n [ " << params.preamble
3051 << sgml_includedfiles << " \n]>\n\n";
3054 string top = top_element;
3056 top += params.language->code();
3059 if (!params.options.empty()) {
3061 top += params.options;
3063 sgmlOpenTag(ofs, 0, top);
3065 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
3066 << "\n See http://www.lyx.org/ for more information -->\n";
3069 int desc_on = 0; // description mode
3070 LyXLayout const & style =
3071 textclasslist.Style(params.textclass,
3074 // environment tag closing
3075 for (; depth > par->params.depth(); --depth) {
3076 if (environment_inner[depth] != "!-- --") {
3077 item_name= "listitem";
3078 sgmlCloseTag(ofs, command_depth + depth,
3080 if (environment_inner[depth] == "varlistentry")
3081 sgmlCloseTag(ofs, depth+command_depth,
3082 environment_inner[depth]);
3084 sgmlCloseTag(ofs, depth + command_depth,
3085 environment_stack[depth]);
3086 environment_stack[depth].erase();
3087 environment_inner[depth].erase();
3090 if (depth == par->params.depth()
3091 && environment_stack[depth] != style.latexname()
3092 && !environment_stack[depth].empty()) {
3093 if (environment_inner[depth] != "!-- --") {
3094 item_name= "listitem";
3095 sgmlCloseTag(ofs, command_depth+depth,
3097 if (environment_inner[depth] == "varlistentry")
3099 depth + command_depth,
3100 environment_inner[depth]);
3103 sgmlCloseTag(ofs, depth + command_depth,
3104 environment_stack[depth]);
3106 environment_stack[depth].erase();
3107 environment_inner[depth].erase();
3110 // Write opening SGML tags.
3111 switch (style.latextype) {
3112 case LATEX_PARAGRAPH:
3113 sgmlOpenTag(ofs, depth+command_depth, style.latexname());
3118 LinuxDocError(par, 0,
3119 _("Error : Wrong depth for "
3120 "LatexType Command.\n"));
3122 command_name = style.latexname();
3124 tmps = style.latexparam();
3125 c_params = split(tmps, c_depth,'|');
3127 cmd_depth= lyx::atoi(c_depth);
3130 if (cmd_depth<command_base) {
3131 for (int j = command_depth;
3132 j >= command_base; --j)
3133 if (!command_stack[j].empty())
3134 sgmlCloseTag(ofs, j, command_stack[j]);
3135 command_depth= command_base= cmd_depth;
3136 } else if (cmd_depth <= command_depth) {
3137 for (int j = command_depth;
3138 j >= cmd_depth; --j)
3140 if (!command_stack[j].empty())
3141 sgmlCloseTag(ofs, j, command_stack[j]);
3142 command_depth= cmd_depth;
3144 command_depth= cmd_depth;
3146 command_depth = command_base = cmd_depth;
3147 command_flag = true;
3149 command_stack[command_depth]= command_name;
3151 // treat label as a special case for
3152 // more WYSIWYM handling.
3153 if (par->GetChar(0) == LyXParagraph::META_INSET) {
3154 Inset * inset = par->GetInset(0);
3155 Inset::Code lyx_code = inset->LyxCode();
3156 if (lyx_code == Inset::LABEL_CODE){
3157 command_name += " id=\"";
3158 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3159 command_name += "\"";
3164 sgmlOpenTag(ofs, depth + command_depth, command_name);
3165 if (c_params.empty())
3166 item_name = "title";
3168 item_name = c_params;
3169 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3172 case LATEX_ENVIRONMENT:
3173 case LATEX_ITEM_ENVIRONMENT:
3174 if (depth < par->params.depth()) {
3175 depth = par->params.depth();
3176 environment_stack[depth].erase();
3179 if (environment_stack[depth] != style.latexname()) {
3180 environment_stack[depth] = style.latexname();
3181 environment_inner[depth] = "!-- --";
3182 sgmlOpenTag(ofs, depth + command_depth,
3183 environment_stack[depth]);
3185 if (environment_inner[depth] != "!-- --") {
3186 item_name= "listitem";
3188 command_depth + depth,
3190 if (environment_inner[depth] == "varlistentry")
3192 depth + command_depth,
3193 environment_inner[depth]);
3197 if (style.latextype == LATEX_ENVIRONMENT) {
3198 if (!style.latexparam().empty()) {
3199 if(style.latexparam() == "CDATA")
3200 ofs << "<![ CDATA [";
3202 sgmlOpenTag(ofs, depth + command_depth,
3203 style.latexparam());
3208 desc_on = (style.labeltype == LABEL_MANUAL);
3211 environment_inner[depth]= "varlistentry";
3213 environment_inner[depth]= "listitem";
3215 sgmlOpenTag(ofs, depth + 1 + command_depth,
3216 environment_inner[depth]);
3220 sgmlOpenTag(ofs, depth + 1 + command_depth,
3224 sgmlOpenTag(ofs, depth + 1 + command_depth,
3229 sgmlOpenTag(ofs, depth + command_depth,
3237 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3238 depth + 1 + command_depth);
3240 DocBookHandleFootnote(ofs, par,
3241 depth + 1 + command_depth);
3242 } while(par && par->IsDummy());
3245 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3246 depth + 1 + command_depth);
3250 // write closing SGML tags
3251 switch (style.latextype) {
3253 if (c_params.empty())
3257 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3259 case LATEX_ENVIRONMENT:
3260 if (!style.latexparam().empty()) {
3261 if(style.latexparam() == "CDATA")
3264 sgmlCloseTag(ofs, depth + command_depth,
3265 style.latexparam());
3268 case LATEX_ITEM_ENVIRONMENT:
3269 if (desc_on == 1) break;
3271 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3273 case LATEX_PARAGRAPH:
3274 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3277 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3283 for (; depth >= 0; --depth) {
3284 if (!environment_stack[depth].empty()) {
3285 if (environment_inner[depth] != "!-- --") {
3286 item_name= "listitem";
3287 sgmlCloseTag(ofs, command_depth + depth,
3289 if (environment_inner[depth] == "varlistentry")
3290 sgmlCloseTag(ofs, depth + command_depth,
3291 environment_inner[depth]);
3294 sgmlCloseTag(ofs, depth + command_depth,
3295 environment_stack[depth]);
3299 for (int j = command_depth; j >= command_base; --j)
3300 if (!command_stack[j].empty())
3301 sgmlCloseTag(ofs, j, command_stack[j]);
3304 sgmlCloseTag(ofs, 0, top_element);
3307 // How to check for successful close
3311 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3312 LyXParagraph * par, int & desc_on,
3315 bool emph_flag = false;
3317 LyXLayout const & style = textclasslist.Style(params.textclass,
3320 LyXParagraph::size_type main_body;
3321 if (style.labeltype != LABEL_MANUAL)
3324 main_body = par->BeginningOfMainBody();
3326 // gets paragraph main font
3327 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3329 int char_line_count = depth;
3330 if (!style.free_spacing)
3331 for (int j = 0; j < depth; ++j)
3334 // parsing main loop
3335 for (LyXParagraph::size_type i = 0;
3336 i < par->size(); ++i) {
3337 LyXFont font2 = par->getFont(params, i);
3339 // handle <emphasis> tag
3340 if (font1.emph() != font2.emph() && i) {
3341 if (font2.emph() == LyXFont::ON) {
3345 os << "</emphasis>";
3350 char c = par->GetChar(i);
3352 if (c == LyXParagraph::META_INSET) {
3353 Inset * inset = par->GetInset(i);
3354 std::ostringstream ost;
3355 inset->DocBook(this, ost);
3356 string tmp_out = ost.str().c_str();
3359 // This code needs some explanation:
3360 // Two insets are treated specially
3361 // label if it is the first element in a command paragraph
3363 // graphics inside tables or figure floats can't go on
3364 // title (the equivalente in latex for this case is caption
3365 // and title should come first
3368 if (desc_on!= 3 || i!= 0) {
3369 if (!tmp_out.empty() && tmp_out[0] == '@') {
3371 extra += frontStrip(tmp_out, '@');
3373 os << frontStrip(tmp_out, '@');
3378 } else if (font2.latex() == LyXFont::ON) {
3379 // "TeX"-Mode on ==> SGML-Mode on.
3385 if (par->linuxDocConvertChar(c, sgml_string)
3386 && !style.free_spacing) { // in freespacing
3388 // non-breaking characters
3392 os << "\n</term><listitem><para>";
3404 // needed if there is an optional argument but no contents
3405 if (main_body > 0 && main_body == par->size()) {
3409 os << "</emphasis>";
3412 // resets description flag correctly
3415 // <term> not closed...
3423 // This should be enabled when the Chktex class is implemented. (Asger)
3424 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3425 // Other flags: -wall -v0 -x
3426 int Buffer::runChktex()
3428 if (!users->text) return 0;
3430 ProhibitInput(users);
3432 // get LaTeX-Filename
3433 string const name = getLatexName();
3434 string path = OnlyPath(filename);
3436 string const org_path = path;
3437 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3441 Path p(path); // path to LaTeX file
3442 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3444 // Remove all error insets
3445 bool const removedErrorInsets = users->removeAutoInsets();
3447 // Generate the LaTeX file if neccessary
3448 makeLaTeXFile(name, org_path, false);
3451 Chktex chktex(lyxrc.chktex_command, name, filepath);
3452 int res = chktex.run(terr); // run chktex
3455 WriteAlert(_("chktex did not work!"),
3456 _("Could not run with file:"), name);
3457 } else if (res > 0) {
3458 // Insert all errors as errors boxes
3459 users->insertErrors(terr);
3462 // if we removed error insets before we ran chktex or if we inserted
3463 // error insets after we ran chktex, this must be run:
3464 if (removedErrorInsets || res){
3466 users->fitCursor(users->text);
3474 void Buffer::validate(LaTeXFeatures & features) const
3476 LyXParagraph * par = paragraph;
3477 LyXTextClass const & tclass =
3478 textclasslist.TextClass(params.textclass);
3480 // AMS Style is at document level
3482 features.amsstyle = (params.use_amsmath ||
3483 tclass.provides(LyXTextClass::amsmath));
3486 // We don't use "lyxerr.debug" because of speed. (Asger)
3487 if (lyxerr.debugging(Debug::LATEX))
3488 lyxerr << "Paragraph: " << par << endl;
3490 // Now just follow the list of paragraphs and run
3491 // validate on each of them.
3492 par->validate(features);
3494 // and then the next paragraph
3502 // the bullet shapes are buffer level not paragraph level
3503 // so they are tested here
3504 for (int i = 0; i < 4; ++i) {
3505 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3506 int const font = params.user_defined_bullets[i].getFont();
3508 int const c = params
3509 .user_defined_bullets[i]
3516 features.latexsym = true;
3518 } else if (font == 1) {
3519 features.amssymb = true;
3520 } else if ((font >= 2 && font <= 5)) {
3521 features.pifont = true;
3526 if (lyxerr.debugging(Debug::LATEX)) {
3527 features.showStruct();
3532 void Buffer::setPaperStuff()
3534 params.papersize = BufferParams::PAPER_DEFAULT;
3535 char const c1 = params.paperpackage;
3536 if (c1 == BufferParams::PACKAGE_NONE) {
3537 char const c2 = params.papersize2;
3538 if (c2 == BufferParams::VM_PAPER_USLETTER)
3539 params.papersize = BufferParams::PAPER_USLETTER;
3540 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3541 params.papersize = BufferParams::PAPER_LEGALPAPER;
3542 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3543 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3544 else if (c2 == BufferParams::VM_PAPER_A3)
3545 params.papersize = BufferParams::PAPER_A3PAPER;
3546 else if (c2 == BufferParams::VM_PAPER_A4)
3547 params.papersize = BufferParams::PAPER_A4PAPER;
3548 else if (c2 == BufferParams::VM_PAPER_A5)
3549 params.papersize = BufferParams::PAPER_A5PAPER;
3550 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3551 (c2 == BufferParams::VM_PAPER_B5))
3552 params.papersize = BufferParams::PAPER_B5PAPER;
3553 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3554 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3555 params.papersize = BufferParams::PAPER_A4PAPER;
3559 // This function should be in Buffer because it's a buffer's property (ale)
3560 string const Buffer::getIncludeonlyList(char delim)
3563 for (inset_iterator it = inset_iterator_begin();
3564 it != inset_iterator_end(); ++it) {
3565 if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3566 InsetInclude * insetinc =
3567 static_cast<InsetInclude *>(*it);
3568 if (insetinc->isInclude()
3569 && insetinc->isNoLoad()) {
3572 lst += OnlyFilename(ChangeExtension(insetinc->getContents(), string()));
3576 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3581 vector<string> const Buffer::getLabelList()
3583 /// if this is a child document and the parent is already loaded
3584 /// Use the parent's list instead [ale990407]
3585 if (!params.parentname.empty()
3586 && bufferlist.exists(params.parentname)) {
3587 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3589 return tmp->getLabelList();
3592 vector<string> label_list;
3593 for (inset_iterator it = inset_iterator_begin();
3594 it != inset_iterator_end(); ++it) {
3595 vector<string> const l = (*it)->getLabelList();
3596 label_list.insert(label_list.end(), l.begin(), l.end());
3602 map<string, vector<Buffer::TocItem> > const Buffer::getTocList() const
3609 map<string, vector<TocItem> > l;
3610 LyXParagraph * par = paragraph;
3613 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3614 if (textclasslist.Style(params.textclass,
3615 par->GetLayout()).labeltype
3616 == LABEL_SENSITIVE) {
3620 tmp.str = par->String(this, false);
3621 switch (par->footnotekind) {
3622 case LyXParagraph::FIG:
3623 case LyXParagraph::WIDE_FIG:
3625 tmp.str = tostr(++figs) + ". "
3627 map<string, vector<TocItem> >::iterator it = l.find("LOF");
3628 if (it == l.end()) {
3629 vector<TocItem> vti;
3633 it->second.push_back(tmp);
3638 case LyXParagraph::TAB:
3639 case LyXParagraph::WIDE_TAB:
3641 tmp.str = tostr(++tables) + ". "
3643 map<string, vector<TocItem> >::iterator it = l.find("LOT");
3644 if (it == l.end()) {
3645 vector<TocItem> vti;
3649 it->second.push_back(tmp);
3654 case LyXParagraph::ALGORITHM:
3656 tmp.str = tostr(++algs) + ". "
3658 map<string, vector<TocItem> >::iterator it = l.find("LOA");
3659 if (it == l.end()) {
3660 vector<TocItem> vti;
3664 it->second.push_back(tmp);
3669 case LyXParagraph::FOOTNOTE:
3670 case LyXParagraph::MARGIN:
3674 } else if (!par->IsDummy()) {
3676 char const labeltype =
3677 textclasslist.Style(params.textclass,
3678 par->GetLayout()).labeltype;
3680 if (labeltype >= LABEL_COUNTER_CHAPTER
3681 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3682 // insert this into the table of contents
3687 textclasslist.TextClass(params.textclass).maxcounter());
3688 tmp.str = par->String(this, true);
3689 map<string, vector<TocItem> >::iterator it = l.find("TOC");
3690 if (it == l.end()) {
3691 vector<TocItem> vti;
3695 it->second.push_back(tmp);
3699 // For each paragrph, traverse its insets and look for
3701 LyXParagraph::inset_iterator it =
3702 par->inset_iterator_begin();
3703 LyXParagraph::inset_iterator end =
3704 par->inset_iterator_end();
3706 LyXTextClassList::size_type cap;
3707 tie(found, cap) = textclasslist
3708 .NumberOfLayout(params.textclass, "Caption");
3710 for (; it != end; ++it) {
3711 if ((*it)->LyxCode() == Inset::FLOAT_CODE) {
3713 static_cast<InsetFloat*>(*it);
3715 //lyxerr << "Found a float!" << endl;
3716 string const type = il->type();
3717 // Now find the caption in the float...
3718 // We now tranverse the paragraphs of
3720 LyXParagraph * tmp = il->inset->par;
3722 if (tmp->layout == cap) {
3726 ti.str = tmp->String(this, false);
3727 map<string, vector<TocItem> >::iterator it = l.find(type);
3728 if (it == l.end()) {
3729 vector<TocItem> vti;
3733 it->second.push_back(ti);
3742 lyxerr << "caption not found" << endl;
3757 // This is also a buffer property (ale)
3758 vector<pair<string,string> > const Buffer::getBibkeyList()
3760 /// if this is a child document and the parent is already loaded
3761 /// Use the parent's list instead [ale990412]
3762 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3763 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3765 return tmp->getBibkeyList();
3768 vector<pair<string, string> > keys;
3769 LyXParagraph * par = paragraph;
3772 keys.push_back(pair<string, string>(par->bibkey->getContents(),
3773 par->String(this, false)));
3781 // Might be either using bibtex or a child has bibliography
3783 for (inset_iterator it = inset_iterator_begin();
3784 it != inset_iterator_end(); ++it) {
3785 // Search for Bibtex or Include inset
3786 if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
3787 vector<pair<string,string> > tmp =
3788 static_cast<InsetBibtex*>(*it)->getKeys(this);
3789 keys.insert(keys.end(), tmp.begin(), tmp.end());
3790 } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3791 vector<pair<string,string> > const tmp =
3792 static_cast<InsetInclude*>(*it)->getKeys();
3793 keys.insert(keys.end(), tmp.begin(), tmp.end());
3802 bool Buffer::isDepClean(string const & name) const
3804 DEPCLEAN * item = dep_clean;
3805 while (item && item->master != name)
3807 if (!item) return true;
3812 void Buffer::markDepClean(string const & name)
3815 dep_clean = new DEPCLEAN;
3816 dep_clean->clean = true;
3817 dep_clean->master = name;
3818 dep_clean->next = 0;
3820 DEPCLEAN * item = dep_clean;
3821 while (item && item->master != name)
3826 item = new DEPCLEAN;
3828 item->master = name;
3835 bool Buffer::Dispatch(string const & command)
3837 // Split command string into command and argument
3839 string line = frontStrip(command);
3840 string const arg = strip(frontStrip(split(line, cmd, ' ')));
3842 return Dispatch(lyxaction.LookupFunc(cmd), arg);
3846 bool Buffer::Dispatch(int action, string const & argument)
3848 bool dispatched = true;
3851 Exporter::Export(this, argument, false);
3861 void Buffer::resize()
3863 /// resize the BufferViews!
3869 void Buffer::resizeInsets(BufferView * bv)
3871 /// then remove all LyXText in text-insets
3872 LyXParagraph * par = paragraph;
3874 for (; par; par = par->next_) {
3875 par->resizeInsetsLyXText(bv);
3878 for (; par; par = par->next()) {
3879 par->resizeInsetsLyXText(bv);
3885 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3888 LyXParagraph * par = paragraph;
3890 par->ChangeLanguage(params, from, to);
3900 bool Buffer::isMultiLingual()
3902 LyXParagraph * par = paragraph;
3904 if (par->isMultiLingual(params))
3916 Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
3917 LyXParagraph::size_type pos)
3920 it = par->InsetIterator(pos);
3921 if (it == par->inset_iterator_end()) {
3932 void Buffer::inset_iterator::SetParagraph()
3935 it = par->inset_iterator_begin();
3936 if (it != par->inset_iterator_end())
3945 // We maintain an invariant that whenever par = 0 then it = 0