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 * ====================================================== */
14 #pragma implementation "lyxparagraph.h"
21 #include "lyxparagraph.h"
22 #include "support/textutils.h"
25 #include "tex-strings.h"
26 #include "bufferparams.h"
27 #include "support/FileInfo.h"
28 #include "support/LAssert.h"
30 #include "LaTeXFeatures.h"
31 #include "insets/insetinclude.h"
32 #include "insets/insetbib.h"
33 #include "insets/insettext.h"
34 #include "support/filetools.h"
35 #include "lyx_gui_misc.h"
37 #include "support/lyxmanip.h"
38 #include "BufferView.h"
45 using std::lower_bound;
46 using std::upper_bound;
49 int tex_code_break_column = 72; // needs non-zero initialization. set later.
50 // this is a bad idea, but how can LyXParagraph find its buffer to get
51 // parameters? (JMarc)
52 extern BufferView * current_view;
53 extern string bibitemWidest(BufferView *);
55 // this is a minibuffer
56 static char minibuffer_char;
57 static LyXFont minibuffer_font;
58 static Inset * minibuffer_inset;
61 // Initialization of the counter for the paragraph id's,
62 // declared in lyxparagraph.h
63 unsigned int LyXParagraph::paragraph_id = 0;
66 LyXParagraph::LyXParagraph()
68 text.reserve(500); // is this number too big?
70 for (int i = 0; i < 10; ++i) setCounter(i , 0);
77 footnoteflag = LyXParagraph::NO_FOOTNOTE;
78 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
80 align = LYX_ALIGN_BLOCK;
83 /* table stuff -- begin*/
85 /* table stuff -- end*/
89 bibkey = 0; // ale970302
94 // This konstruktor inserts the new paragraph in a list.
95 LyXParagraph::LyXParagraph(LyXParagraph * par)
98 par->text.resize(par->text.size());
100 for (int i = 0; i < 10; ++i) setCounter(i, 0);
104 // double linked list begin
107 next->previous = this;
109 previous->next = this;
112 footnoteflag = LyXParagraph::NO_FOOTNOTE;
113 footnotekind = LyXParagraph::FOOTNOTE;
116 /* table stuff -- begin*/
118 /* table stuff -- end*/
121 id_ = paragraph_id++;
123 bibkey = 0; // ale970302
129 void LyXParagraph::writeFile(Buffer const * buf, ostream & os,
130 BufferParams const & params,
131 char footflag, char dth) const
135 footnoteflag != LyXParagraph::NO_FOOTNOTE ||
137 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE
142 // The beginning or the end of a footnote environment?
143 if (footflag != footnoteflag) {
144 footflag = footnoteflag;
146 os << "\n\\begin_float "
147 << string_footnotekinds[footnotekind]
150 os << "\n\\end_float ";
154 // The beginning or end of a deeper (i.e. nested) area?
157 while (depth > dth) {
158 os << "\n\\begin_deeper ";
162 while (depth < dth) {
163 os << "\n\\end_deeper ";
169 // First write the layout
171 << textclasslist.NameOfLayout(params.textclass, layout)
174 // Maybe some vertical spaces.
175 if (added_space_top.kind() != VSpace::NONE)
176 os << "\\added_space_top "
177 << added_space_top.asLyXCommand() << " ";
178 if (added_space_bottom.kind() != VSpace::NONE)
179 os << "\\added_space_bottom "
180 << added_space_bottom.asLyXCommand() << " ";
182 // Maybe the paragraph has special spacing
183 spacing.writeFile(os, true);
185 // The labelwidth string used in lists.
186 if (!labelwidthstring.empty())
187 os << "\\labelwidthstring "
188 << labelwidthstring << '\n';
190 // Lines above or below?
194 os << "\\line_bottom ";
196 // Pagebreaks above or below?
198 os << "\\pagebreak_top ";
199 if (pagebreak_bottom)
200 os << "\\pagebreak_bottom ";
202 // Start of appendix?
203 if (start_of_appendix)
204 os << "\\start_of_appendix ";
211 if (align != LYX_ALIGN_LAYOUT) {
214 case LYX_ALIGN_LEFT: h = 1; break;
215 case LYX_ALIGN_RIGHT: h = 2; break;
216 case LYX_ALIGN_CENTER: h = 3; break;
217 default: h = 0; break;
219 os << "\\align " << string_align[h] << " ";
221 if (pextra_type != PEXTRA_NONE) {
222 os << "\\pextra_type " << pextra_type;
223 if (pextra_type == PEXTRA_MINIPAGE) {
224 os << " \\pextra_alignment "
227 os << " \\pextra_hfill "
229 if (pextra_start_minipage)
230 os << " \\pextra_start_minipage "
231 << pextra_start_minipage;
233 if (!pextra_width.empty()) {
234 os << " \\pextra_width "
235 << VSpace(pextra_width).asLyXCommand();
236 } else if (!pextra_widthp.empty()) {
237 os << " \\pextra_widthp "
244 // Dummy layout. This means that a footnote ended.
245 os << "\n\\end_float ";
246 footflag = LyXParagraph::NO_FOOTNOTE;
250 // It might be a table.
252 os << "\\LyXTable\n";
258 bibkey->Write(buf, os);
260 LyXFont font1(LyXFont::ALL_INHERIT, params.language_info);
263 for (size_type i = 0; i < size(); ++i) {
269 // Write font changes
270 LyXFont font2 = GetFontSettings(params, i);
271 if (font2 != font1) {
272 font2.lyxWriteChanges(font1, os);
277 value_type c = GetChar(i);
281 Inset const * inset = GetInset(i);
283 if (inset->DirectWrite()) {
284 // international char, let it write
285 // code directly so it's shorter in
287 inset->Write(buf, os);
289 os << "\n\\begin_inset ";
290 inset->Write(buf, os);
291 os << "\n\\end_inset \n\n";
297 os << "\n\\newline \n";
301 os << "\n\\hfill \n";
305 os << "\n\\backslash \n";
309 if (i + 1 < size() && GetChar(i + 1) == ' ') {
316 if ((column > 70 && c == ' ')
321 // this check is to amend a bug. LyX sometimes
322 // inserts '\0' this could cause problems.
326 lyxerr << "ERROR (LyXParagraph::writeFile):"
327 " NULL char in structure." << endl;
333 // now write the next paragraph
335 next->writeFile(buf, os, params, footflag, dth);
339 void LyXParagraph::validate(LaTeXFeatures & features) const
341 BufferParams const & params = features.bufferParams();
344 // this will be useful later
345 LyXLayout const & layout =
346 textclasslist.Style(params.textclass,
351 if (line_top || line_bottom)
352 features.lyxline = true;
353 if (!spacing.isDefault())
354 features.setspace = true;
357 features.layout[GetLayout()] = true;
360 Language const * doc_language = params.language_info;
362 for (FontList::const_iterator cit = fontlist.begin();
363 cit != fontlist.end(); ++cit) {
364 if ((*cit).font.noun() == LyXFont::ON) {
365 lyxerr[Debug::LATEX] << "font.noun: "
366 << (*cit).font.noun()
368 features.noun = true;
369 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
370 << (*cit).font.stateText(0)
373 switch ((*cit).font.color()) {
375 case LColor::inherit:
379 features.color = true;
380 lyxerr[Debug::LATEX] << "Color enabled. Font: "
381 << (*cit).font.stateText(0)
385 Language const * language = (*cit).font.language();
386 if (language != doc_language) {
387 features.UsedLanguages.insert(language);
388 lyxerr[Debug::LATEX] << "Found language "
389 << language->lang() << endl;
394 for (InsetList::const_iterator cit = insetlist.begin();
395 cit != insetlist.end(); ++cit) {
397 (*cit).inset->Validate(features);
401 if (table && table->IsLongTable())
402 features.longtable = true;
404 if (pextra_type == PEXTRA_INDENT)
405 features.LyXParagraphIndent = true;
406 if (pextra_type == PEXTRA_FLOATFLT)
407 features.floatflt = true;
409 if (layout.needprotect
410 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
411 features.NeedLyXFootnoteCode = true;
413 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
414 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
415 features.NeedLyXMinipageIndent = true;
417 if (table && table->NeedRotating())
418 features.rotating = true;
421 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
422 features.algorithm = true;
427 // First few functions needed for cut and paste and paragraph breaking.
428 void LyXParagraph::CopyIntoMinibuffer(BufferParams const & bparams,
429 LyXParagraph::size_type pos) const
431 minibuffer_char = GetChar(pos);
432 minibuffer_font = GetFontSettings(bparams, pos);
433 minibuffer_inset = 0;
434 if (minibuffer_char == LyXParagraph::META_INSET) {
436 minibuffer_inset = GetInset(pos)->Clone();
438 minibuffer_inset = 0;
439 minibuffer_char = ' ';
440 // This reflects what GetInset() does (ARRae)
446 void LyXParagraph::CutIntoMinibuffer(BufferParams const & bparams,
447 LyXParagraph::size_type pos)
449 minibuffer_char = GetChar(pos);
450 minibuffer_font = GetFontSettings(bparams, pos);
451 minibuffer_inset = 0;
452 if (minibuffer_char == LyXParagraph::META_INSET) {
454 minibuffer_inset = GetInset(pos);
455 // This is a little hack since I want exactly
456 // the inset, not just a clone. Otherwise
457 // the inset would be deleted when calling Erase(pos)
459 InsetTable search_elem(pos, 0);
460 InsetList::iterator it =
461 lower_bound(insetlist.begin(),
463 search_elem, matchIT());
464 if (it != insetlist.end() && (*it).pos == pos)
467 minibuffer_inset = 0;
468 minibuffer_char = ' ';
469 // This reflects what GetInset() does (ARRae)
474 // Erase(pos); now the caller is responsible for that.
478 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
480 if ((minibuffer_char == LyXParagraph::META_INSET) &&
481 !InsertInsetAllowed(minibuffer_inset))
483 if (minibuffer_char == LyXParagraph::META_INSET)
484 InsertInset(pos, minibuffer_inset, minibuffer_font);
486 InsertChar(pos, minibuffer_char, minibuffer_font);
494 void LyXParagraph::Clear()
499 pagebreak_top = false;
500 pagebreak_bottom = false;
502 added_space_top = VSpace(VSpace::NONE);
503 added_space_bottom = VSpace(VSpace::NONE);
504 spacing.set(Spacing::Default);
506 align = LYX_ALIGN_LAYOUT;
510 pextra_type = PEXTRA_NONE;
511 pextra_width.erase();
512 pextra_widthp.erase();
513 pextra_alignment = MINIPAGE_ALIGN_TOP;
514 pextra_hfill = false;
515 pextra_start_minipage = false;
518 labelwidthstring.erase();
522 start_of_appendix = false;
526 // the destructor removes the new paragraph from the list
527 LyXParagraph::~LyXParagraph()
530 previous->next = next;
532 next->previous = previous;
534 for (InsetList::iterator it = insetlist.begin();
535 it != insetlist.end(); ++it) {
539 /* table stuff -- begin*/
541 /* table stuff -- end*/
547 //lyxerr << "LyXParagraph::paragraph_id = "
548 // << LyXParagraph::paragraph_id << endl;
552 void LyXParagraph::Erase(LyXParagraph::size_type pos)
554 // > because last is the next unused position, and you can
555 // use it if you want
558 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
559 NextAfterFootnote()->Erase(pos - text.size() - 1);
562 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
563 "position does not exist." << endl;
566 if (pos < size()) { // last is free for insertation, but should be empty
567 // if it is an inset, delete the inset entry
568 if (text[pos] == LyXParagraph::META_INSET) {
570 InsetTable search_inset(pos, 0);
571 InsetList::iterator it =
572 lower_bound(insetlist.begin(),
574 search_inset, matchIT());
575 if (it != insetlist.end() && (*it).pos == pos) {
580 text.erase(text.begin() + pos);
582 // Erase entries in the tables.
583 FontTable search_font(pos, LyXFont());
585 FontList::iterator it =
586 lower_bound(fontlist.begin(),
588 search_font, matchFT());
589 if (it != fontlist.end() && (*it).pos == pos &&
591 (it != fontlist.begin() && (*(it-1)).pos == pos - 1))) {
592 // If it is a multi-character font
593 // entry, we just make it smaller
594 // (see update below), otherwise we
596 unsigned int i = it - fontlist.begin();
597 fontlist.erase(fontlist.begin() + i);
598 it = fontlist.begin() + i;
599 if (i > 0 && i < fontlist.size() &&
600 fontlist[i-1].font == fontlist[i].font) {
601 fontlist.erase(fontlist.begin() + i-1);
602 it = fontlist.begin() + i-1;
606 // Update all other entries.
607 for (; it != fontlist.end(); ++it)
610 // Update the inset table.
611 InsetTable search_inset(pos, 0);
612 for (InsetList::iterator it =
613 upper_bound(insetlist.begin(),
615 search_inset, matchIT());
616 it != insetlist.end(); ++it)
619 lyxerr << "ERROR (LyXParagraph::Erase): "
620 "can't erase non-existant char." << endl;
625 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
626 LyXParagraph::value_type c)
628 LyXFont f(LyXFont::ALL_INHERIT);
629 InsertChar(pos, c, f);
633 void LyXParagraph::InsertChar(LyXParagraph::size_type pos,
634 LyXParagraph::value_type c,
635 LyXFont const & font)
637 // > because last is the next unused position, and you can
638 // use it if you want
642 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
643 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
647 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
648 "position does not exist." << endl;
651 text.insert(text.begin() + pos, c);
652 // Update the font table.
653 FontTable search_font(pos, LyXFont());
654 for (FontList::iterator it = lower_bound(fontlist.begin(),
656 search_font, matchFT());
657 it != fontlist.end(); ++it)
660 // Update the inset table.
661 InsetTable search_inset(pos, 0);
662 for (InsetList::iterator it = lower_bound(insetlist.begin(),
664 search_inset, matchIT());
665 it != insetlist.end(); ++it)
672 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
675 LyXFont f(LyXFont::ALL_INHERIT);
676 InsertInset(pos, inset, f);
680 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
681 Inset * inset, LyXFont const & font)
685 // > because last is the next unused position, and you can
686 // use it if you want
690 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
692 ->InsertInset(pos - text.size() - 1,
696 lyxerr << "ERROR (LyXParagraph::InsertInset): "
697 "position does not exist: " << pos << endl;
701 InsertChar(pos, META_INSET, font);
702 Assert(text[pos] == META_INSET);
704 // Add a new entry in the inset table.
705 InsetTable search_inset(pos, 0);
706 InsetList::iterator it = lower_bound(insetlist.begin(),
708 search_inset, matchIT());
709 if (it != insetlist.end() && (*it).pos == pos)
710 lyxerr << "ERROR (LyXParagraph::InsertInset): "
711 "there is an inset in position: " << pos << endl;
713 insetlist.insert(it, InsetTable(pos, inset));
715 inset->setOwner(inset_owner);
719 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
721 lyxerr << "LyXParagraph::InsertInsetAllowed" << endl;
724 return inset_owner->InsertInsetAllowed(inset);
729 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
734 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
735 return NextAfterFootnote()
736 ->GetInset(pos - text.size() - 1);
739 lyxerr << "ERROR (LyXParagraph::GetInset): "
740 "position does not exist: "
746 InsetTable search_inset(pos, 0);
747 InsetList::iterator it = lower_bound(insetlist.begin(),
749 search_inset, matchIT());
750 if (it != insetlist.end() && (*it).pos == pos)
753 lyxerr << "ERROR (LyXParagraph::GetInset): "
754 "Inset does not exist: " << pos << endl;
757 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
758 // Did this commenting out introduce a bug? So far I have not
759 // see any, please enlighten me. (Lgb)
760 // My guess is that since the inset does not exist, we might
761 // as well replace it with a space to prevent craches. (Asger)
766 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
771 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
772 return NextAfterFootnote()
773 ->GetInset(pos - text.size() - 1);
776 lyxerr << "ERROR (LyXParagraph::GetInset): "
777 "position does not exist: "
783 InsetTable search_inset(pos, 0);
784 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
786 search_inset, matchIT());
787 if (cit != insetlist.end() && (*cit).pos == pos)
790 lyxerr << "ERROR (LyXParagraph::GetInset): "
791 "Inset does not exist: " << pos << endl;
793 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
794 // Did this commenting out introduce a bug? So far I have not
795 // see any, please enlighten me. (Lgb)
796 // My guess is that since the inset does not exist, we might
797 // as well replace it with a space to prevent craches. (Asger)
802 // Gets uninstantiated font setting at position.
803 // Optimized after profiling. (Asger)
804 LyXFont LyXParagraph::GetFontSettings(BufferParams const & bparams,
805 LyXParagraph::size_type pos) const
808 FontTable search_font(pos, LyXFont());
809 FontList::const_iterator cit = lower_bound(fontlist.begin(),
811 search_font, matchFT());
812 if (cit != fontlist.end())
815 // > because last is the next unused position, and you can
816 // use it if you want
817 else if (pos > size()) {
820 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
821 return NextAfterFootnote()
822 ->GetFontSettings(bparams,
823 pos - text.size() - 1);
826 // Why is it an error to ask for the font of a
827 // position that does not exist? Would it be
828 // enough for this to be enabled on debug?
829 // We want strict error checking, but it's ok to only
830 // have it when debugging. (Asger)
831 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
832 "position does not exist. "
833 << pos << " (" << static_cast<int>(pos)
835 } else if (pos > 0) {
836 return GetFontSettings(bparams, pos - 1);
837 } else // pos = size() = 0
838 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
840 return LyXFont(LyXFont::ALL_INHERIT);
843 // Gets uninstantiated font setting at position 0
844 LyXFont LyXParagraph::GetFirstFontSettings() const
847 if (!fontlist.empty())
848 return fontlist[0].font;
852 else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
853 return NextAfterFootnote()->GetFirstFontSettings();
855 return LyXFont(LyXFont::ALL_INHERIT);
859 // Gets the fully instantiated font at a given position in a paragraph
860 // This is basically the same function as LyXText::GetFont() in text2.C.
861 // The difference is that this one is used for generating the LaTeX file,
862 // and thus cosmetic "improvements" are disallowed: This has to deliver
863 // the true picture of the buffer. (Asger)
864 // If position is -1, we get the layout font of the paragraph.
865 // If position is -2, we get the font of the manual label of the paragraph.
866 LyXFont LyXParagraph::getFont(BufferParams const & bparams,
867 LyXParagraph::size_type pos) const
870 LyXLayout const & layout =
871 textclasslist.Style(bparams.textclass,
873 LyXParagraph::size_type main_body = 0;
874 if (layout.labeltype == LABEL_MANUAL)
875 main_body = BeginningOfMainBody();
880 layoutfont = layout.labelfont;
882 layoutfont = layout.font;
883 tmpfont = GetFontSettings(bparams, pos);
884 tmpfont.realize(layoutfont);
886 // process layoutfont for pos == -1 and labelfont for pos < -1
888 tmpfont = layout.font;
890 tmpfont = layout.labelfont;
891 tmpfont.setLanguage(getParLanguage(bparams));
894 // check for environment font information
895 char par_depth = GetDepth();
896 LyXParagraph const * par = this;
897 while (par && par_depth && !tmpfont.resolved()) {
898 par = par->DepthHook(par_depth - 1);
900 tmpfont.realize(textclasslist.
901 Style(bparams.textclass,
902 par->GetLayout()).font);
903 par_depth = par->GetDepth();
907 tmpfont.realize(textclasslist
908 .TextClass(bparams.textclass)
914 /// Returns the height of the highest font in range
916 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
917 LyXParagraph::size_type endpos) const
919 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
920 if (fontlist.empty())
923 FontTable end_search(endpos, LyXFont());
924 FontList::const_iterator end_it = lower_bound(fontlist.begin(),
926 end_search, matchFT());
927 if (end_it != fontlist.end())
930 FontTable start_search(startpos, LyXFont());
931 for (FontList::const_iterator cit =
932 lower_bound(fontlist.begin(),
934 start_search, matchFT());
935 cit != end_it; ++cit) {
936 LyXFont::FONT_SIZE size = (*cit).font.size();
937 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
944 LyXParagraph::value_type
945 LyXParagraph::GetChar(LyXParagraph::size_type pos)
952 // > because last is the next unused position, and you can
953 // use it if you want
954 else if (pos > size()) {
956 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
957 return NextAfterFootnote()
958 ->GetChar(pos - text.size() - 1);
962 lyxerr << "ERROR (LyXParagraph::GetChar): "
963 "position does not exist."
964 << pos << " (" << static_cast<int>(pos)
966 // Assert(false); // This triggers sometimes...
975 // We should have a footnote environment.
976 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
977 // Notice that LyX does request the
978 // last char from time to time. (Asger)
979 //lyxerr << "ERROR (LyXParagraph::GetChar): "
980 // "expected footnote." << endl;
983 switch (next->footnotekind) {
984 case LyXParagraph::FOOTNOTE:
985 return LyXParagraph::META_FOOTNOTE;
986 case LyXParagraph::MARGIN:
987 return LyXParagraph::META_MARGIN;
988 case LyXParagraph::FIG:
989 case LyXParagraph::WIDE_FIG:
990 return LyXParagraph::META_FIG;
991 case LyXParagraph::TAB:
992 case LyXParagraph::WIDE_TAB:
993 return LyXParagraph::META_TAB;
994 case LyXParagraph::ALGORITHM:
995 return LyXParagraph::META_ALGORITHM;
997 return '\0'; // to shut up gcc
1000 return '\0'; // to shut up gcc
1005 LyXParagraph::value_type
1006 LyXParagraph::GetChar(LyXParagraph::size_type pos) const
1013 // > because last is the next unused position, and you can
1014 // use it if you want
1015 else if (pos > size()) {
1017 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1018 return NextAfterFootnote()
1019 ->GetChar(pos - text.size() - 1);
1023 lyxerr << "ERROR (LyXParagraph::GetChar const): "
1024 "position does not exist."
1025 << pos << " (" << static_cast<int>(pos)
1033 // We should have a footnote environment.
1034 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
1035 // Notice that LyX does request the
1036 // last char from time to time. (Asger)
1037 //lyxerr << "ERROR (LyXParagraph::GetChar): "
1038 // "expected footnote." << endl;
1041 switch (next->footnotekind) {
1042 case LyXParagraph::FOOTNOTE:
1043 return LyXParagraph::META_FOOTNOTE;
1044 case LyXParagraph::MARGIN:
1045 return LyXParagraph::META_MARGIN;
1046 case LyXParagraph::FIG:
1047 case LyXParagraph::WIDE_FIG:
1048 return LyXParagraph::META_FIG;
1049 case LyXParagraph::TAB:
1050 case LyXParagraph::WIDE_TAB:
1051 return LyXParagraph::META_TAB;
1052 case LyXParagraph::ALGORITHM:
1053 return LyXParagraph::META_ALGORITHM;
1055 return '\0'; // to shut up gcc
1058 return '\0'; // to shut up gcc
1064 // return an string of the current word, and the end of the word in lastpos.
1065 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
1069 // the current word is defined as starting at the first character
1070 // from the immediate left of lastpospos which meets the definition
1071 // of IsLetter(), continuing to the last character to the right
1072 // of this meeting IsLetter.
1078 // move back until we have a letter
1080 //there's no real reason to have firstpos & lastpos as
1081 //separate variables as this is written, but maybe someon
1082 // will want to return firstpos in the future.
1084 //since someone might have typed a punctuation first
1085 int firstpos = lastpos;
1087 while ((firstpos >= 0) && !IsLetter(firstpos))
1090 // now find the beginning by looking for a nonletter
1092 while ((firstpos>= 0) && IsLetter(firstpos))
1095 // the above is now pointing to the preceeding non-letter
1099 // so copy characters into theword until we get a nonletter
1100 // note that this can easily exceed lastpos, wich means
1101 // that if used in the middle of a word, the whole word
1104 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1111 LyXParagraph::size_type LyXParagraph::Last() const
1114 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1115 return text.size() + NextAfterFootnote()->Last() + 1;
1116 // the 1 is the symbol
1124 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1126 // > because last is the next unused position, and you can
1127 // use it if you want
1131 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1132 return NextAfterFootnote()
1133 ->ParFromPos(pos - text.size() - 1);
1136 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1137 "position does not exist." << endl;
1144 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1146 // > because last is the next unused position, and you can
1147 // use it if you want
1151 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1152 return NextAfterFootnote()
1153 ->PositionInParFromPos(pos - text.size() - 1);
1157 "ERROR (LyXParagraph::PositionInParFromPos): "
1158 "position does not exist." << endl;
1166 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1167 LyXFont const & font)
1169 // > because last is the next unused position, and you can
1170 // use it if you want
1174 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1175 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1179 lyxerr << "ERROR (LyXParagraph::SetFont): "
1180 "position does not exist." << endl;
1185 // First, reduce font against layout/label font
1186 // Update: The SetCharFont() routine in text2.C already
1187 // reduces font, so we don't need to do that here. (Asger)
1188 // No need to simplify this because it will disappear
1189 // in a new kernel. (Asger)
1190 // Next search font table
1192 FontTable search_font(pos, LyXFont());
1193 FontList::iterator it = lower_bound(fontlist.begin(),
1195 search_font, matchFT());
1196 unsigned int i = it - fontlist.begin();
1197 bool notfound = it == fontlist.end();
1199 if (!notfound && fontlist[i].font == font)
1202 bool begin = pos == 0 || notfound ||
1203 (i > 0 && fontlist[i-1].pos == pos - 1);
1204 // Is position pos is a beginning of a font block?
1205 bool end = !notfound && fontlist[i].pos == pos;
1206 // Is position pos is the end of a font block?
1207 if (begin && end) { // A single char block
1208 if (i+1 < fontlist.size() &&
1209 fontlist[i+1].font == font) {
1210 // Merge the singleton block with the next block
1211 fontlist.erase(fontlist.begin() + i);
1212 if (i > 0 && fontlist[i-1].font == font)
1213 fontlist.erase(fontlist.begin() + i-1);
1214 } else if (i > 0 && fontlist[i-1].font == font) {
1215 // Merge the singleton block with the previous block
1216 fontlist[i-1].pos = pos;
1217 fontlist.erase(fontlist.begin() + i);
1219 fontlist[i].font = font;
1221 if (i > 0 && fontlist[i-1].font == font)
1222 fontlist[i-1].pos = pos;
1224 fontlist.insert(fontlist.begin() + i,
1225 FontTable(pos, font));
1227 fontlist[i].pos = pos - 1;
1228 if (!(i+1 < fontlist.size() &&
1229 fontlist[i+1].font == font))
1230 fontlist.insert(fontlist.begin() + i+1,
1231 FontTable(pos, font));
1232 } else { // The general case. The block is splitted into 3 blocks
1233 fontlist.insert(fontlist.begin() + i,
1234 FontTable(pos - 1, fontlist[i].font));
1235 fontlist.insert(fontlist.begin() + i+1, FontTable(pos, font));
1240 // This function is able to hide closed footnotes.
1241 LyXParagraph * LyXParagraph::Next()
1244 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1245 LyXParagraph * tmp = next;
1247 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1249 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1250 return tmp->Next(); /* there can be more than one
1251 footnote in a logical
1254 return next; // This should never happen!
1262 LyXParagraph * LyXParagraph::NextAfterFootnote()
1264 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1265 LyXParagraph * tmp = next;
1266 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1268 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1269 return tmp; /* there can be more than one footnote
1270 in a logical paragraph */
1272 return next; // This should never happen!
1280 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1282 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1283 LyXParagraph * tmp = next;
1284 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1286 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1287 return tmp; /* there can be more than one footnote
1288 in a logical paragraph */
1290 return next; // This should never happen!
1298 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1301 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1303 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1304 tmp = tmp->previous;
1305 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1306 return tmp; /* there can be more than one footnote
1307 in a logical paragraph */
1309 return previous; // This should never happen!
1317 LyXParagraph * LyXParagraph::LastPhysicalPar()
1319 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1322 LyXParagraph * tmp = this;
1324 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1325 tmp = tmp->NextAfterFootnote();
1333 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1335 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1338 LyXParagraph const * tmp = this;
1340 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1341 tmp = tmp->NextAfterFootnote();
1349 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1353 LyXParagraph * tmppar = this;
1357 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1358 tmppar = tmppar->previous;
1369 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1373 LyXParagraph const * tmppar = this;
1377 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1378 tmppar = tmppar->previous;
1388 // This function is able to hide closed footnotes.
1389 LyXParagraph * LyXParagraph::Previous()
1392 LyXParagraph * tmp = previous;
1397 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1398 tmp = tmp->previous;
1400 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1401 tmp = tmp->previous;
1402 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1403 return tmp->next->Previous();
1413 // This function is able to hide closed footnotes.
1414 LyXParagraph const * LyXParagraph::Previous() const
1417 LyXParagraph * tmp = previous;
1421 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1422 tmp = tmp->previous;
1424 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1425 tmp = tmp->previous;
1426 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1427 return tmp->next->Previous();
1437 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1438 LyXParagraph::size_type pos,
1441 size_type i, j, pos_end, pos_first;
1442 // create a new paragraph
1443 LyXParagraph * par = ParFromPos(pos);
1445 LyXParagraph * firstpar = FirstPhysicalPar();
1447 LyXParagraph * firstpar = this;
1450 LyXParagraph * tmp = new LyXParagraph(par);
1453 tmp->footnoteflag = footnoteflag;
1454 tmp->footnotekind = footnotekind;
1456 // this is an idea for a more userfriendly layout handling, I will
1457 // see what the users say
1459 // layout stays the same with latex-environments
1461 tmp->SetOnlyLayout(bparams, firstpar->layout);
1462 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1465 if (Last() > pos || !Last() || flag == 2) {
1466 tmp->SetOnlyLayout(bparams, firstpar->layout);
1467 tmp->align = firstpar->align;
1468 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1470 tmp->line_bottom = firstpar->line_bottom;
1471 firstpar->line_bottom = false;
1472 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1473 firstpar->pagebreak_bottom = false;
1474 tmp->added_space_bottom = firstpar->added_space_bottom;
1475 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1477 tmp->depth = firstpar->depth;
1478 tmp->noindent = firstpar->noindent;
1480 // copy everything behind the break-position
1481 // to the new paragraph
1483 while (ParFromPos(pos_first) != par)
1486 pos_end = pos_first + par->text.size() - 1;
1488 for (i = j = pos; i <= pos_end; ++i) {
1489 par->CutIntoMinibuffer(bparams, i - pos_first);
1490 if (tmp->InsertFromMinibuffer(j - pos))
1493 tmp->text.resize(tmp->text.size());
1494 for (i = pos_end; i >= pos; --i)
1495 par->Erase(i - pos_first);
1497 par->text.resize(par->text.size());
1500 // just an idea of me
1502 tmp->line_top = firstpar->line_top;
1503 tmp->pagebreak_top = firstpar->pagebreak_top;
1504 tmp->added_space_top = firstpar->added_space_top;
1505 tmp->bibkey = firstpar->bibkey;
1507 // layout stays the same with latex-environments
1509 firstpar->SetOnlyLayout(bparams, tmp->layout);
1510 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1511 firstpar->depth = tmp->depth;
1517 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1520 par = par->FirstPhysicalPar();
1521 footnoteflag = par->footnoteflag;
1522 footnotekind = par->footnotekind;
1524 layout = par->layout;
1525 align = par-> align;
1526 SetLabelWidthString(par->labelwidthstring);
1528 line_bottom = par->line_bottom;
1529 pagebreak_bottom = par->pagebreak_bottom;
1530 added_space_bottom = par->added_space_bottom;
1532 line_top = par->line_top;
1533 pagebreak_top = par->pagebreak_top;
1534 added_space_top = par->added_space_top;
1536 spacing = par->spacing;
1538 pextra_type = par->pextra_type;
1539 pextra_width = par->pextra_width;
1540 pextra_widthp = par->pextra_widthp;
1541 pextra_alignment = par->pextra_alignment;
1542 pextra_hfill = par->pextra_hfill;
1543 pextra_start_minipage = par->pextra_start_minipage;
1545 noindent = par->noindent;
1551 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1553 LyXParagraph * tmppar = this;
1556 && tmppar->previous->footnoteflag ==
1557 LyXParagraph::CLOSED_FOOTNOTE)
1558 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1559 tmppar = tmppar->previous;
1562 return this; // This should never happen!
1569 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1571 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1586 && (IsNewline(0) || IsLineSeparator(0))){
1595 LyXParagraph * LyXParagraph::Clone() const
1597 // create a new paragraph
1598 LyXParagraph * result = new LyXParagraph;
1600 result->MakeSameLayout(this);
1602 // this is because of the dummy layout of the paragraphs that
1604 result->layout = layout;
1607 /* table stuff -- begin*/
1609 result->table = table->Clone();
1612 /* table stuff -- end*/
1614 result->inset_owner = inset_owner;
1617 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1620 // copy everything behind the break-position to the new paragraph
1622 result->text = text;
1623 result->fontlist = fontlist;
1624 result->insetlist = insetlist;
1625 for (InsetList::iterator it = result->insetlist.begin();
1626 it != result->insetlist.end(); ++it)
1627 (*it).inset = (*it).inset->Clone();
1632 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1635 par = par->FirstPhysicalPar();
1640 par->footnoteflag == footnoteflag &&
1641 par->footnotekind == footnotekind &&
1643 par->layout == layout &&
1645 par->align == align &&
1647 par->line_bottom == line_bottom &&
1648 par->pagebreak_bottom == pagebreak_bottom &&
1649 par->added_space_bottom == added_space_bottom &&
1651 par->line_top == line_top &&
1652 par->pagebreak_top == pagebreak_top &&
1653 par->added_space_top == added_space_top &&
1655 par->spacing == spacing &&
1657 par->pextra_type == pextra_type &&
1658 par->pextra_width == pextra_width &&
1659 par->pextra_widthp == pextra_widthp &&
1660 par->pextra_alignment == pextra_alignment &&
1661 par->pextra_hfill == pextra_hfill &&
1662 par->pextra_start_minipage == pextra_start_minipage &&
1664 par->table == table && // what means: NO TABLE AT ALL
1667 par->noindent == noindent &&
1668 par->depth == depth);
1672 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1673 LyXParagraph::size_type pos)
1675 // create a new paragraph
1676 LyXParagraph * par = ParFromPos(pos);
1678 LyXParagraph * tmp = new LyXParagraph(par);
1680 tmp->MakeSameLayout(par);
1682 // When can pos < Last()?
1683 // I guess pos == Last() is possible.
1685 // copy everything behind the break-position to the new
1687 size_type pos_first = 0;
1688 while (ParFromPos(pos_first) != par)
1690 size_type pos_end = pos_first + par->text.size() - 1;
1693 for (i = j = pos; i <= pos_end; ++i) {
1694 par->CutIntoMinibuffer(bparams, i - pos_first);
1695 if (tmp->InsertFromMinibuffer(j - pos))
1698 tmp->text.resize(tmp->text.size());
1699 for (size_type i = pos_end; i >= pos; --i)
1700 par->Erase(i - pos_first);
1702 par->text.resize(par->text.size());
1707 // Be carefull, this does not make any check at all.
1708 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1710 // copy the next paragraph to this one
1711 LyXParagraph * the_next = Next();
1713 LyXParagraph * firstpar = FirstPhysicalPar();
1715 LyXParagraph * firstpar = this;
1718 // first the DTP-stuff
1719 firstpar->line_bottom = the_next->line_bottom;
1720 firstpar->added_space_bottom = the_next->added_space_bottom;
1721 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1723 size_type pos_end = the_next->text.size() - 1;
1724 size_type pos_insert = Last();
1726 // ok, now copy the paragraph
1728 for (i = j = 0; i <= pos_end; ++i) {
1729 the_next->CutIntoMinibuffer(bparams, i);
1730 if (InsertFromMinibuffer(pos_insert + j))
1734 // delete the next paragraph
1735 LyXParagraph * ppar = the_next->previous;
1736 LyXParagraph * npar = the_next->next;
1743 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1745 LyXParagraph * par = ParFromPos(pos);
1747 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1748 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1754 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1756 LyXParagraph * par = ParFromPos(pos);
1758 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1759 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1766 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1768 LyXParagraph const * par = this;
1769 int par_depth = GetDepth();
1771 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1773 textclasslist.Style(bparams.textclass,
1774 layout).endlabeltype;
1775 if (endlabeltype != END_LABEL_NO_LABEL) {
1776 LyXParagraph const * last = this;
1778 if( footnoteflag == NO_FOOTNOTE)
1779 last = LastPhysicalPar();
1780 else if (next->footnoteflag == NO_FOOTNOTE)
1781 return endlabeltype;
1786 if (!last || !last->next)
1787 return endlabeltype;
1789 int next_depth = last->next->GetDepth();
1790 if (par_depth > next_depth ||
1791 (par_depth == next_depth && layout != last->next->GetLayout() ))
1792 return endlabeltype;
1797 par = par->DepthHook(par_depth - 1);
1799 par_depth = par->GetDepth();
1801 return END_LABEL_NO_LABEL;
1805 LyXTextClass::size_type LyXParagraph::GetLayout() const
1808 return FirstPhysicalPar()->layout;
1815 char LyXParagraph::GetDepth() const
1818 return FirstPhysicalPar()->depth;
1825 char LyXParagraph::GetAlign() const
1828 return FirstPhysicalPar()->align;
1835 string const & LyXParagraph::GetLabelstring() const
1838 return FirstPhysicalPar()->labelstring;
1845 int LyXParagraph::GetFirstCounter(int i) const
1848 return FirstPhysicalPar()->counter_[i];
1855 // the next two functions are for the manual labels
1856 string LyXParagraph::GetLabelWidthString() const
1859 if (!FirstPhysicalPar()->labelwidthstring.empty())
1860 return FirstPhysicalPar()->labelwidthstring;
1862 if (!labelwidthstring.empty())
1863 return labelwidthstring;
1866 return _("Senseless with this layout!");
1870 void LyXParagraph::SetLabelWidthString(string const & s)
1873 LyXParagraph * par = FirstPhysicalPar();
1875 par->labelwidthstring = s;
1877 labelwidthstring = s;
1882 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1883 LyXTextClass::size_type new_layout)
1886 LyXParagraph * par = FirstPhysicalPar();
1888 LyXParagraph * par = this;
1890 LyXParagraph * ppar = 0;
1891 LyXParagraph * npar = 0;
1893 par->layout = new_layout;
1895 /* table stuff -- begin*/
1898 /* table stuff -- end*/
1900 if (par->pextra_type == PEXTRA_NONE) {
1901 if (par->Previous()) {
1903 ppar = par->Previous()->FirstPhysicalPar();
1905 ppar = par->Previous();
1909 && (ppar->depth > par->depth))
1911 ppar = ppar->Previous()->FirstPhysicalPar();
1913 ppar = ppar->Previous();
1918 npar = par->Next()->NextAfterFootnote();
1924 && (npar->depth > par->depth))
1926 npar = npar->Next()->NextAfterFootnote();
1928 npar = npar->Next();
1931 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1933 p1 = ppar->pextra_width,
1934 p2 = ppar->pextra_widthp;
1935 ppar->SetPExtraType(bparams, ppar->pextra_type,
1936 p1.c_str(), p2.c_str());
1938 if ((par->pextra_type == PEXTRA_NONE) &&
1939 npar && (npar->pextra_type != PEXTRA_NONE)) {
1941 p1 = npar->pextra_width,
1942 p2 = npar->pextra_widthp;
1943 npar->SetPExtraType(bparams, npar->pextra_type,
1944 p1.c_str(), p2.c_str());
1950 void LyXParagraph::SetLayout(BufferParams const & bparams,
1951 LyXTextClass::size_type new_layout)
1955 * par = FirstPhysicalPar(),
1962 par->layout = new_layout;
1963 par->labelwidthstring.erase();
1964 par->align = LYX_ALIGN_LAYOUT;
1965 par->added_space_top = VSpace(VSpace::NONE);
1966 par->added_space_bottom = VSpace(VSpace::NONE);
1967 par->spacing.set(Spacing::Default);
1970 /* table stuff -- begin*/
1973 /* table stuff -- end*/
1975 if (par->pextra_type == PEXTRA_NONE) {
1976 if (par->Previous()) {
1978 ppar = par->Previous()->FirstPhysicalPar();
1980 ppar = par->Previous();
1984 && (ppar->depth > par->depth))
1986 ppar = ppar->Previous()->FirstPhysicalPar();
1988 ppar = ppar->Previous();
1993 npar = par->Next()->NextAfterFootnote();
1999 && (npar->depth > par->depth))
2001 npar = npar->Next()->NextAfterFootnote();
2003 npar = npar->Next();
2006 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
2008 p1 = ppar->pextra_width,
2009 p2 = ppar->pextra_widthp;
2010 ppar->SetPExtraType(bparams, ppar->pextra_type,
2011 p1.c_str(), p2.c_str());
2013 if ((par->pextra_type == PEXTRA_NONE) &&
2014 npar && (npar->pextra_type != PEXTRA_NONE)) {
2016 p1 = npar->pextra_width,
2017 p2 = npar->pextra_widthp;
2018 npar->SetPExtraType(bparams, npar->pextra_type,
2019 p1.c_str(), p2.c_str());
2025 // if the layout of a paragraph contains a manual label, the beginning of the
2026 // main body is the beginning of the second word. This is what the par-
2027 // function returns. If the layout does not contain a label, the main
2028 // body always starts with position 0. This differentiation is necessary,
2029 // because there cannot be a newline or a blank <= the beginning of the
2030 // main body in TeX.
2032 int LyXParagraph::BeginningOfMainBody() const
2035 if (FirstPhysicalPar() != this)
2038 // Unroll the first two cycles of the loop
2039 // and remember the previous character to
2040 // remove unnecessary GetChar() calls
2043 && GetChar(i) != LyXParagraph::META_NEWLINE
2046 char previous_char = 0, temp = 0;
2048 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2049 // Yes, this ^ is supposed to be "= " not "=="
2052 && previous_char != ' '
2053 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
2055 previous_char = temp;
2061 if (i == 0 && i == size() &&
2062 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
2063 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
2064 ++i; /* the cursor should not jump
2065 * to the main body if there
2072 LyXParagraph * LyXParagraph::DepthHook(int deth)
2074 LyXParagraph * newpar = this;
2080 newpar = newpar->FirstPhysicalPar()->Previous();
2082 newpar = newpar->Previous();
2084 } while (newpar && newpar->GetDepth() > deth
2086 && newpar->footnoteflag == footnoteflag
2091 if (Previous() || GetDepth())
2092 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2097 return newpar->FirstPhysicalPar();
2104 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
2106 LyXParagraph const * newpar = this;
2112 newpar = newpar->FirstPhysicalPar()->Previous();
2114 newpar = newpar->Previous();
2116 } while (newpar && newpar->GetDepth() > deth
2118 && newpar->footnoteflag == footnoteflag
2123 if (Previous() || GetDepth())
2124 lyxerr << "ERROR (LyXParagraph::DepthHook): "
2129 return newpar->FirstPhysicalPar();
2136 int LyXParagraph::AutoDeleteInsets()
2139 InsetList::size_type index = 0;
2140 while (index < insetlist.size()) {
2141 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
2142 Erase(insetlist[index].pos);
2143 // Erase() calls to insetlist.erase(&insetlist[index])
2144 // so index shouldn't be increased.
2153 LyXParagraph::inset_iterator
2154 LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
2156 InsetTable search_inset(pos, 0);
2157 InsetList::iterator it = lower_bound(insetlist.begin(),
2159 search_inset, matchIT());
2160 return inset_iterator(it);
2164 // returns -1 if inset not found
2165 int LyXParagraph::GetPositionOfInset(Inset * inset) const
2168 // We could use lower_bound here too, we just need to add
2169 // the approp. operator() to matchIT (and change the name
2170 // of that struct). Code would then be:
2171 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
2173 // inset, matchIT());
2174 // if ((*cit).inset == inset) {
2175 // return (*cit).pos;
2177 for (InsetList::const_iterator cit = insetlist.begin();
2178 cit != insetlist.end(); ++cit) {
2179 if ((*cit).inset == inset) {
2184 // Think about footnotes.
2185 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2186 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2188 NextAfterFootnote()->GetPositionOfInset(inset);
2190 return text.size() + 1 + further;
2197 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2198 BufferParams const & bparams,
2199 ostream & os, TexRow & texrow,
2204 TexRow & foot_texrow,
2209 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2210 LyXLayout const & style =
2211 textclasslist.Style(bparams.textclass,
2214 bool further_blank_line = false;
2217 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2220 if (start_of_appendix) {
2221 os << "\\appendix\n";
2225 if (!spacing.isDefault()
2226 && (!Previous() || !Previous()->HasSameLayout(this))) {
2227 os << spacing.writeEnvirBegin() << "\n";
2231 if (tex_code_break_column && style.isCommand()){
2236 if (pagebreak_top) {
2238 further_blank_line = true;
2240 if (added_space_top.kind() != VSpace::NONE) {
2241 os << added_space_top.asLatexCommand(bparams);
2242 further_blank_line = true;
2246 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2247 << "\\vspace{-1\\parskip}";
2248 further_blank_line = true;
2251 if (further_blank_line){
2256 Language const * language = getParLanguage(bparams);
2257 Language const * doc_language = bparams.language_info;
2258 Language const * previous_language = previous
2259 ? previous->getParLanguage(bparams) : doc_language;
2260 if (language != doc_language && language != previous_language) {
2261 os << subst(lyxrc.language_command_begin, "$$lang",
2267 if (bparams.inputenc == "auto" &&
2268 language->encoding() != previous_language->encoding()) {
2269 os << "\\inputencoding{"
2270 << language->encoding()->LatexName()
2275 switch (style.latextype) {
2278 << style.latexname()
2279 << style.latexparam();
2281 case LATEX_ITEM_ENVIRONMENT:
2283 bibkey->Latex(buf, os, false, false);
2287 case LATEX_LIST_ENVIRONMENT:
2294 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2296 LyXParagraph * par = next;
2298 // Spit out footnotes
2299 if (lyxrc.rtl_support) {
2300 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2301 && next->footnoteflag != footnoteflag) {
2302 LyXParagraph * p = 0;
2303 bool is_rtl = (size() > 0)
2304 ? GetFontSettings(bparams,
2305 size()-1).isRightToLeft()
2306 : language->RightToLeft();
2307 if ( (p = NextAfterFootnote()) != 0 &&
2309 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2310 is_rtl = getParLanguage(bparams)->RightToLeft();
2311 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2312 && par->footnoteflag != footnoteflag) {
2313 par = par->TeXFootnote(buf, bparams,
2315 foot_texrow, foot_count,
2317 par->SimpleTeXOnePar(buf, bparams,
2318 os, texrow, moving_arg);
2319 is_rtl = (par->size() > 0)
2320 ? par->GetFontSettings(bparams,
2321 par->size()-1).isRightToLeft()
2322 : language->RightToLeft();
2324 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2325 (p = par->NextAfterFootnote()) != 0 &&
2327 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2328 is_rtl = language->RightToLeft();
2333 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2334 && par->footnoteflag != footnoteflag) {
2335 par = par->TeXFootnote(buf, bparams,
2337 foot, foot_texrow, foot_count,
2339 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2345 // Make sure that \\par is done with the font of the last
2346 // character if this has another size as the default.
2347 // This is necessary because LaTeX (and LyX on the screen)
2348 // calculates the space between the baselines according
2349 // to this font. (Matthias)
2350 LyXFont font = getFont(bparams, Last() - 1);
2352 if (style.resfont.size() != font.size()) {
2358 } else if (textclasslist.Style(bparams.textclass,
2359 GetLayout()).isCommand()) {
2360 if (style.resfont.size() != font.size()) {
2366 } else if (style.resfont.size() != font.size()){
2367 os << "{\\" << font.latexSize() << " \\par}";
2370 if (language != doc_language &&
2373 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2375 || par->getParLanguage(bparams) != language)) {
2377 << subst(lyxrc.language_command_end, "$$lang",
2378 doc_language->lang());
2381 switch (style.latextype) {
2382 case LATEX_ITEM_ENVIRONMENT:
2383 case LATEX_LIST_ENVIRONMENT:
2384 if (par && (depth < par->depth)) {
2389 case LATEX_ENVIRONMENT:
2390 // if its the last paragraph of the current environment
2391 // skip it otherwise fall through
2393 && (par->layout != layout
2394 || par->depth != depth
2395 || par->pextra_type != pextra_type))
2398 // we don't need it for the last paragraph!!!
2401 && !( footnoteflag != LyXParagraph::NO_FOOTNOTE
2402 && footnotekind != LyXParagraph::FOOTNOTE
2403 && footnotekind != LyXParagraph::MARGIN)
2411 // don't insert this if we would be adding it
2412 // before or after a table in a float. This
2413 // little trick is needed in order to allow
2414 // use of tables in \subfigures or \subtables.
2420 further_blank_line = false;
2422 os << "\\lyxline{\\" << getFont(bparams, Last() - 1).latexSize() << '}';
2423 further_blank_line = true;
2426 if (added_space_bottom.kind() != VSpace::NONE) {
2427 os << added_space_bottom.asLatexCommand(bparams);
2428 further_blank_line = true;
2431 if (pagebreak_bottom) {
2433 further_blank_line = true;
2436 if (further_blank_line){
2441 if (!spacing.isDefault()
2442 && (!par || !par->HasSameLayout(this))) {
2443 os << spacing.writeEnvirEnd() << "\n";
2447 // we don't need it for the last paragraph!!!
2450 && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2451 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)
2458 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2463 // This one spits out the text of the paragraph
2464 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2465 BufferParams const & bparams,
2466 ostream & os, TexRow & texrow,
2469 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2473 return SimpleTeXOneTablePar(buf, bparams, os, texrow);
2476 bool return_value = false;
2478 LyXLayout const & style =
2479 textclasslist.Style(bparams.textclass,
2481 LyXFont basefont, last_font;
2483 // Maybe we have to create a optional argument.
2484 size_type main_body;
2485 if (style.labeltype != LABEL_MANUAL)
2488 main_body = BeginningOfMainBody();
2490 if (main_body > 0) {
2492 basefont = getFont(bparams, -2); // Get label font
2494 basefont = getFont(bparams, -1); // Get layout font
2505 if (style.isCommand()) {
2508 } else if (align != LYX_ALIGN_LAYOUT) {
2511 return_value = true;
2515 moving_arg |= style.needprotect;
2517 // Which font is currently active?
2518 LyXFont running_font(basefont);
2519 // Do we have an open font change?
2520 bool open_font = false;
2522 texrow.start(this, 0);
2524 for (size_type i = 0; i < size(); ++i) {
2526 // First char in paragraph or after label?
2532 if (main_body > 0) {
2534 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2537 basefont = getFont(bparams, -1); // Now use the layout font
2538 running_font = basefont;
2542 if (style.isCommand()) {
2545 } else if (align != LYX_ALIGN_LAYOUT) {
2548 return_value = true;
2552 os << "\\noindent ";
2556 case LYX_ALIGN_NONE:
2557 case LYX_ALIGN_BLOCK:
2558 case LYX_ALIGN_LAYOUT:
2559 case LYX_ALIGN_SPECIAL:
2561 case LYX_ALIGN_LEFT:
2562 if (getParLanguage(bparams)->lang() != "hebrew") {
2563 os << "\\raggedright ";
2566 os << "\\raggedleft ";
2570 case LYX_ALIGN_RIGHT:
2571 if (getParLanguage(bparams)->lang() != "hebrew") {
2572 os << "\\raggedleft ";
2575 os << "\\raggedright ";
2579 case LYX_ALIGN_CENTER:
2580 os << "\\centering ";
2586 value_type c = GetChar(i);
2588 // Fully instantiated font
2589 LyXFont font = getFont(bparams, i);
2591 LyXParagraph * p = 0;
2594 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2595 (p = PreviousBeforeFootnote()) != 0)
2596 last_font = p->getFont(bparams, p->size() - 1);
2599 last_font = running_font;
2601 // Spaces at end of font change are simulated to be
2602 // outside font change, i.e. we write "\textXX{text} "
2603 // rather than "\textXX{text }". (Asger)
2604 if (open_font && c == ' ' && i <= size() - 2
2605 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2606 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2607 font = getFont(bparams, i + 1);
2609 // We end font definition before blanks
2610 if (!font.equalExceptLatex(running_font) && open_font) {
2611 column += running_font.latexWriteEndChanges(os,
2613 (i == main_body-1) ? basefont : font);
2614 running_font = basefont;
2618 // Blanks are printed before start of fontswitch
2620 // Do not print the separation of the optional argument
2621 if (i != main_body - 1) {
2622 SimpleTeXBlanks(os, texrow, i,
2623 column, font, style);
2627 // Do we need to change font?
2628 if (!font.equalExceptLatex(running_font)
2629 && i != main_body-1) {
2630 column += font.latexWriteStartChanges(os, basefont,
2632 running_font = font;
2636 if (c == LyXParagraph::META_NEWLINE) {
2637 // newlines are handled differently here than
2638 // the default in SimpleTeXSpecialChars().
2639 if (!style.newline_allowed
2640 || font.latex() == LyXFont::ON) {
2644 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2647 basefont = getFont(bparams, -1);
2648 running_font = basefont;
2649 if (font.family() ==
2650 LyXFont::TYPEWRITER_FAMILY) {
2658 texrow.start(this, i + 1);
2661 SimpleTeXSpecialChars(buf, bparams,
2662 os, texrow, moving_arg,
2663 font, running_font, basefont,
2664 open_font, style, i, column, c);
2668 // If we have an open font definition, we have to close it
2670 LyXParagraph * p = 0;
2673 && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2674 && (p = NextAfterFootnote()) != 0
2679 running_font.latexWriteEndChanges(os, basefont,
2680 p->getFont(bparams, 0));
2682 running_font.latexWriteEndChanges(os, basefont, basefont);
2685 // Needed if there is an optional argument but no contents.
2686 if (main_body > 0 && main_body == size()) {
2688 return_value = false;
2691 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2692 return return_value;
2697 // This one spits out the text of a table paragraph
2698 bool LyXParagraph::SimpleTeXOneTablePar(Buffer const * buf,
2699 BufferParams const & bparams,
2700 ostream & os, TexRow & texrow)
2702 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2704 bool return_value = false;
2706 LyXLayout const & style =
2707 textclasslist.Style(bparams.textclass, GetLayout());
2711 if (!IsDummy()) { // it is dummy if it is in a float!!!
2713 if (style.isCommand()) {
2716 } else if (align != LYX_ALIGN_LAYOUT) {
2719 return_value = true;
2722 os << "\\noindent ";
2726 case LYX_ALIGN_NONE:
2727 case LYX_ALIGN_BLOCK:
2728 case LYX_ALIGN_LAYOUT:
2729 case LYX_ALIGN_SPECIAL: break;
2730 case LYX_ALIGN_LEFT:
2731 os << "\\raggedright ";
2734 case LYX_ALIGN_RIGHT:
2735 os << "\\raggedleft ";
2738 case LYX_ALIGN_CENTER:
2739 os << "\\centering ";
2747 LyXFont basefont = getFont(bparams, -1); // Get layout font
2748 // Which font is currently active?
2749 LyXFont running_font = basefont;
2751 // Do we have an open font change?
2752 bool open_font = false;
2753 int current_cell_number = -1;
2754 int tmp = table->TexEndOfCell(os, current_cell_number);
2755 for (; tmp > 0 ; --tmp)
2758 texrow.start(this, 0);
2760 bool is_rtl = getParLanguage(bparams)->RightToLeft();
2761 bool first_in_cell = true;
2763 for (size_type i = 0; i < size(); ++i) {
2764 value_type c = GetChar(i);
2765 if (table->IsContRow(current_cell_number + 1)) {
2766 if (c == LyXParagraph::META_NEWLINE)
2767 ++current_cell_number;
2772 if (first_in_cell && is_rtl) {
2775 first_in_cell = false;
2778 // Fully instantiated font
2779 LyXFont font = getFont(bparams, i);
2780 last_font = running_font;
2782 // Spaces at end of font change are simulated to be
2783 // outside font change.
2784 // i.e. we write "\textXX{text} " rather than
2785 // "\textXX{text }". (Asger)
2786 if (open_font && c == ' ' && i <= size() - 2
2787 && getFont(bparams, i + 1) != running_font
2788 && getFont(bparams, i + 1) != font) {
2789 font = getFont(bparams, i + 1);
2792 // We end font definition before blanks
2793 if (font != running_font && open_font) {
2794 column += running_font.latexWriteEndChanges(os,
2797 running_font = basefont;
2800 // Blanks are printed before start of fontswitch
2802 SimpleTeXBlanks(os, texrow, i, column, font, style);
2804 // Do we need to change font?
2805 if (font != running_font) {
2806 column += font.latexWriteStartChanges(os, basefont,
2808 running_font = font;
2811 // Do we need to turn on LaTeX mode?
2812 if (font.latex() != running_font.latex()) {
2813 if (font.latex() == LyXFont::ON
2814 && style.needprotect) {
2819 if (c == LyXParagraph::META_NEWLINE) {
2820 // special case for inside a table
2821 // different from default case in
2822 // SimpleTeXSpecialChars()
2824 column += running_font
2825 .latexWriteEndChanges(os, basefont,
2829 basefont = getFont(bparams, -1);
2830 running_font = basefont;
2831 ++current_cell_number;
2832 if (table->CellHasContRow(current_cell_number) >= 0) {
2833 TeXContTableRows(buf, bparams, os, i + 1,
2834 current_cell_number,
2837 if (is_rtl && !first_in_cell) {
2839 first_in_cell = true;
2842 // if this cell follow only ContRows till end don't
2843 // put the EndOfCell because it is put after the
2845 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2846 --current_cell_number;
2849 int tmp = table->TexEndOfCell(os,
2850 current_cell_number);
2853 } else if (tmp < 0) {
2859 texrow.start(this, i + 1);
2861 SimpleTeXSpecialChars(buf, bparams,
2863 font, running_font, basefont,
2864 open_font, style, i, column, c);
2868 // If we have an open font definition, we have to close it
2870 running_font.latexWriteEndChanges(os, basefont, basefont);
2872 ++current_cell_number;
2873 if (is_rtl && !first_in_cell)
2875 tmp = table->TexEndOfCell(os, current_cell_number);
2876 for (; tmp > 0; --tmp)
2878 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2879 return return_value;
2885 // This one spits out the text off ContRows in tables
2886 bool LyXParagraph::TeXContTableRows(Buffer const * buf,
2887 BufferParams const & bparams,
2889 LyXParagraph::size_type i,
2890 int current_cell_number,
2891 int & column, TexRow & texrow)
2893 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2897 bool return_value = false;
2898 LyXLayout const & style =
2899 textclasslist.Style(bparams.textclass,
2901 LyXFont basefont = getFont(bparams, -1); // Get layout font
2903 // Which font is currently active?
2904 LyXFont running_font = basefont;
2905 // Do we have an open font change?
2906 bool open_font = false;
2908 size_type lastpos = i;
2909 int cell = table->CellHasContRow(current_cell_number);
2910 ++current_cell_number;
2913 // first find the right position
2915 for (; (i < size()) && (current_cell_number < cell); ++i) {
2917 if (c == LyXParagraph::META_NEWLINE)
2918 ++current_cell_number;
2922 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2926 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2931 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2935 // Fully instantiated font
2936 LyXFont font = getFont(bparams, i);
2937 last_font = running_font;
2939 // Spaces at end of font change are simulated to
2940 // be outside font change. i.e. we write
2941 // "\textXX{text} " rather than "\textXX{text }".
2943 if (open_font && c == ' ' && i <= size() - 2
2944 && getFont(bparams, i + 1) != running_font
2945 && getFont(bparams, i + 1) != font) {
2946 font = getFont(bparams, i + 1);
2949 // We end font definition before blanks
2950 if (font != running_font && open_font) {
2951 column += running_font.latexWriteEndChanges(os, basefont, font);
2952 running_font = basefont;
2955 // Blanks are printed before start of fontswitch
2957 SimpleTeXBlanks(os, texrow, i,
2958 column, font, style);
2960 // Do we need to change font?
2961 if (font != running_font) {
2963 font.latexWriteStartChanges(os,
2966 running_font = font;
2969 // Do we need to turn on LaTeX mode?
2970 if (font.latex() != running_font.latex()) {
2971 if (font.latex() == LyXFont::ON
2972 && style.needprotect) {
2977 SimpleTeXSpecialChars(buf, bparams,
2978 os, texrow, false, font,
2979 running_font, basefont,
2980 open_font, style, i, column, c);
2982 // If we have an open font definition, we have to close it
2984 running_font.latexWriteEndChanges(os, basefont,
2988 basefont = getFont(bparams, -1);
2989 running_font = basefont;
2990 cell = table->CellHasContRow(current_cell_number);
2992 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2993 return return_value;
2998 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
3000 bool retval = false;
3002 case LyXParagraph::META_HFILL:
3003 sgml_string.erase();
3005 case LyXParagraph::META_NEWLINE:
3009 sgml_string = "&";
3012 sgml_string = "<";
3015 sgml_string = ">";
3018 sgml_string = "$";
3021 sgml_string = "#";
3024 sgml_string = "%";
3027 sgml_string = "[";
3030 sgml_string = "]";
3033 sgml_string = "{";
3036 sgml_string = "}";
3039 sgml_string = "˜";
3042 sgml_string = """;
3045 sgml_string = "\";
3051 case '\0': // Ignore :-)
3052 sgml_string.erase();
3063 void LyXParagraph::SimpleDocBookOneTablePar(Buffer const * buffer,
3064 ostream & os, string & extra,
3065 int & desc_on, int depth)
3067 BufferParams const & bparams = buffer->params;
3069 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
3071 LyXFont font1, font2;
3074 size_type main_body;
3075 bool emph_flag = false;
3077 LyXLayout const & style =
3078 textclasslist.Style(bparams.textclass,
3081 if (style.labeltype != LABEL_MANUAL)
3084 main_body = BeginningOfMainBody();
3086 // Gets paragraph main font.
3088 font1 = style.labelfont;
3092 int char_line_count = depth;
3093 os << newlineAndDepth(depth);
3095 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
3096 os << "<INFORMALTABLE>"
3097 << newlineAndDepth(++depth);
3100 os << "<INFORMALTABLE>"
3101 << newlineAndDepth(++depth);
3103 int current_cell_number = -1;
3104 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3106 // Parsing main loop.
3107 for (size_type i = 0; i < size(); ++i) {
3109 if (table->IsContRow(current_cell_number+1)) {
3110 if (c == LyXParagraph::META_NEWLINE)
3111 ++current_cell_number;
3116 // Fully instantiated font
3117 font2 = getFont(bparams, i);
3119 // Handle <emphasis> tag.
3120 if (font1.emph() != font2.emph() && i) {
3121 if (font2.emph() == LyXFont::ON) {
3124 } else if (emph_flag) {
3125 os << "</emphasis>";
3129 if (c == LyXParagraph::META_NEWLINE) {
3130 // We have only to control for emphasis open here!
3132 os << "</emphasis>";
3135 font1 = font2 = getFont(bparams, -1);
3136 ++current_cell_number;
3137 if (table->CellHasContRow(current_cell_number) >= 0) {
3138 DocBookContTableRows(buffer,
3139 os, extra, desc_on, i + 1,
3140 current_cell_number,
3143 // if this cell follow only ContRows till end don't
3144 // put the EndOfCell because it is put after the
3146 if (table->ShouldBeVeryLastCell(current_cell_number)) {
3147 --current_cell_number;
3150 tmp = table->DocBookEndOfCell(os,
3151 current_cell_number,
3156 } else if (c == LyXParagraph::META_INSET) {
3157 inset = GetInset(i);
3159 std::ostringstream ost;
3160 inset->DocBook(buffer, ost);
3161 string tmp_out = ost.str().c_str();
3164 inset->DocBook(buffer, ost);
3166 char * ctmp = ost.str();
3167 string tmp_out(ctmp);
3171 // This code needs some explanation:
3172 // Two insets are treated specially
3173 // label if it is the first element in a
3174 // command paragraph
3176 // graphics inside tables or figure floats
3178 // title (the equivalente in latex for this
3180 // and title should come first
3183 if(desc_on != 3 || i != 0) {
3184 if(tmp_out[0] == '@') {
3186 extra += frontStrip(tmp_out,
3189 os << frontStrip(tmp_out,
3194 } else if (font2.latex() == LyXFont::ON) {
3195 // "TeX"-Mode on == > SGML-Mode on.
3201 if (linuxDocConvertChar(c, sgml_string)
3202 && !style.free_spacing) {
3203 // in freespacing mode, spaces are
3204 // non-breaking characters
3209 << "</term><listitem><para>";
3221 // Needed if there is an optional argument but no contents.
3222 if (main_body > 0 && main_body == size()) {
3227 os << "</emphasis>";
3230 ++current_cell_number;
3231 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
3232 // Resets description flag correctly.
3235 // <term> not closed...
3240 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3242 os << "</INFORMALTABLE>";
3244 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3251 void LyXParagraph::DocBookContTableRows(Buffer const * buffer,
3252 ostream & os, string & extra,
3254 LyXParagraph::size_type i,
3255 int current_cell_number, int &column)
3260 BufferParams const & bparams = buffer->params;
3262 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3267 //string emph = "emphasis";
3268 bool emph_flag = false;
3269 int char_line_count = 0;
3271 LyXLayout const & style =
3272 textclasslist.Style(bparams.textclass,
3275 size_type main_body;
3276 if (style.labeltype != LABEL_MANUAL)
3279 main_body = BeginningOfMainBody();
3281 // Gets paragraph main font.
3284 font1 = style.labelfont;
3288 size_type lastpos = i;
3289 int cell = table->CellHasContRow(current_cell_number);
3290 ++current_cell_number;
3292 // first find the right position
3294 for (; i < size() && current_cell_number < cell; ++i) {
3296 if (c == LyXParagraph::META_NEWLINE)
3297 ++current_cell_number;
3301 // I don't know how to handle this so I comment it
3302 // for the moment (Jug)
3303 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3304 // file += " \\\\\n";
3307 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3312 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3316 // Fully instantiated font
3317 font2 = getFont(bparams, i);
3319 // Handle <emphasis> tag.
3320 if (font1.emph() != font2.emph() && i) {
3321 if (font2.emph() == LyXFont::ON) {
3324 } else if (emph_flag) {
3325 os << "</emphasis>";
3329 if (c == LyXParagraph::META_INSET) {
3330 inset = GetInset(i);
3332 std::ostringstream ost;
3333 inset->DocBook(buffer, ost);
3334 string tmp_out = ost.str().c_str();
3337 inset->DocBook(buffer, ost);
3339 char * ctmp = ost.str();
3340 string tmp_out(ctmp);
3344 // This code needs some explanation:
3345 // Two insets are treated specially
3346 // label if it is the first element in a
3347 // command paragraph
3349 // graphics inside tables or figure floats
3350 // can't go on title (the equivalente in
3351 // latex for this case is caption and title
3352 // should come first
3355 if(desc_on != 3 || i != 0) {
3356 if(tmp_out[0] == '@') {
3358 extra += frontStrip(tmp_out, '@');
3360 os << frontStrip(tmp_out, '@');
3364 } else if (font2.latex() == LyXFont::ON) {
3365 // "TeX"-Mode on == > SGML-Mode on.
3371 if (linuxDocConvertChar(c, sgml_string)
3372 && !style.free_spacing) {
3373 // in freespacing mode, spaces are
3374 // non-breaking characters
3379 << "</term><listitem><para>";
3389 // we have only to control for emphasis open here!
3391 os << "</emphasis>";
3394 font1 = font2 = getFont(bparams, -1);
3395 cell = table->CellHasContRow(current_cell_number);
3397 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3402 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3403 LyXParagraph::size_type const i,
3404 int & column, LyXFont const & font,
3405 LyXLayout const & style)
3407 if (column > tex_code_break_column
3409 && GetChar(i - 1) != ' '
3411 // In LaTeX mode, we don't want to
3412 // break lines since some commands
3414 && ! (font.latex() == LyXFont::ON)
3415 // same in FreeSpacing mode
3416 && !style.free_spacing
3417 // In typewriter mode, we want to avoid
3418 // ! . ? : at the end of a line
3419 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3420 && (GetChar(i-1) == '.'
3421 || GetChar(i-1) == '?'
3422 || GetChar(i-1) == ':'
3423 || GetChar(i-1) == '!'))) {
3424 if (tex_code_break_column == 0) {
3425 // in batchmode we need LaTeX to still
3426 // see it as a space not as an extra '\n'
3432 texrow.start(this, i + 1);
3434 } else if (font.latex() == LyXFont::OFF) {
3435 if (style.free_spacing) {
3444 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
3445 BufferParams const & bparams,
3446 ostream & os, TexRow & texrow,
3449 LyXFont & running_font,
3452 LyXLayout const & style,
3453 LyXParagraph::size_type & i,
3455 LyXParagraph::value_type const c)
3457 // Two major modes: LaTeX or plain
3458 // Handle here those cases common to both modes
3459 // and then split to handle the two modes separately.
3461 case LyXParagraph::META_INSET: {
3462 Inset * inset = GetInset(i);
3465 int len = os.tellp();
3466 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3467 || inset->LyxCode() == Inset::MATH_CODE
3468 || inset->LyxCode() == Inset::URL_CODE)
3469 && running_font.isRightToLeft()) {
3474 int tmp = inset->Latex(buf, os, moving_arg,
3475 style.free_spacing);
3483 column += os.tellp() - len;
3492 case LyXParagraph::META_NEWLINE:
3494 column += running_font.latexWriteEndChanges(os,
3499 basefont = getFont(bparams, -1);
3500 running_font = basefont;
3503 case LyXParagraph::META_HFILL:
3509 // And now for the special cases within each mode
3510 // Are we in LaTeX mode?
3511 if (font.latex() == LyXFont::ON) {
3512 // at present we only have one option
3513 // but I'll leave it as a switch statement
3514 // so its simpler to extend. (ARRae)
3517 // make sure that we will not print
3518 // error generating chars to the tex
3519 // file. This test would not be needed
3520 // if it were done in the buffer
3528 // Plain mode (i.e. not LaTeX)
3531 os << "\\textbackslash{}";
3535 case '°': case '±': case '²': case '³':
3536 case '×': case '÷': case '¹': case 'ª':
3537 case 'º': case '¬': case 'µ':
3538 if (bparams.inputenc == "latin1" ||
3539 (bparams.inputenc == "auto" &&
3540 font.language()->encoding()->LatexName()
3542 os << "\\ensuremath{"
3551 case '|': case '<': case '>':
3552 // In T1 encoding, these characters exist
3553 if (lyxrc.fontenc == "T1") {
3555 //... but we should avoid ligatures
3556 if ((c == '>' || c == '<')
3558 && GetChar(i + 1) == c) {
3559 //os << "\\textcompwordmark{}";
3560 // Jean-Marc, have a look at
3561 // this. IÂ think this works
3569 // Typewriter font also has them
3570 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3574 // Otherwise, we use what LaTeX
3578 os << "\\textless{}";
3582 os << "\\textgreater{}";
3586 os << "\\textbar{}";
3592 case '-': // "--" in Typewriter mode -> "-{}-"
3594 && GetChar(i + 1) == '-'
3595 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3604 os << "\\char`\\\"{}";
3609 if (bparams.inputenc == "default") {
3618 case '%': case '#': case '{':
3625 os << "\\textasciitilde{}";
3630 os << "\\textasciicircum{}";
3634 case '*': case '[': case ']':
3635 // avoid being mistaken for optional arguments
3636 os << '{' << c << '}';
3641 // Blanks are printed before font switching.
3642 // Sure? I am not! (try nice-latex)
3643 // I am sure it's correct. LyX might be smarter
3644 // in the future, but for now, nothing wrong is
3649 /* idea for labels --- begin*/
3653 && font.family() != LyXFont::TYPEWRITER_FAMILY
3654 && GetChar(i + 1) == 'y'
3655 && GetChar(i + 2) == 'X') {
3663 && font.family() != LyXFont::TYPEWRITER_FAMILY
3664 && GetChar(i + 1) == 'e'
3665 && GetChar(i + 2) == 'X') {
3670 // Check for "LaTeX2e"
3673 && font.family() != LyXFont::TYPEWRITER_FAMILY
3674 && GetChar(i + 1) == 'a'
3675 && GetChar(i + 2) == 'T'
3676 && GetChar(i + 3) == 'e'
3677 && GetChar(i + 4) == 'X'
3678 && GetChar(i + 5) == '2'
3679 && GetChar(i + 6) == 'e') {
3684 // Check for "LaTeX"
3687 && font.family() != LyXFont::TYPEWRITER_FAMILY
3688 && GetChar(i + 1) == 'a'
3689 && GetChar(i + 2) == 'T'
3690 && GetChar(i + 3) == 'e'
3691 && GetChar(i + 4) == 'X') {
3695 /* idea for labels --- end*/
3696 } else if (c != '\0') {
3706 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3707 BufferParams const & bparams,
3708 ostream & os, TexRow & texrow,
3710 TexRow & foot_texrow,
3713 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3714 LyXParagraph * par = this;
3717 (par->depth == depth)
3719 && (par->footnoteflag == footnoteflag)
3724 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3726 if (textclasslist.Style(bparams.textclass,
3727 par->layout).isEnvironment()
3728 || par->pextra_type != PEXTRA_NONE) {
3729 par = par->TeXEnvironment(buf, bparams,
3734 par = par->TeXOnePar(buf, bparams,
3744 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3750 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3751 BufferParams const & bparams,
3752 ostream & os, TexRow & texrow,
3754 TexRow & foot_texrow,
3757 bool eindent_open = false;
3758 bool foot_this_level = false;
3759 // flags when footnotetext should be appended to file.
3760 static bool minipage_open = false;
3761 static int minipage_open_depth = 0;
3762 char par_sep = bparams.paragraph_separation;
3764 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3767 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3770 LyXLayout const & style =
3771 textclasslist.Style(bparams.textclass,
3774 if (pextra_type == PEXTRA_INDENT) {
3775 if (!pextra_width.empty()) {
3776 os << "\\begin{LyXParagraphIndent}{"
3777 << pextra_width << "}\n";
3779 //float ib = atof(pextra_widthp.c_str())/100;
3780 // string can't handle floats at present (971109)
3781 // so I'll do a conversion by hand knowing that
3782 // the limits are 0.0 to 1.0. ARRae.
3783 os << "\\begin{LyXParagraphIndent}{";
3784 switch (pextra_widthp.length()) {
3796 os << "\\columnwidth}\n";
3799 eindent_open = true;
3801 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3802 if (pextra_hfill && Previous() &&
3803 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3804 os << "\\hfill{}\n";
3807 if (par_sep == BufferParams::PARSEP_INDENT) {
3808 os << "{\\setlength\\parindent{0pt}\n";
3811 os << "\\begin{minipage}";
3812 switch(pextra_alignment) {
3813 case MINIPAGE_ALIGN_TOP:
3816 case MINIPAGE_ALIGN_MIDDLE:
3819 case MINIPAGE_ALIGN_BOTTOM:
3823 if (!pextra_width.empty()) {
3824 os << '{' << pextra_width << "}\n";
3826 //float ib = atof(par->pextra_width.c_str())/100;
3827 // string can't handle floats at present
3828 // so I'll do a conversion by hand knowing that
3829 // the limits are 0.0 to 1.0. ARRae.
3831 switch (pextra_widthp.length()) {
3843 os << "\\columnwidth}\n";
3846 if (par_sep == BufferParams::PARSEP_INDENT) {
3847 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3850 minipage_open = true;
3851 minipage_open_depth = depth;
3854 #ifdef WITH_WARNINGS
3855 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3856 //I disabled it because it breaks when lists span on several
3859 if (style.isEnvironment()){
3860 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3861 #ifdef FANCY_FOOTNOTE_CODE
3862 if (foot_count < 0) {
3863 // flag that footnote[mark][text] should be
3864 // used for any footnotes from now on
3866 foot_this_level = true;
3869 os << "\\begin{" << style.latexname() << "}{"
3870 << labelwidthstring << "}\n";
3871 } else if (style.labeltype == LABEL_BIBLIO) {
3873 os << "\\begin{" << style.latexname() << "}{"
3874 << bibitemWidest(current_view)
3876 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3877 #ifdef FANCY_FOOTNOTE_CODE
3878 if (foot_count < 0) {
3879 // flag that footnote[mark][text] should be
3880 // used for any footnotes from now on
3882 foot_this_level = true;
3885 os << "\\begin{" << style.latexname() << '}'
3886 << style.latexparam() << '\n';
3888 os << "\\begin{" << style.latexname() << '}'
3889 << style.latexparam() << '\n';
3892 LyXParagraph * par = this;
3894 par = par->TeXOnePar(buf, bparams,
3898 foot, foot_texrow, foot_count
3902 if (minipage_open && par && !style.isEnvironment() &&
3903 (par->pextra_type == PEXTRA_MINIPAGE) &&
3904 par->pextra_start_minipage) {
3905 os << "\\end{minipage}\n";
3907 if (par_sep == BufferParams::PARSEP_INDENT) {
3911 minipage_open = false;
3913 if (par && par->depth > depth) {
3914 if (textclasslist.Style(bparams.textclass,
3915 par->layout).isParagraph()
3920 // How to handle this? (Lgb)
3921 //&& !suffixIs(os, "\n\n")
3923 // There should be at least one '\n' already
3924 // but we need there to be two for Standard
3925 // paragraphs that are depth-increment'ed to be
3926 // output correctly. However, tables can
3927 // also be paragraphs so don't adjust them.
3930 // Will it ever harm to have one '\n' too
3931 // many? i.e. that we sometimes will have
3932 // three in a row. (Lgb)
3936 par = par->TeXDeeper(buf, bparams, os, texrow,
3937 foot, foot_texrow, foot_count);
3939 if (par && par->layout == layout && par->depth == depth &&
3940 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3941 if (par->pextra_hfill && par->Previous() &&
3942 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3943 os << "\\hfill{}\n";
3946 if (par_sep == BufferParams::PARSEP_INDENT) {
3947 os << "{\\setlength\\parindent{0pt}\n";
3950 os << "\\begin{minipage}";
3951 switch(par->pextra_alignment) {
3952 case MINIPAGE_ALIGN_TOP:
3955 case MINIPAGE_ALIGN_MIDDLE:
3958 case MINIPAGE_ALIGN_BOTTOM:
3962 if (!par->pextra_width.empty()) {
3963 os << '{' << par->pextra_width << "}\n";
3965 //float ib = atof(par->pextra_widthp.c_str())/100;
3966 // string can't handle floats at present
3967 // so I'll do a conversion by hand knowing that
3968 // the limits are 0.0 to 1.0. ARRae.
3970 switch (par->pextra_widthp.length()) {
3975 os << "0." << par->pextra_widthp;
3978 os << "0.0" << par->pextra_widthp;
3980 os << "\\columnwidth}\n";
3983 if (par_sep == BufferParams::PARSEP_INDENT) {
3984 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3987 minipage_open = true;
3988 minipage_open_depth = par->depth;
3991 && par->layout == layout
3992 && par->depth == depth
3993 && par->pextra_type == pextra_type
3995 && par->footnoteflag == footnoteflag
3999 if (style.isEnvironment()) {
4000 os << "\\end{" << style.latexname() << '}';
4001 // maybe this should go after the minipage closes?
4002 if (foot_this_level) {
4003 if (foot_count >= 1) {
4004 if (foot_count > 1) {
4005 os << "\\addtocounter{footnote}{-"
4010 texrow += foot_texrow;
4012 foot_texrow.reset();
4017 if (minipage_open && (minipage_open_depth == depth) &&
4018 (!par || par->pextra_start_minipage ||
4019 par->pextra_type != PEXTRA_MINIPAGE)) {
4020 os << "\\end{minipage}\n";
4022 if (par_sep == BufferParams::PARSEP_INDENT) {
4026 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
4027 os << "\\medskip\n\n";
4031 minipage_open = false;
4034 os << "\\end{LyXParagraphIndent}\n";
4037 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
4038 && par->pextra_hfill)) {
4042 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
4043 return par; // ale970302
4048 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
4049 BufferParams const & bparams,
4050 ostream & os, TexRow & texrow,
4051 ostream & foot, TexRow & foot_texrow,
4055 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
4056 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
4057 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4058 "No footnote!" << endl;
4060 LyXParagraph * par = this;
4061 LyXLayout const & style =
4062 textclasslist.Style(bparams.textclass,
4063 previous->GetLayout());
4065 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
4066 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4067 "Float other than footnote in command"
4068 " with moving argument is illegal" << endl;
4071 if (footnotekind != LyXParagraph::FOOTNOTE
4072 && footnotekind != LyXParagraph::MARGIN
4075 // How to solve this?
4076 //&& !suffixIs(file, '\n')
4078 // we need to ensure that real floats like tables and figures
4079 // have their \begin{} on a new line otherwise we can get
4080 // incorrect results when using the endfloat.sty package
4081 // especially if two floats follow one another. ARRae 981022
4082 // NOTE: if the file is length 0 it must have just been
4083 // written out so we assume it ended with a '\n'
4085 // As far as I can see there is never any harm in writing
4086 // a '\n' too much. Please tell me if I am wrong. (Lgb)
4091 bool moving_arg = false;
4092 bool need_closing = false;
4093 bool is_rtl = isRightToLeftPar(bparams);
4095 if (is_rtl != parent_is_rtl) {
4100 need_closing = true;
4103 //BufferParams * params = ¤t_view->buffer()->params;
4104 bool footer_in_body = true;
4105 switch (footnotekind) {
4106 case LyXParagraph::FOOTNOTE:
4107 if (style.intitle) {
4108 os << "\\thanks{\n";
4109 footer_in_body = false;
4112 if (foot_count == -1) {
4113 // we're at depth 0 so we can use:
4114 os << "\\footnote{%\n";
4115 footer_in_body = false;
4117 os << "\\footnotemark{}%\n";
4119 // we only need this when there are
4120 // multiple footnotes
4121 os << "\\stepcounter{footnote}";
4123 os << "\\footnotetext{%\n";
4124 foot_texrow.start(this, 0);
4125 foot_texrow.newline();
4130 case LyXParagraph::MARGIN:
4131 os << "\\marginpar{\n";
4133 case LyXParagraph::FIG:
4134 if (pextra_type == PEXTRA_FLOATFLT
4135 && (!pextra_width.empty()
4136 || !pextra_widthp.empty())) {
4137 if (!pextra_width.empty())
4138 os << "\\begin{floatingfigure}{"
4139 << pextra_width << "}\n";
4141 os << "\\begin{floatingfigure}{"
4142 << atoi(pextra_widthp.c_str())/100.0
4143 << "\\textwidth}\n";
4145 os << "\\begin{figure}";
4146 if (!bparams.float_placement.empty()) {
4147 os << '[' << bparams.float_placement << "]\n";
4153 case LyXParagraph::TAB:
4154 os << "\\begin{table}";
4155 if (!bparams.float_placement.empty()) {
4156 os << '[' << bparams.float_placement << "]\n";
4161 case LyXParagraph::WIDE_FIG:
4162 os << "\\begin{figure*}";
4163 if (!bparams.float_placement.empty()) {
4164 os << '[' << bparams.float_placement << "]\n";
4169 case LyXParagraph::WIDE_TAB:
4170 os << "\\begin{table*}";
4171 if (!bparams.float_placement.empty()) {
4172 os << '[' << bparams.float_placement << "]\n";
4177 case LyXParagraph::ALGORITHM:
4178 os << "\\begin{algorithm}\n";
4183 if (footnotekind != LyXParagraph::FOOTNOTE
4184 || !footer_in_body) {
4185 // Process text for all floats except footnotes in body
4187 LyXLayout const & style =
4189 .Style(bparams.textclass, par->layout);
4191 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4193 if (style.isEnvironment()
4194 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4195 // Allows the use of minipages within float
4196 // environments. Shouldn't be circular because
4197 // we don't support footnotes inside
4198 // floats (yet). ARRae
4199 par = par->TeXEnvironment(buf, bparams, os,
4204 par = par->TeXOnePar(buf, bparams,
4205 os, texrow, moving_arg,
4210 if (par && !par->IsDummy() && par->depth > depth) {
4211 par = par->TeXDeeper(buf, bparams, os, texrow,
4215 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4217 // process footnotes > depth 0 or in environments separately
4218 // NOTE: Currently don't support footnotes within footnotes
4219 // even though that is possible using the \footnotemark
4221 std::ostringstream dummy;
4225 TexRow dummy_texrow;
4226 int dummy_count = 0;
4228 LyXLayout const & style =
4230 .Style(bparams.textclass, par->layout);
4232 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4234 if (style.isEnvironment()
4235 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4236 // Allows the use of minipages within float
4237 // environments. Shouldn't be circular because
4238 // we don't support footnotes inside
4239 // floats (yet). ARRae
4240 par = par->TeXEnvironment(buf, bparams,
4242 dummy, dummy_texrow,
4245 par = par->TeXOnePar(buf, bparams,
4248 dummy, dummy_texrow,
4252 if (par && !par->IsDummy() && par->depth > depth) {
4253 par = par->TeXDeeper(buf, bparams,
4255 dummy, dummy_texrow,
4259 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4261 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4262 "Footnote in a Footnote -- not supported"
4265 #ifndef HAVE_OSTREAM
4266 delete [] dummy.str();
4270 switch (footnotekind) {
4271 case LyXParagraph::FOOTNOTE:
4272 if (footer_in_body) {
4273 // This helps tell which of the multiple
4274 // footnotetexts an error was in.
4276 foot_texrow.newline();
4281 case LyXParagraph::MARGIN:
4284 case LyXParagraph::FIG:
4285 if (pextra_type == PEXTRA_FLOATFLT
4286 && (!pextra_width.empty()
4287 || !pextra_widthp.empty()))
4288 os << "\\end{floatingfigure}";
4290 os << "\\end{figure}";
4292 case LyXParagraph::TAB:
4293 os << "\\end{table}";
4295 case LyXParagraph::WIDE_FIG:
4296 os << "\\end{figure*}";
4298 case LyXParagraph::WIDE_TAB:
4299 os << "\\end{table*}";
4301 case LyXParagraph::ALGORITHM:
4302 os << "\\end{algorithm}";
4309 if (footnotekind != LyXParagraph::FOOTNOTE
4310 && footnotekind != LyXParagraph::MARGIN) {
4311 // we need to ensure that real floats like tables and figures
4312 // have their \end{} on a line of their own otherwise we can
4313 // get incorrect results when using the endfloat.sty package.
4318 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4323 bool LyXParagraph::IsDummy() const
4325 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4326 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4330 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
4331 int type, char const * width,
4332 char const * widthp)
4335 pextra_width = width;
4336 pextra_widthp = widthp;
4338 if (textclasslist.Style(bparams.textclass,
4339 layout).isEnvironment()) {
4344 while (par && (par->layout == layout)
4345 && (par->depth == depth)) {
4347 par = par->Previous();
4350 par = par->FirstPhysicalPar();
4352 while (par && par->depth > depth) {
4353 par = par->Previous();
4356 par = par->FirstPhysicalPar();
4361 while (par && (par->layout == layout)
4362 && (par->depth == depth)) {
4363 par->pextra_type = type;
4364 par->pextra_width = width;
4365 par->pextra_widthp = widthp;
4367 par = par->NextAfterFootnote();
4371 if (par && (par->depth > depth))
4372 par->SetPExtraType(bparams,
4373 type, width, widthp);
4375 while (par && ((par->depth > depth) || par->IsDummy()))
4376 par = par->NextAfterFootnote();
4378 while (par && ((par->depth > depth)))
4386 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
4388 if (pextra_type == PEXTRA_NONE)
4391 pextra_type = PEXTRA_NONE;
4392 pextra_width.erase();
4393 pextra_widthp.erase();
4395 if (textclasslist.Style(bparams.textclass,
4396 layout).isEnvironment()) {
4401 while (par && (par->layout == layout)
4402 && (par->depth == depth)) {
4404 par = par->Previous();
4407 par = par->FirstPhysicalPar();
4409 while (par && par->depth > depth) {
4410 par = par->Previous();
4413 par = par->FirstPhysicalPar();
4418 while (par && (par->layout == layout)
4419 && (par->depth == depth)) {
4420 par->pextra_type = PEXTRA_NONE;
4421 par->pextra_width.erase();
4422 par->pextra_widthp.erase();
4424 par = par->NextAfterFootnote();
4428 if (par && (par->depth > depth))
4429 par->UnsetPExtraType(bparams);
4431 while (par && ((par->depth > depth) || par->IsDummy()))
4432 par = par->NextAfterFootnote();
4434 while (par && ((par->depth > depth)))
4442 bool LyXParagraph::IsHfill(size_type pos) const
4444 return IsHfillChar(GetChar(pos));
4448 bool LyXParagraph::IsInset(size_type pos) const
4450 return IsInsetChar(GetChar(pos));
4455 bool LyXParagraph::IsFloat(size_type pos) const
4457 return IsFloatChar(GetChar(pos));
4462 bool LyXParagraph::IsNewline(size_type pos) const
4464 return pos >= 0 && IsNewlineChar(GetChar(pos));
4468 bool LyXParagraph::IsSeparator(size_type pos) const
4470 return IsSeparatorChar(GetChar(pos));
4474 bool LyXParagraph::IsLineSeparator(size_type pos) const
4476 return IsLineSeparatorChar(GetChar(pos));
4480 bool LyXParagraph::IsKomma(size_type pos) const
4482 return IsKommaChar(GetChar(pos));
4486 /// Used by the spellchecker
4487 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4489 value_type c = GetChar(pos);
4490 if (IsLetterChar(c))
4492 // '\0' is not a letter, allthough every string contains "" (below)
4495 // We want to pass the ' and escape chars to ispell
4496 string extra = lyxrc.isp_esc_chars + '\'';
4500 return contains(extra, ch);
4504 bool LyXParagraph::IsWord(size_type pos ) const
4506 return IsWordChar(GetChar(pos)) ;
4511 LyXParagraph::getParLanguage(BufferParams const & bparams) const
4515 return FirstPhysicalPar()->getParLanguage(bparams);
4522 return GetFirstFontSettings().language();
4525 for (size_type pos = 0; pos < size(); ++pos)
4527 return GetFontSettings(bparams, pos).language();
4528 return GetFirstFontSettings().language();
4532 return previous->getParLanguage(bparams);
4534 return bparams.language_info;
4538 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
4540 return lyxrc.rtl_support
4544 && getParLanguage(bparams)->RightToLeft();
4548 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
4549 Language const * from, Language const * to)
4551 for(size_type i = 0; i < size(); ++i) {
4552 LyXFont font = GetFontSettings(bparams, i);
4553 if (font.language() == from) {
4554 font.setLanguage(to);
4561 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
4563 Language const * doc_language = bparams.language_info;
4564 for (FontList::const_iterator cit = fontlist.begin();
4565 cit != fontlist.end(); ++cit)
4566 if ((*cit).font.language() != doc_language)
4572 // Convert the paragraph to a string.
4573 // Used for building the table of contents
4574 string LyXParagraph::String(Buffer const * buffer, bool label)
4576 BufferParams const & bparams = buffer->params;
4579 if (label && !IsDummy() && !labelstring.empty())
4581 if (label && !labelstring.empty())
4583 s += labelstring + ' ';
4584 string::size_type len = s.size();
4586 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4587 value_type c = GetChar(i);
4590 else if (c == META_INSET &&
4591 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4593 std::ostringstream ost;
4594 GetInset(i)->Ascii(buffer, ost);
4597 GetInset(i)->Ascii(buffer, ost);
4600 s += subst(ost.str(),'\n',' ');
4605 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
4606 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
4607 s += NextAfterFootnote()->String(buffer, false);
4611 if (isRightToLeftPar(bparams))
4612 reverse(s.begin() + len,s.end());
4620 string LyXParagraph::String(Buffer const * buffer,
4621 LyXParagraph::size_type beg,
4622 LyXParagraph::size_type end)
4629 for (LyXParagraph::size_type i = 0; i < beg; ++i)
4631 if (cell >= table->NumberOfCellsInRow(actcell))
4640 if (beg == 0 && !IsDummy() && !labelstring.empty())
4642 if (beg == 0 && !labelstring.empty())
4644 s += labelstring + ' ';
4646 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4647 value_type c = GetChar(i);
4650 else if (c == META_INSET) {
4652 std::ostringstream ost;
4653 GetInset(i)->Ascii(buffer, ost);
4656 GetInset(i)->Ascii(buffer, ost);
4662 else if (table && IsNewlineChar(c)) {
4663 if (cell >= table->NumberOfCellsInRow(actcell)) {
4679 void LyXParagraph::SetInsetOwner(Inset *i)
4682 for (InsetList::const_iterator cit = insetlist.begin();
4683 cit != insetlist.end(); ++cit) {
4685 (*cit).inset->setOwner(i);
4690 void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
4693 for (InsetList::const_iterator cit = insetlist.begin();
4694 cit != insetlist.end(); ++cit) {
4696 if ((*cit).inset->IsTextInset()) {
4697 static_cast<UpdatableInset *>
4698 ((*cit).inset)->deleteLyXText(bv);
4705 void LyXParagraph::resizeInsetsLyXText(BufferView * bv)
4708 for (InsetList::const_iterator cit = insetlist.begin();
4709 cit != insetlist.end(); ++cit) {
4711 if ((*cit).inset->IsTextInset()) {
4712 static_cast<UpdatableInset *>
4713 ((*cit).inset)->resizeLyXText(bv);