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 "support/filetools.h"
33 #include "lyx_gui_misc.h"
37 extern void addNewlineAndDepth(string & file, int const depth); // Jug 990923
38 int tex_code_break_column = 72; // needs non-zero initialization. set later.
39 // this is a bad idea, but how can LyXParagraph find its buffer to get
40 // parameters? (JMarc)
41 extern BufferView * current_view;
47 extern string bibitemWidthest(Painter &);
49 extern string bibitemWidthest();
52 // this is a minibuffer
53 static char minibuffer_char;
54 static LyXFont minibuffer_font;
55 static Inset * minibuffer_inset;
58 // Initialization of the counter for the paragraph id's,
59 // declared in lyxparagraph.h
60 unsigned int LyXParagraph::paragraph_id = 0;
63 LyXParagraph::LyXParagraph()
65 text.reserve(500); // is this number too big?
67 for (int i = 0; i < 10; ++i) setCounter(i , 0);
73 footnoteflag = LyXParagraph::NO_FOOTNOTE;
74 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
76 align = LYX_ALIGN_BLOCK;
78 /* table stuff -- begin*/
80 /* table stuff -- end*/
82 bibkey = 0; // ale970302
87 // This konstruktor inserts the new paragraph in a list.
88 LyXParagraph::LyXParagraph(LyXParagraph * par)
91 par->text.resize(par->text.size());
93 for (int i = 0; i < 10; ++i) setCounter(i, 0);
97 // double linked list begin
100 next->previous = this;
102 previous->next = this;
104 footnoteflag = LyXParagraph::NO_FOOTNOTE;
105 footnotekind = LyXParagraph::FOOTNOTE;
107 /* table stuff -- begin*/
109 /* table stuff -- end*/
110 id_ = paragraph_id++;
112 bibkey = 0; // ale970302
118 void LyXParagraph::writeFile(ostream & os, BufferParams & params,
119 char footflag, char dth)
121 LyXFont font1, font2;
127 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
129 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
131 // The beginning or the end of a footnote environment?
132 if (footflag != footnoteflag) {
133 footflag = footnoteflag;
135 os << "\n\\begin_float "
136 << string_footnotekinds[footnotekind]
139 os << "\n\\end_float ";
143 // The beginning or end of a deeper (i.e. nested) area?
146 while (depth > dth) {
147 os << "\n\\begin_deeper ";
151 while (depth < dth) {
152 os << "\n\\end_deeper ";
158 // First write the layout
160 << textclasslist.NameOfLayout(params.textclass, layout)
163 // Maybe some vertical spaces.
164 if (added_space_top.kind() != VSpace::NONE)
165 os << "\\added_space_top "
166 << added_space_top.asLyXCommand() << " ";
167 if (added_space_bottom.kind() != VSpace::NONE)
168 os << "\\added_space_bottom "
169 << added_space_bottom.asLyXCommand() << " ";
171 // The labelwidth string used in lists.
172 if (!labelwidthstring.empty())
173 os << "\\labelwidthstring "
174 << labelwidthstring << '\n';
176 // Lines above or below?
180 os << "\\line_bottom ";
182 // Pagebreaks above or below?
184 os << "\\pagebreak_top ";
185 if (pagebreak_bottom)
186 os << "\\pagebreak_bottom ";
188 // Start of appendix?
189 if (start_of_appendix)
190 os << "\\start_of_appendix ";
197 if (align != LYX_ALIGN_LAYOUT) {
199 case LYX_ALIGN_LEFT: h = 1; break;
200 case LYX_ALIGN_RIGHT: h = 2; break;
201 case LYX_ALIGN_CENTER: h = 3; break;
202 default: h = 0; break;
204 os << "\\align " << string_align[h] << " ";
206 if (pextra_type != PEXTRA_NONE) {
207 os << "\\pextra_type " << pextra_type;
208 if (pextra_type == PEXTRA_MINIPAGE) {
209 os << " \\pextra_alignment "
212 os << " \\pextra_hfill "
214 if (pextra_start_minipage)
215 os << " \\pextra_start_minipage "
216 << pextra_start_minipage;
218 if (!pextra_width.empty()) {
219 os << " \\pextra_width "
220 << VSpace(pextra_width).asLyXCommand();
221 } else if (!pextra_widthp.empty()) {
222 os << " \\pextra_widthp "
228 // Dummy layout. This means that a footnote ended.
229 os << "\n\\end_float ";
230 footflag = LyXParagraph::NO_FOOTNOTE;
233 // It might be a table.
235 os << "\\LyXTable\n";
243 font1 = LyXFont(LyXFont::ALL_INHERIT);
246 for (size_type i = 0; i < size(); ++i) {
252 // Write font changes
253 font2 = GetFontSettings(i);
254 if (font2 != font1) {
255 font2.lyxWriteChanges(font1, os);
265 if (inset->DirectWrite()) {
266 // international char, let it write
267 // code directly so it's shorter in
271 os << "\n\\begin_inset ";
273 os << "\n\\end_inset \n\n";
278 os << "\n\\newline \n";
282 os << "\n\\hfill \n";
285 case META_PROTECTED_SEPARATOR:
286 os << "\n\\protected_separator \n";
290 os << "\n\\backslash \n";
294 if (i + 1 < size() && GetChar(i + 1) == ' ') {
301 if ((column > 70 && c == ' ')
306 // this check is to amend a bug. LyX sometimes
307 // inserts '\0' this could cause problems.
311 lyxerr << "ERROR (LyXParagraph::writeFile):"
312 " NULL char in structure." << endl;
318 // now write the next paragraph
320 next->writeFile(os, params, footflag, dth);
324 void LyXParagraph::validate(LaTeXFeatures & features) const
326 // this will be useful later
327 LyXLayout const & layout =
328 textclasslist.Style(current_view->buffer()->params.textclass,
332 if (line_top || line_bottom)
333 features.lyxline = true;
336 features.layout[GetLayout()] = true;
339 for (FontList::const_iterator cit = fontlist.begin();
340 cit != fontlist.end(); ++cit) {
341 if ((*cit).font.noun() == LyXFont::ON) {
342 lyxerr[Debug::LATEX] << "font.noun: "
343 << (*cit).font.noun()
345 features.noun = true;
346 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
347 << (*cit).font.stateText()
350 switch ((*cit).font.color()) {
353 case LColor::inherit:
358 case LyXFont::INHERIT_COLOR:
359 case LyXFont::IGNORE_COLOR:
363 features.color = true;
364 lyxerr[Debug::LATEX] << "Color enabled. Font: "
365 << (*cit).font.stateText()
371 for (InsetList::const_iterator cit = insetlist.begin();
372 cit != insetlist.end(); ++cit) {
374 (*cit).inset->Validate(features);
377 if (table && table->IsLongTable())
378 features.longtable = true;
379 if (pextra_type == PEXTRA_INDENT)
380 features.LyXParagraphIndent = true;
381 if (pextra_type == PEXTRA_FLOATFLT)
382 features.floatflt = true;
383 if (layout.needprotect
384 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
385 features.NeedLyXFootnoteCode = true;
386 if ((current_view->buffer()->params.paragraph_separation == BufferParams::PARSEP_INDENT) &&
387 (pextra_type == LyXParagraph::PEXTRA_MINIPAGE))
388 features.NeedLyXMinipageIndent = true;
389 if (table && table->NeedRotating())
390 features.rotating = true;
391 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
392 features.algorithm = true;
396 // First few functions needed for cut and paste and paragraph breaking.
397 void LyXParagraph::CopyIntoMinibuffer(LyXParagraph::size_type pos) const
399 minibuffer_char = GetChar(pos);
400 minibuffer_font = GetFontSettings(pos);
401 minibuffer_inset = 0;
402 if (minibuffer_char == LyXParagraph::META_INSET) {
404 minibuffer_inset = GetInset(pos)->Clone();
406 minibuffer_inset = 0;
407 minibuffer_char = ' ';
408 // This reflects what GetInset() does (ARRae)
414 void LyXParagraph::CutIntoMinibuffer(LyXParagraph::size_type pos)
416 minibuffer_char = GetChar(pos);
417 minibuffer_font = GetFontSettings(pos);
418 minibuffer_inset = 0;
419 if (minibuffer_char == LyXParagraph::META_INSET) {
421 minibuffer_inset = GetInset(pos);
422 // This is a little hack since I want exactly
423 // the inset, not just a clone. Otherwise
424 // the inset would be deleted when calling Erase(pos)
426 for (InsetList::iterator it = insetlist.begin();
427 it != insetlist.end(); ++it) {
428 if ((*it).pos == pos) {
435 minibuffer_inset = 0;
436 minibuffer_char = ' ';
437 // This reflects what GetInset() does (ARRae)
442 // Erase(pos); now the caller is responsible for that.
446 void LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
448 InsertChar(pos, minibuffer_char);
449 SetFont(pos, minibuffer_font);
450 if (minibuffer_char == LyXParagraph::META_INSET)
451 InsertInset(pos, minibuffer_inset);
458 void LyXParagraph::Clear()
463 pagebreak_top = false;
464 pagebreak_bottom = false;
466 added_space_top = VSpace(VSpace::NONE);
467 added_space_bottom = VSpace(VSpace::NONE);
469 align = LYX_ALIGN_LAYOUT;
473 pextra_type = PEXTRA_NONE;
474 pextra_width.clear();
475 pextra_widthp.clear();
476 pextra_alignment = MINIPAGE_ALIGN_TOP;
477 pextra_hfill = false;
478 pextra_start_minipage = false;
481 labelwidthstring.clear();
485 start_of_appendix = false;
489 // the destructor removes the new paragraph from the list
490 LyXParagraph::~LyXParagraph()
493 previous->next = next;
495 next->previous = previous;
497 for (InsetList::iterator it = insetlist.begin();
498 it != insetlist.end(); ++it) {
502 /* table stuff -- begin*/
504 /* table stuff -- end*/
511 void LyXParagraph::Erase(LyXParagraph::size_type pos)
513 // > because last is the next unused position, and you can
514 // use it if you want
516 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
517 NextAfterFootnote()->Erase(pos - text.size() - 1);
519 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
520 "position does not exist." << endl;
523 if (pos < size()) { // last is free for insertation, but should be empty
524 // if it is an inset, delete the inset entry
525 if (text[pos] == LyXParagraph::META_INSET) {
527 for (InsetList::iterator it = insetlist.begin();
528 it != insetlist.end(); ++it) {
529 if ((*it).pos == pos) {
536 text.erase(text.begin() + pos);
537 // Erase entries in the tables.
538 for (FontList::iterator it = fontlist.begin();
539 it != fontlist.end(); ++it) {
540 if (pos >= (*it).pos && pos <= (*it).pos_end) {
541 if ((*it).pos == (*it).pos_end) {
542 // If it is a multi-character font
543 // entry, we just make it smaller
544 // (see update below), otherwise we
551 // Update all other entries.
552 for (FontList::iterator it = fontlist.begin();
553 it != fontlist.end(); ++it) {
556 if ((*it).pos_end >= pos)
560 // Update the inset table.
561 for (InsetList::iterator it = insetlist.begin();
562 it != insetlist.end(); ++it) {
567 lyxerr << "ERROR (LyXParagraph::Erase): "
568 "can't erase non-existant char." << endl;
573 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
575 // > because last is the next unused position, and you can
576 // use it if you want
579 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
580 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
583 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
584 "position does not exist." << endl;
587 text.insert(text.begin() + pos, c);
588 // Update the font table.
589 for (FontList::iterator it = fontlist.begin();
590 it != fontlist.end(); ++it) {
591 if ((*it).pos >= pos)
593 if ((*it).pos_end >= pos)
597 // Update the inset table.
598 for (InsetList::iterator it = insetlist.begin();
599 it != insetlist.end(); ++it) {
600 if ((*it).pos >= pos)
606 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
609 // > because last is the next unused position, and you can
610 // use it if you want
613 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
615 ->InsertInset(pos - text.size() - 1, inset);
617 lyxerr << "ERROR (LyXParagraph::InsertInset): "
618 "position does not exist: " << pos << endl;
621 if (text[pos] != LyXParagraph::META_INSET) {
622 lyxerr << "ERROR (LyXParagraph::InsertInset): "
623 "there is no LyXParagraph::META_INSET" << endl;
628 // Add a new entry in the inset table.
629 InsetList::iterator it =
630 insetlist.insert(insetlist.begin(), InsetTable());
637 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
641 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
642 return NextAfterFootnote()
643 ->GetInset(pos - text.size() - 1);
645 lyxerr << "ERROR (LyXParagraph::GetInset): "
646 "position does not exist: "
652 for (InsetList::iterator it = insetlist.begin();
653 it != insetlist.end(); ++it) {
654 if ((*it).pos == pos) {
658 lyxerr << "ERROR (LyXParagraph::GetInset): "
659 "Inset does not exist: " << pos << endl;
660 text[pos] = ' '; // WHY!!! does this set the pos to ' '????
661 // Did this commenting out introduce a bug? So far I have not
662 // see any, please enlighten me. (Lgb)
663 // My guess is that since the inset does not exist, we might
664 // as well replace it with a space to prevent craches. (Asger)
669 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
673 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
674 return NextAfterFootnote()
675 ->GetInset(pos - text.size() - 1);
677 lyxerr << "ERROR (LyXParagraph::GetInset): "
678 "position does not exist: "
684 for (InsetList::const_iterator cit = insetlist.begin();
685 cit != insetlist.end(); ++cit) {
686 if ((*cit).pos == pos) {
690 lyxerr << "ERROR (LyXParagraph::GetInset): "
691 "Inset does not exist: " << pos << endl;
692 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
693 // Did this commenting out introduce a bug? So far I have not
694 // see any, please enlighten me. (Lgb)
695 // My guess is that since the inset does not exist, we might
696 // as well replace it with a space to prevent craches. (Asger)
701 // Gets uninstantiated font setting at position.
702 // Optimized after profiling. (Asger)
703 LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const
706 for (FontList::const_iterator cit = fontlist.begin();
707 cit != fontlist.end(); ++cit) {
708 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
712 // > because last is the next unused position, and you can
713 // use it if you want
714 else if (pos > size()) {
716 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
717 return NextAfterFootnote()
718 ->GetFontSettings(pos - text.size() - 1);
720 // Why is it an error to ask for the font of a
721 // position that does not exist? Would it be
722 // enough for this to be enabled on debug?
723 // We want strict error checking, but it's ok to only
724 // have it when debugging. (Asger)
725 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
726 "position does not exist. "
727 << pos << " (" << static_cast<int>(pos)
731 return GetFontSettings(pos - 1);
733 return LyXFont(LyXFont::ALL_INHERIT);
737 // Gets the fully instantiated font at a given position in a paragraph
738 // This is basically the same function as LyXText::GetFont() in text2.C.
739 // The difference is that this one is used for generating the LaTeX file,
740 // and thus cosmetic "improvements" are disallowed: This has to deliver
741 // the true picture of the buffer. (Asger)
742 // If position is -1, we get the layout font of the paragraph.
743 // If position is -2, we get the font of the manual label of the paragraph.
744 LyXFont LyXParagraph::getFont(LyXParagraph::size_type pos) const
747 LyXLayout const & layout =
748 textclasslist.Style(current_view->buffer()->params.textclass,
750 LyXParagraph::size_type main_body = 0;
751 if (layout.labeltype == LABEL_MANUAL)
752 main_body = BeginningOfMainBody();
757 layoutfont = layout.labelfont;
759 layoutfont = layout.font;
760 tmpfont = GetFontSettings(pos);
761 tmpfont.realize(layoutfont);
763 // process layoutfont for pos == -1 and labelfont for pos < -1
765 tmpfont = layout.font;
767 tmpfont = layout.labelfont;
768 if (getParDirection() == LYX_DIR_RIGHT_TO_LEFT)
769 tmpfont.setDirection(LyXFont::RTL_DIR);
772 // check for environment font information
773 char par_depth = GetDepth();
774 LyXParagraph const * par = this;
775 while (par && par_depth && !tmpfont.resolved()) {
776 par = par->DepthHook(par_depth - 1);
778 tmpfont.realize(textclasslist.
779 Style(current_view->buffer()->params.textclass,
780 par->GetLayout()).font);
781 par_depth = par->GetDepth();
785 tmpfont.realize(textclasslist
786 .TextClass(current_view->buffer()->params.textclass)
792 /// Returns the height of the highest font in range
794 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
795 LyXParagraph::size_type endpos) const
797 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
798 for (FontList::const_iterator cit = fontlist.begin();
799 cit != fontlist.end(); ++cit) {
800 if (startpos <= (*cit).pos_end && endpos >= (*cit).pos) {
801 LyXFont::FONT_SIZE size = (*cit).font.size();
802 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
810 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
817 // > because last is the next unused position, and you can
818 // use it if you want
819 else if (pos > size()) {
820 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
821 return NextAfterFootnote()
822 ->GetChar(pos - text.size() - 1);
824 lyxerr << "ERROR (LyXParagraph::GetChar): "
825 "position does not exist."
826 << pos << " (" << static_cast<int>(pos)
828 // Assert(false); // This triggers sometimes...
833 // We should have a footnote environment.
834 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
835 // Notice that LyX does request the
836 // last char from time to time. (Asger)
837 //lyxerr << "ERROR (LyXParagraph::GetChar): "
838 // "expected footnote." << endl;
841 switch (next->footnotekind) {
842 case LyXParagraph::FOOTNOTE:
843 return LyXParagraph::META_FOOTNOTE;
844 case LyXParagraph::MARGIN:
845 return LyXParagraph::META_MARGIN;
846 case LyXParagraph::FIG:
847 case LyXParagraph::WIDE_FIG:
848 return LyXParagraph::META_FIG;
849 case LyXParagraph::TAB:
850 case LyXParagraph::WIDE_TAB:
851 return LyXParagraph::META_TAB;
852 case LyXParagraph::ALGORITHM:
853 return LyXParagraph::META_ALGORITHM;
855 return '\0'; // to shut up gcc
860 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
867 // > because last is the next unused position, and you can
868 // use it if you want
869 else if (pos > size()) {
870 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
871 return NextAfterFootnote()
872 ->GetChar(pos - text.size() - 1);
874 lyxerr << "ERROR (LyXParagraph::GetChar const): "
875 "position does not exist."
876 << pos << " (" << static_cast<int>(pos)
882 // We should have a footnote environment.
883 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
884 // Notice that LyX does request the
885 // last char from time to time. (Asger)
886 //lyxerr << "ERROR (LyXParagraph::GetChar): "
887 // "expected footnote." << endl;
890 switch (next->footnotekind) {
891 case LyXParagraph::FOOTNOTE:
892 return LyXParagraph::META_FOOTNOTE;
893 case LyXParagraph::MARGIN:
894 return LyXParagraph::META_MARGIN;
895 case LyXParagraph::FIG:
896 case LyXParagraph::WIDE_FIG:
897 return LyXParagraph::META_FIG;
898 case LyXParagraph::TAB:
899 case LyXParagraph::WIDE_TAB:
900 return LyXParagraph::META_TAB;
901 case LyXParagraph::ALGORITHM:
902 return LyXParagraph::META_ALGORITHM;
904 return '\0'; // to shut up gcc
909 // return an string of the current word, and the end of the word in lastpos.
910 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
914 // the current word is defined as starting at the first character
915 // from the immediate left of lastpospos which meets the definition
916 // of IsLetter(), continuing to the last character to the right
917 // of this meeting IsLetter.
923 // move back until we have a letter
925 //there's no real reason to have firstpos & lastpos as
926 //separate variables as this is written, but maybe someon
927 // will want to return firstpos in the future.
929 //since someone might have typed a punctuation first
930 int firstpos = lastpos;
932 while ((firstpos >= 0) && !IsLetter(firstpos))
935 // now find the beginning by looking for a nonletter
937 while ((firstpos>= 0) && IsLetter(firstpos))
940 // the above is now pointing to the preceeding non-letter
944 // so copy characters into theword until we get a nonletter
945 // note that this can easily exceed lastpos, wich means
946 // that if used in the middle of a word, the whole word
949 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
956 LyXParagraph::size_type LyXParagraph::Last() const
958 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
959 return text.size() + NextAfterFootnote()->Last() + 1;
960 // the 1 is the symbol
967 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
969 // > because last is the next unused position, and you can
970 // use it if you want
973 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
974 return NextAfterFootnote()
975 ->ParFromPos(pos - text.size() - 1);
977 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
978 "position does not exist." << endl;
985 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
987 // > because last is the next unused position, and you can
988 // use it if you want
991 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
992 return NextAfterFootnote()
993 ->PositionInParFromPos(pos - text.size() - 1);
996 "ERROR (LyXParagraph::PositionInParFromPos): "
997 "position does not exist." << endl;
1005 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1006 LyXFont const & font)
1008 // > because last is the next unused position, and you can
1009 // use it if you want
1012 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1013 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1016 lyxerr << "ERROR (LyXParagraph::SetFont): "
1017 "position does not exist." << endl;
1021 LyXFont patternfont(LyXFont::ALL_INHERIT);
1023 // First, reduce font against layout/label font
1024 // Update: The SetCharFont() routine in text2.C already
1025 // reduces font, so we don't need to do that here. (Asger)
1026 // No need to simplify this because it will disappear
1027 // in a new kernel. (Asger)
1028 // Next search font table
1029 FontList::iterator tmp = fontlist.begin();
1030 for (; tmp != fontlist.end(); ++tmp) {
1031 if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
1035 if (tmp == fontlist.end()) { // !found
1036 // if we did not find a font entry, but if the font at hand
1037 // is the same as default, we just forget it
1038 if (font == patternfont) return;
1040 // ok, we did not find a font entry. But maybe there is exactly
1041 // the needed font ientry one position left
1042 FontList::iterator tmp2 = fontlist.begin();
1043 for (; tmp2 != fontlist.end(); ++tmp2) {
1044 if (pos - 1 >= (*tmp2).pos
1045 && pos - 1 <= (*tmp2).pos_end)
1048 if (tmp2 != fontlist.end()) {
1049 // ok there is one, maybe it is exactly
1051 if ((*tmp2).font == font) {
1052 // put the position under the font
1057 // Add a new entry in the
1058 // fontlist for the position
1062 ft.font = font; // or patternfont
1063 // It seems that using font instead of patternfont here
1064 // fixes all the problems. This also surfaces a "bug" in
1066 fontlist.insert(fontlist.begin(), ft);
1067 } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
1069 // more than one character
1070 if (pos == (*tmp).pos) {
1071 // maybe we should enlarge the left fonttable
1072 FontList::iterator tmp2 = fontlist.begin();
1073 for (; tmp2 != fontlist.end(); ++tmp2) {
1074 if (pos - 1 >= (*tmp2).pos
1075 && pos - 1 <= (*tmp2).pos_end)
1078 // Is there is one, and is it exactly
1080 if (tmp2 != fontlist.end() &&
1081 (*tmp2).font == font) {
1082 // Put the position under the font
1088 // Add a new entry in the
1089 // fontlist for the position
1092 ft.pos_end = (*tmp).pos_end;
1093 ft.font = (*tmp).font;
1094 (*tmp).pos_end = pos;
1096 fontlist.insert(fontlist.begin(), ft);
1097 } else if (pos == (*tmp).pos_end) {
1098 // Add a new entry in the
1099 // fontlist for the position
1101 ft.pos = (*tmp).pos;
1102 ft.pos_end = (*tmp).pos_end - 1;
1103 ft.font = (*tmp).font;
1104 (*tmp).pos = (*tmp).pos_end;
1106 fontlist.insert(fontlist.begin(), ft);
1108 // Add a new entry in the
1109 // fontlist for the position
1111 ft.pos = (*tmp).pos;
1112 ft.pos_end = pos - 1;
1113 ft.font = (*tmp).font;
1117 ft2.pos_end = (*tmp).pos_end;
1118 ft2.font = (*tmp).font;
1121 (*tmp).pos_end = pos;
1124 fontlist.insert(fontlist.begin(), ft);
1125 fontlist.insert(fontlist.begin(), ft2);
1133 // This function is able to hide closed footnotes.
1134 LyXParagraph * LyXParagraph::Next()
1136 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1137 LyXParagraph * tmp = next;
1139 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1141 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1142 return tmp->Next(); /* there can be more than one
1143 footnote in a logical
1146 return next; // This should never happen!
1152 LyXParagraph * LyXParagraph::NextAfterFootnote()
1154 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1155 LyXParagraph * tmp = next;
1156 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1158 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1159 return tmp; /* there can be more than one footnote
1160 in a logical paragraph */
1162 return next; // This should never happen!
1168 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1170 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1171 LyXParagraph * tmp = next;
1172 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1174 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1175 return tmp; /* there can be more than one footnote
1176 in a logical paragraph */
1178 return next; // This should never happen!
1184 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1187 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1189 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1190 tmp = tmp->previous;
1191 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1192 return tmp; /* there can be more than one footnote
1193 in a logical paragraph */
1195 return previous; // This should never happen!
1201 LyXParagraph * LyXParagraph::LastPhysicalPar()
1203 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1206 LyXParagraph * tmp = this;
1208 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1209 tmp = tmp->NextAfterFootnote();
1216 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1220 LyXParagraph * tmppar = this;
1224 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1225 tmppar = tmppar->previous;
1234 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1238 LyXParagraph const * tmppar = this;
1242 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1243 tmppar = tmppar->previous;
1252 // This function is able to hide closed footnotes.
1253 LyXParagraph * LyXParagraph::Previous()
1255 LyXParagraph * tmp = previous;
1260 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1261 tmp = tmp->previous;
1263 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1264 tmp = tmp->previous;
1265 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1266 return tmp->next->Previous();
1275 // This function is able to hide closed footnotes.
1276 LyXParagraph const * LyXParagraph::Previous() const
1278 LyXParagraph * tmp = previous;
1283 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1284 tmp = tmp->previous;
1286 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1287 tmp = tmp->previous;
1288 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1289 return tmp->next->Previous();
1298 void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos,
1301 size_type i, pos_end, pos_first;
1302 // create a new paragraph
1303 LyXParagraph * par = ParFromPos(pos);
1304 LyXParagraph * firstpar = FirstPhysicalPar();
1306 LyXParagraph * tmp = new LyXParagraph(par);
1308 tmp->footnoteflag = footnoteflag;
1309 tmp->footnotekind = footnotekind;
1311 // this is an idea for a more userfriendly layout handling, I will
1312 // see what the users say
1314 // layout stays the same with latex-environments
1316 tmp->SetOnlyLayout(firstpar->layout);
1317 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1320 if (Last() > pos || !Last() || flag == 2) {
1321 tmp->SetOnlyLayout(firstpar->layout);
1322 tmp->align = firstpar->align;
1323 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1325 tmp->line_bottom = firstpar->line_bottom;
1326 firstpar->line_bottom = false;
1327 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1328 firstpar->pagebreak_bottom = false;
1329 tmp->added_space_bottom = firstpar->added_space_bottom;
1330 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1332 tmp->depth = firstpar->depth;
1333 tmp->noindent = firstpar->noindent;
1335 // copy everything behind the break-position
1336 // to the new paragraph
1338 while (ParFromPos(pos_first) != par)
1341 pos_end = pos_first + par->text.size() - 1;
1342 // The constructor has already reserved 500 elements
1343 //if (pos_end > pos)
1344 // tmp->text.reserve(pos_end - pos);
1346 for (i = pos; i <= pos_end; ++i) {
1347 par->CutIntoMinibuffer(i - pos_first);
1348 tmp->InsertFromMinibuffer(i - pos);
1350 tmp->text.resize(tmp->text.size());
1351 for (i = pos_end; i >= pos; --i)
1352 par->Erase(i - pos_first);
1354 par->text.resize(par->text.size());
1357 // just an idea of me
1359 tmp->line_top = firstpar->line_top;
1360 tmp->pagebreak_top = firstpar->pagebreak_top;
1361 tmp->added_space_top = firstpar->added_space_top;
1362 tmp->bibkey = firstpar->bibkey;
1364 // layout stays the same with latex-environments
1366 firstpar->SetOnlyLayout(tmp->layout);
1367 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1368 firstpar->depth = tmp->depth;
1374 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1376 par = par->FirstPhysicalPar();
1377 footnoteflag = par->footnoteflag;
1378 footnotekind = par->footnotekind;
1380 layout = par->layout;
1381 align = par-> align;
1382 SetLabelWidthString(par->labelwidthstring);
1384 line_bottom = par->line_bottom;
1385 pagebreak_bottom = par->pagebreak_bottom;
1386 added_space_bottom = par->added_space_bottom;
1388 line_top = par->line_top;
1389 pagebreak_top = par->pagebreak_top;
1390 added_space_top = par->added_space_top;
1392 pextra_type = par->pextra_type;
1393 pextra_width = par->pextra_width;
1394 pextra_widthp = par->pextra_widthp;
1395 pextra_alignment = par->pextra_alignment;
1396 pextra_hfill = par->pextra_hfill;
1397 pextra_start_minipage = par->pextra_start_minipage;
1399 noindent = par->noindent;
1404 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1406 LyXParagraph * tmppar = this;
1409 && tmppar->previous->footnoteflag ==
1410 LyXParagraph::CLOSED_FOOTNOTE)
1411 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1412 tmppar = tmppar->previous;
1415 return this; // This should never happen!
1421 LyXParagraph * LyXParagraph::Clone() const
1423 // create a new paragraph
1424 LyXParagraph * result = new LyXParagraph;
1426 result->MakeSameLayout(this);
1428 // this is because of the dummy layout of the paragraphs that
1430 result->layout = layout;
1432 /* table stuff -- begin*/
1434 result->table = table->Clone();
1437 /* table stuff -- end*/
1440 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1443 // copy everything behind the break-position to the new paragraph
1445 for (size_type i = 0; i < size(); ++i) {
1446 CopyIntoMinibuffer(i);
1447 result->InsertFromMinibuffer(i);
1449 result->text.resize(result->text.size());
1454 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1456 par = par->FirstPhysicalPar();
1459 par->footnoteflag == footnoteflag &&
1460 par->footnotekind == footnotekind &&
1462 par->layout == layout &&
1464 par->align == align &&
1466 par->line_bottom == line_bottom &&
1467 par->pagebreak_bottom == pagebreak_bottom &&
1468 par->added_space_bottom == added_space_bottom &&
1470 par->line_top == line_top &&
1471 par->pagebreak_top == pagebreak_top &&
1472 par->added_space_top == added_space_top &&
1474 par->pextra_type == pextra_type &&
1475 par->pextra_width == pextra_width &&
1476 par->pextra_widthp == pextra_widthp &&
1477 par->pextra_alignment == pextra_alignment &&
1478 par->pextra_hfill == pextra_hfill &&
1479 par->pextra_start_minipage == pextra_start_minipage &&
1481 par->table == table && // what means: NO TABLE AT ALL
1483 par->noindent == noindent &&
1484 par->depth == depth);
1488 void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos)
1490 // create a new paragraph
1491 LyXParagraph * par = ParFromPos(pos);
1493 LyXParagraph * tmp = new LyXParagraph(par);
1495 tmp->MakeSameLayout(par);
1497 // When can pos < Last()?
1498 // I guess pos == Last() is possible.
1500 // copy everything behind the break-position to the new
1502 size_type pos_first = 0;
1503 while (ParFromPos(pos_first) != par)
1505 size_type pos_end = pos_first + par->text.size() - 1;
1506 // make sure there is enough memory for the now larger
1507 // paragraph. This is not neccessary, because
1508 // InsertFromMinibuffer will enlarge the memory (it uses
1509 // InsertChar of course). But doing it by hand
1510 // is MUCH faster! (only one time, not thousend times!!)
1511 // Not needed since the constructor aleady have
1512 // reserved 500 elements in text.
1513 //if (pos_end > pos)
1514 // tmp->text.reserve(pos_end - pos);
1516 for (size_type i = pos; i <= pos_end; ++i) {
1517 par->CutIntoMinibuffer(i - pos_first);
1518 tmp->InsertFromMinibuffer(i - pos);
1520 tmp->text.resize(tmp->text.size());
1521 for (size_type i = pos_end; i >= pos; --i)
1522 par->Erase(i - pos_first);
1524 par->text.resize(par->text.size());
1529 // Be carefull, this does not make any check at all.
1530 void LyXParagraph::PasteParagraph()
1532 // copy the next paragraph to this one
1533 LyXParagraph * the_next = Next();
1535 LyXParagraph * firstpar = FirstPhysicalPar();
1537 // first the DTP-stuff
1538 firstpar->line_bottom = the_next->line_bottom;
1539 firstpar->added_space_bottom = the_next->added_space_bottom;
1540 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1542 size_type pos_end = the_next->text.size() - 1;
1543 size_type pos_insert = Last();
1545 // ok, now copy the paragraph
1546 for (size_type i = 0; i <= pos_end; ++i) {
1547 the_next->CutIntoMinibuffer(i);
1548 InsertFromMinibuffer(pos_insert + i);
1551 // delete the next paragraph
1556 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1558 LyXParagraph * par = ParFromPos(pos);
1560 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1561 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1567 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1569 LyXParagraph * par = ParFromPos(pos);
1571 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1572 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1578 LyXTextClass::LayoutList::size_type LyXParagraph::GetLayout() const
1580 return FirstPhysicalPar()->layout;
1584 char LyXParagraph::GetDepth() const
1586 return FirstPhysicalPar()->depth;
1590 char LyXParagraph::GetAlign() const
1592 return FirstPhysicalPar()->align;
1596 string LyXParagraph::GetLabestring() const
1598 return FirstPhysicalPar()->labelstring;
1602 int LyXParagraph::GetFirstCounter(int i) const
1604 return FirstPhysicalPar()->counter_[i];
1608 // the next two functions are for the manual labels
1609 string LyXParagraph::GetLabelWidthString() const
1611 if (!FirstPhysicalPar()->labelwidthstring.empty())
1612 return FirstPhysicalPar()->labelwidthstring;
1614 return _("Senseless with this layout!");
1618 void LyXParagraph::SetLabelWidthString(string const & s)
1620 LyXParagraph * par = FirstPhysicalPar();
1622 par->labelwidthstring = s;
1626 void LyXParagraph::SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout)
1628 LyXParagraph * par = FirstPhysicalPar();
1629 LyXParagraph * ppar = 0;
1630 LyXParagraph * npar = 0;
1632 par->layout = new_layout;
1633 /* table stuff -- begin*/
1636 /* table stuff -- end*/
1637 if (par->pextra_type == PEXTRA_NONE) {
1638 if (par->Previous()) {
1639 ppar = par->Previous()->FirstPhysicalPar();
1642 && (ppar->depth > par->depth))
1643 ppar = ppar->Previous()->FirstPhysicalPar();
1646 npar = par->Next()->NextAfterFootnote();
1649 && (npar->depth > par->depth))
1650 npar = npar->Next()->NextAfterFootnote();
1652 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1654 p1 = ppar->pextra_width,
1655 p2 = ppar->pextra_widthp;
1656 ppar->SetPExtraType(ppar->pextra_type,
1657 p1.c_str(), p2.c_str());
1659 if ((par->pextra_type == PEXTRA_NONE) &&
1660 npar && (npar->pextra_type != PEXTRA_NONE)) {
1662 p1 = npar->pextra_width,
1663 p2 = npar->pextra_widthp;
1664 npar->SetPExtraType(npar->pextra_type,
1665 p1.c_str(), p2.c_str());
1671 void LyXParagraph::SetLayout(LyXTextClass::LayoutList::size_type new_layout)
1674 * par = FirstPhysicalPar(),
1678 par->layout = new_layout;
1679 par->labelwidthstring.clear();
1680 par->align = LYX_ALIGN_LAYOUT;
1681 par->added_space_top = VSpace(VSpace::NONE);
1682 par->added_space_bottom = VSpace(VSpace::NONE);
1683 /* table stuff -- begin*/
1686 /* table stuff -- end*/
1687 if (par->pextra_type == PEXTRA_NONE) {
1688 if (par->Previous()) {
1689 ppar = par->Previous()->FirstPhysicalPar();
1692 && (ppar->depth > par->depth))
1693 ppar = ppar->Previous()->FirstPhysicalPar();
1696 npar = par->Next()->NextAfterFootnote();
1699 && (npar->depth > par->depth))
1700 npar = npar->Next()->NextAfterFootnote();
1702 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1704 p1 = ppar->pextra_width,
1705 p2 = ppar->pextra_widthp;
1706 ppar->SetPExtraType(ppar->pextra_type,
1707 p1.c_str(), p2.c_str());
1709 if ((par->pextra_type == PEXTRA_NONE) &&
1710 npar && (npar->pextra_type != PEXTRA_NONE)) {
1712 p1 = npar->pextra_width,
1713 p2 = npar->pextra_widthp;
1714 npar->SetPExtraType(npar->pextra_type,
1715 p1.c_str(), p2.c_str());
1721 // if the layout of a paragraph contains a manual label, the beginning of the
1722 // main body is the beginning of the second word. This is what the par-
1723 // function returns. If the layout does not contain a label, the main
1724 // body always starts with position 0. This differentiation is necessary,
1725 // because there cannot be a newline or a blank <= the beginning of the
1726 // main body in TeX.
1728 int LyXParagraph::BeginningOfMainBody() const
1730 if (FirstPhysicalPar() != this)
1733 // Unroll the first two cycles of the loop
1734 // and remember the previous character to
1735 // remove unnecessary GetChar() calls
1738 && GetChar(i) != LyXParagraph::META_NEWLINE) {
1740 char previous_char, temp;
1742 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1743 // Yes, this ^ is supposed to be "= " not "=="
1746 && previous_char != ' '
1747 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1749 previous_char = temp;
1754 if (i == 0 && i == size() &&
1755 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1756 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1757 ++i; /* the cursor should not jump
1758 * to the main body if there
1764 LyXParagraph * LyXParagraph::DepthHook(int deth)
1766 LyXParagraph * newpar = this;
1771 newpar = newpar->FirstPhysicalPar()->Previous();
1772 } while (newpar && newpar->GetDepth() > deth
1773 && newpar->footnoteflag == footnoteflag);
1776 if (Previous() || GetDepth())
1777 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1781 return newpar->FirstPhysicalPar();
1785 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1787 LyXParagraph const * newpar = this;
1792 newpar = newpar->FirstPhysicalPar()->Previous();
1793 } while (newpar && newpar->GetDepth() > deth
1794 && newpar->footnoteflag == footnoteflag);
1797 if (Previous() || GetDepth())
1798 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1802 return newpar->FirstPhysicalPar();
1806 int LyXParagraph::AutoDeleteInsets()
1808 vector<size_type> tmpvec;
1810 for (InsetList::iterator it = insetlist.begin();
1811 it != insetlist.end(); ++it) {
1812 if ((*it).inset && (*it).inset->AutoDelete()) {
1813 tmpvec.push_back((*it).pos);
1817 for (vector<size_type>::const_iterator cit = tmpvec.begin();
1818 cit != tmpvec.end(); ++cit) {
1825 Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
1827 InsetList::iterator it2 = insetlist.end();
1828 for (InsetList::iterator it = insetlist.begin();
1829 it != insetlist.end(); ++it) {
1830 if ((*it).pos >= pos) {
1831 if (it2 == insetlist.end() || (*it).pos < (*it2).pos)
1835 if (it2 != insetlist.end()) {
1837 return (*it2).inset;
1843 // returns -1 if inset not found
1844 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1847 for (InsetList::const_iterator cit = insetlist.begin();
1848 cit != insetlist.end(); ++cit) {
1849 if ((*cit).inset == inset) {
1853 // Think about footnotes.
1854 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
1855 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1857 NextAfterFootnote()->GetPositionOfInset(inset);
1859 return text.size() + 1 + further;
1865 void LyXParagraph::readSimpleWholeFile(istream & is)
1871 InsertChar(text.size(), c);
1876 LyXParagraph * LyXParagraph::TeXOnePar(string & file, TexRow & texrow,
1877 string & foot, TexRow & foot_texrow,
1880 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1881 LyXParagraph * par = next;
1882 LyXLayout const & style =
1883 textclasslist.Style(current_view->buffer()->params.textclass,
1886 bool further_blank_line = false;
1888 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
1890 if (start_of_appendix) {
1891 file += "\\appendix\n";
1895 if (tex_code_break_column && style.isCommand()){
1900 if (pagebreak_top) {
1901 file += "\\newpage";
1902 further_blank_line = true;
1904 if (added_space_top.kind() != VSpace::NONE) {
1905 file += added_space_top.asLatexCommand();
1906 further_blank_line = true;
1910 file += "\\lyxline{\\" + getFont(0).latexSize() + '}';
1911 file += "\\vspace{-1\\parskip}";
1912 further_blank_line = true;
1915 if (further_blank_line){
1920 LyXDirection direction = getParDirection();
1921 LyXDirection global_direction =
1922 current_view->buffer()->params.getDocumentDirection();
1923 if (direction != global_direction) {
1924 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1925 file += "\\unsethebrew\n";
1927 file += "\\sethebrew\n";
1932 switch (style.latextype) {
1935 file += style.latexname();
1936 file += style.latexparam();
1938 case LATEX_ITEM_ENVIRONMENT:
1940 bibkey->Latex(file, false);
1944 case LATEX_LIST_ENVIRONMENT:
1951 bool need_par = SimpleTeXOnePar(file, texrow);
1953 // Spit out footnotes
1954 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
1955 && par->footnoteflag != footnoteflag) {
1956 par = par->TeXFootnote(file, texrow,
1957 foot, foot_texrow, foot_count,
1959 par->SimpleTeXOnePar(file, texrow);
1963 // Make sure that \\par is done with the font of the last
1964 // character if this has another size as the default.
1965 // This is necessary because LaTeX (and LyX on the screen)
1966 // calculates the space between the baselines according
1967 // to this font. (Matthias)
1968 LyXFont font = getFont(Last()-1);
1970 if (style.resfont.size() != font.size()) {
1972 file += font.latexSize();
1976 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
1977 GetLayout()).isCommand()){
1978 if (style.resfont.size() != font.size()) {
1980 file += font.latexSize();
1984 } else if (style.resfont.size() != font.size()){
1985 file += "{\\" + font.latexSize() + " \\par}";
1988 if (direction != global_direction)
1989 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1990 file += "\\sethebrew";
1992 file += "\\unsethebrew";
1994 switch (style.latextype) {
1995 case LATEX_ITEM_ENVIRONMENT:
1996 case LATEX_LIST_ENVIRONMENT:
1997 if (par && (depth < par->depth)) {
2002 case LATEX_ENVIRONMENT:
2003 // if its the last paragraph of the current environment
2004 // skip it otherwise fall through
2006 && (par->layout != layout
2007 || par->depth != depth
2008 || par->pextra_type != pextra_type))
2011 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE
2012 && footnotekind != LyXParagraph::FOOTNOTE
2013 && footnotekind != LyXParagraph::MARGIN
2017 // don't insert this if we would be adding it
2018 // before or after a table in a float. This
2019 // little trick is needed in order to allow
2020 // use of tables in \subfigures or \subtables.
2026 further_blank_line = false;
2028 file += "\\lyxline{\\" + getFont(Last()-1).latexSize() + '}';
2029 further_blank_line = true;
2032 if (added_space_bottom.kind() != VSpace::NONE) {
2033 file += added_space_bottom.asLatexCommand();
2034 further_blank_line = true;
2037 if (pagebreak_bottom) {
2038 file += "\\newpage";
2039 further_blank_line = true;
2042 if (further_blank_line){
2047 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2048 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2053 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2058 // This one spits out the text of the paragraph
2059 bool LyXParagraph::SimpleTeXOnePar(string & file, TexRow & texrow)
2061 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2064 return SimpleTeXOneTablePar(file, texrow);
2067 size_type main_body;
2069 bool return_value = false;
2071 LyXLayout const & style = textclasslist.Style(current_view->buffer()->params.textclass, GetLayout());
2072 LyXFont basefont, last_font;
2074 // Maybe we have to create a optional argument.
2075 if (style.labeltype != LABEL_MANUAL)
2078 main_body = BeginningOfMainBody();
2080 if (main_body > 0) {
2082 basefont = getFont(-2); // Get label font
2084 basefont = getFont(-1); // Get layout font
2092 if (style.isCommand()) {
2095 } else if (align != LYX_ALIGN_LAYOUT) {
2098 return_value = true;
2102 // Which font is currently active?
2103 LyXFont running_font = basefont;
2104 // Do we have an open font change?
2105 bool open_font = false;
2107 texrow.start(this, 0);
2109 for (size_type i = 0; i < size(); ++i) {
2111 // First char in paragraph or after label?
2112 if (i == main_body && !IsDummy()) {
2113 if (main_body > 0) {
2115 column += running_font.latexWriteEndChanges(file, basefont, basefont);
2118 basefont = getFont(-1); // Now use the layout font
2119 running_font = basefont;
2123 if (style.isCommand()) {
2126 } else if (align != LYX_ALIGN_LAYOUT) {
2129 return_value = true;
2133 file += "\\noindent ";
2137 case LYX_ALIGN_NONE:
2138 case LYX_ALIGN_BLOCK:
2139 case LYX_ALIGN_LAYOUT:
2140 case LYX_ALIGN_SPECIAL: break;
2141 case LYX_ALIGN_LEFT:
2142 file += "\\raggedright ";
2145 case LYX_ALIGN_RIGHT:
2146 file += "\\raggedleft ";
2149 case LYX_ALIGN_CENTER:
2150 file += "\\centering ";
2158 // Fully instantiated font
2159 LyXFont font = getFont(i);
2160 last_font = running_font;
2162 // Spaces at end of font change are simulated to be
2163 // outside font change, i.e. we write "\textXX{text} "
2164 // rather than "\textXX{text }". (Asger)
2165 if (open_font && c == ' ' && i <= size() - 2
2166 && !getFont(i+1).equalExceptLatex(running_font)
2167 && !getFont(i+1).equalExceptLatex(font)) {
2168 font = getFont(i + 1);
2170 // We end font definition before blanks
2171 if (!font.equalExceptLatex(running_font) && open_font) {
2172 column += running_font.latexWriteEndChanges(file,
2174 (i == main_body-1) ? basefont : font);
2175 running_font = basefont;
2179 // Blanks are printed before start of fontswitch
2181 // Do not print the separation of the optional argument
2182 if (i != main_body - 1) {
2183 SimpleTeXBlanks(file, texrow, i,
2184 column, font, style);
2188 // Do we need to change font?
2189 if (!font.equalExceptLatex(running_font)
2190 && i != main_body-1) {
2191 column += font.latexWriteStartChanges(file, basefont, last_font);
2192 running_font = font;
2196 if (c == LyXParagraph::META_NEWLINE) {
2197 // newlines are handled differently here than
2198 // the default in SimpleTeXSpecialChars().
2199 if (!style.newline_allowed
2200 || font.latex() == LyXFont::ON) {
2204 column += running_font.latexWriteEndChanges(file, basefont, basefont);
2207 basefont = getFont(-1);
2208 running_font = basefont;
2209 if (font.family() ==
2210 LyXFont::TYPEWRITER_FAMILY) {
2216 texrow.start(this, i + 1);
2219 SimpleTeXSpecialChars(file, texrow,
2220 font, running_font, basefont,
2221 open_font, style, i, column, c);
2225 // If we have an open font definition, we have to close it
2227 running_font.latexWriteEndChanges(file, basefont, basefont);
2230 // Needed if there is an optional argument but no contents.
2231 if (main_body > 0 && main_body == size()) {
2233 return_value = false;
2236 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2237 return return_value;
2241 // This one spits out the text of a table paragraph
2242 bool LyXParagraph::SimpleTeXOneTablePar(string & file, TexRow & texrow)
2244 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2246 bool return_value = false;
2248 LyXLayout const & style =
2249 textclasslist.Style(current_view->buffer()->params.textclass,
2253 if (!IsDummy()) { // it is dummy if it is in a float!!!
2254 if (style.isCommand()) {
2257 } else if (align != LYX_ALIGN_LAYOUT) {
2260 return_value = true;
2263 file += "\\noindent ";
2267 case LYX_ALIGN_NONE:
2268 case LYX_ALIGN_BLOCK:
2269 case LYX_ALIGN_LAYOUT:
2270 case LYX_ALIGN_SPECIAL: break;
2271 case LYX_ALIGN_LEFT:
2272 file += "\\raggedright ";
2275 case LYX_ALIGN_RIGHT:
2276 file += "\\raggedleft ";
2279 case LYX_ALIGN_CENTER:
2280 file += "\\centering ";
2286 LyXFont basefont = getFont(-1); // Get layout font
2287 // Which font is currently active?
2288 LyXFont running_font = basefont;
2290 // Do we have an open font change?
2291 bool open_font = false;
2292 int current_cell_number = -1;
2293 int tmp = table->TexEndOfCell(file, current_cell_number);
2294 for (; tmp > 0 ; --tmp)
2297 texrow.start(this, 0);
2299 for (size_type i = 0; i < size(); ++i) {
2300 char c = GetChar(i);
2301 if (table->IsContRow(current_cell_number + 1)) {
2302 if (c == LyXParagraph::META_NEWLINE)
2303 ++current_cell_number;
2308 // Fully instantiated font
2309 LyXFont font = getFont(i);
2310 last_font = running_font;
2312 // Spaces at end of font change are simulated to be
2313 // outside font change.
2314 // i.e. we write "\textXX{text} " rather than
2315 // "\textXX{text }". (Asger)
2316 if (open_font && c == ' ' && i <= size() - 2
2317 && getFont(i+1) != running_font && getFont(i+1) != font) {
2318 font = getFont(i+1);
2321 // We end font definition before blanks
2322 if (font != running_font && open_font) {
2323 column += running_font.latexWriteEndChanges(file,
2325 running_font = basefont;
2328 // Blanks are printed before start of fontswitch
2330 SimpleTeXBlanks(file, texrow, i, column, font, style);
2332 // Do we need to change font?
2333 if (font != running_font) {
2334 column += font.latexWriteStartChanges(file, basefont, last_font);
2335 running_font = font;
2338 // Do we need to turn on LaTeX mode?
2339 if (font.latex() != running_font.latex()) {
2340 if (font.latex() == LyXFont::ON
2341 && style.needprotect) {
2342 file += "\\protect ";
2346 if (c == LyXParagraph::META_NEWLINE) {
2347 // special case for inside a table
2348 // different from default case in
2349 // SimpleTeXSpecialChars()
2351 column += running_font
2352 .latexWriteEndChanges(file, basefont, basefont);
2355 basefont = getFont(-1);
2356 running_font = basefont;
2357 ++current_cell_number;
2358 if (table->CellHasContRow(current_cell_number) >= 0) {
2359 TeXContTableRows(file, i + 1,
2360 current_cell_number,
2363 // if this cell follow only ContRows till end don't
2364 // put the EndOfCell because it is put after the
2366 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2367 --current_cell_number;
2370 int tmp = table->TexEndOfCell(file,
2371 current_cell_number);
2374 } else if (tmp < 0) {
2380 texrow.start(this, i + 1);
2382 SimpleTeXSpecialChars(file, texrow,
2383 font, running_font, basefont,
2384 open_font, style, i, column, c);
2388 // If we have an open font definition, we have to close it
2390 running_font.latexWriteEndChanges(file, basefont, basefont);
2392 ++current_cell_number;
2393 tmp = table->TexEndOfCell(file, current_cell_number);
2394 for (; tmp > 0; --tmp)
2396 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2397 return return_value;
2401 // This one spits out the text off ContRows in tables
2402 bool LyXParagraph::TeXContTableRows(string & file,
2403 LyXParagraph::size_type i,
2404 int current_cell_number,
2405 int & column, TexRow & texrow)
2407 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2413 bool return_value = false;
2414 LyXLayout const & style =
2415 textclasslist.Style(current_view->buffer()->params.textclass,
2417 LyXFont basefont = getFont(-1); // Get layout font
2419 // Which font is currently active?
2420 LyXFont running_font = basefont;
2421 // Do we have an open font change?
2422 bool open_font = false;
2424 size_type lastpos = i;
2425 int cell = table->CellHasContRow(current_cell_number);
2426 ++current_cell_number;
2428 // first find the right position
2430 for (; (i < size()) && (current_cell_number<cell); ++i) {
2432 if (c == LyXParagraph::META_NEWLINE)
2433 ++current_cell_number;
2437 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2441 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2446 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2450 // Fully instantiated font
2451 LyXFont font = getFont(i);
2452 last_font = running_font;
2454 // Spaces at end of font change are simulated to
2455 // be outside font change. i.e. we write
2456 // "\textXX{text} " rather than "\textXX{text }".
2458 if (open_font && c == ' ' && i <= size() - 2
2459 && getFont(i + 1) != running_font
2460 && getFont(i + 1) != font) {
2461 font = getFont(i + 1);
2464 // We end font definition before blanks
2465 if (font != running_font && open_font) {
2466 column += running_font.latexWriteEndChanges(file, basefont, font);
2467 running_font = basefont;
2470 // Blanks are printed before start of fontswitch
2472 SimpleTeXBlanks(file, texrow, i,
2473 column, font, style);
2475 // Do we need to change font?
2476 if (font != running_font) {
2478 font.latexWriteStartChanges(file,
2479 basefont, last_font);
2480 running_font = font;
2483 // Do we need to turn on LaTeX mode?
2484 if (font.latex() != running_font.latex()) {
2485 if (font.latex() == LyXFont::ON
2486 && style.needprotect)
2488 file += "\\protect ";
2492 SimpleTeXSpecialChars(file, texrow, font,
2493 running_font, basefont,
2494 open_font, style, i, column, c);
2496 // If we have an open font definition, we have to close it
2498 running_font.latexWriteEndChanges(file, basefont, basefont);
2501 basefont = getFont(-1);
2502 running_font = basefont;
2503 cell = table->CellHasContRow(current_cell_number);
2505 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2506 return return_value;
2510 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2512 bool retval = false;
2514 case LyXParagraph::META_HFILL:
2515 sgml_string.clear();
2517 case LyXParagraph::META_PROTECTED_SEPARATOR:
2520 case LyXParagraph::META_NEWLINE:
2524 sgml_string = "&";
2527 sgml_string = "<";
2530 sgml_string = ">";
2533 sgml_string = "$";
2536 sgml_string = "#";
2539 sgml_string = "%";
2542 sgml_string = "[";
2545 sgml_string = "]";
2548 sgml_string = "{";
2551 sgml_string = "}";
2554 sgml_string = "˜";
2557 sgml_string = """;
2560 sgml_string = "\";
2566 case '\0': // Ignore :-)
2567 sgml_string.clear();
2577 void LyXParagraph::SimpleDocBookOneTablePar(string & file, string & extra,
2578 int & desc_on, int depth)
2581 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2583 LyXFont font1, font2;
2586 size_type main_body;
2587 string emph = "emphasis";
2588 bool emph_flag = false;
2590 LyXLayout const & style =
2591 textclasslist.Style(current_view->buffer()->params.textclass,
2594 if (style.labeltype != LABEL_MANUAL)
2597 main_body = BeginningOfMainBody();
2599 // Gets paragraph main font.
2601 font1 = style.labelfont;
2605 int char_line_count = depth;
2606 addNewlineAndDepth(file, depth);
2607 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2608 file += "<INFORMALTABLE>";
2609 addNewlineAndDepth(file, ++depth);
2611 int current_cell_number = -1;
2612 int tmp = table->DocBookEndOfCell(file, current_cell_number, depth);
2614 // Parsing main loop.
2615 for (size_type i = 0; i < size(); ++i) {
2617 if (table->IsContRow(current_cell_number+1)) {
2618 if (c == LyXParagraph::META_NEWLINE)
2619 ++current_cell_number;
2624 // Fully instantiated font
2627 // Handle <emphasis> tag.
2628 if (font1.emph() != font2.emph() && i) {
2629 if (font2.emph() == LyXFont::ON) {
2630 file += "<emphasis>";
2632 } else if (emph_flag) {
2633 file += "</emphasis>";
2637 if (c == LyXParagraph::META_NEWLINE) {
2638 // We have only to control for emphasis open here!
2640 file += "</emphasis>";
2643 font1 = font2 = getFont(-1);
2644 ++current_cell_number;
2645 if (table->CellHasContRow(current_cell_number) >= 0) {
2646 DocBookContTableRows(file, extra, desc_on, i+1,
2647 current_cell_number,
2650 // if this cell follow only ContRows till end don't
2651 // put the EndOfCell because it is put after the
2653 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2654 --current_cell_number;
2657 tmp = table->DocBookEndOfCell(file,
2658 current_cell_number,
2663 } else if (c == LyXParagraph::META_INSET) {
2664 inset = GetInset(i);
2666 inset->DocBook(tmp_out);
2668 // This code needs some explanation:
2669 // Two insets are treated specially
2670 // label if it is the first element in a
2671 // command paragraph
2673 // graphics inside tables or figure floats
2675 // title (the equivalente in latex for this
2677 // and title should come first
2680 if(desc_on != 3 || i != 0) {
2681 if(tmp_out[0] == '@') {
2683 extra += frontStrip(tmp_out,
2686 file += frontStrip(tmp_out,
2691 } else if (font2.latex() == LyXFont::ON) {
2692 // "TeX"-Mode on == > SGML-Mode on.
2698 if (linuxDocConvertChar(c, sgml_string)
2699 && !style.free_spacing) {
2700 // in freespacing mode, spaces are
2701 // non-breaking characters
2706 file += "</term><listitem><para>";
2712 file += sgml_string;
2718 // Needed if there is an optional argument but no contents.
2719 if (main_body > 0 && main_body == size()) {
2724 file += "</emphasis>";
2727 ++current_cell_number;
2728 tmp = table->DocBookEndOfCell(file, current_cell_number, depth);
2729 // Resets description flag correctly.
2732 // <term> not closed...
2736 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2737 file += "</INFORMALTABLE>";
2739 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
2744 void LyXParagraph::DocBookContTableRows(string & file, string & extra,
2746 LyXParagraph::size_type i,
2747 int current_cell_number, int &column)
2752 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
2757 string emph= "emphasis";
2758 bool emph_flag= false;
2759 int char_line_count= 0;
2761 LyXLayout const & style =
2762 textclasslist.Style(current_view->buffer()->params.textclass,
2765 size_type main_body;
2766 if (style.labeltype != LABEL_MANUAL)
2769 main_body = BeginningOfMainBody();
2771 // Gets paragraph main font.
2774 font1 = style.labelfont;
2778 size_type lastpos = i;
2779 int cell = table->CellHasContRow(current_cell_number);
2780 ++current_cell_number;
2782 // first find the right position
2784 for (; i < size() && current_cell_number < cell; ++i) {
2786 if (c == LyXParagraph::META_NEWLINE)
2787 ++current_cell_number;
2791 // I don't know how to handle this so I comment it
2792 // for the moment (Jug)
2793 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2794 // file += " \\\\\n";
2797 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2802 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2806 // Fully instantiated font
2809 // Handle <emphasis> tag.
2810 if (font1.emph() != font2.emph() && i) {
2811 if (font2.emph() == LyXFont::ON) {
2812 file += "<emphasis>";
2814 } else if (emph_flag) {
2815 file += "</emphasis>";
2819 if (c == LyXParagraph::META_INSET) {
2820 inset = GetInset(i);
2822 inset->DocBook(tmp_out);
2824 // This code needs some explanation:
2825 // Two insets are treated specially
2826 // label if it is the first element in a
2827 // command paragraph
2829 // graphics inside tables or figure floats
2830 // can't go on title (the equivalente in
2831 // latex for this case is caption and title
2832 // should come first
2835 if(desc_on != 3 || i != 0) {
2836 if(tmp_out[0] == '@') {
2838 extra += frontStrip(tmp_out, '@');
2840 file += frontStrip(tmp_out, '@');
2844 } else if (font2.latex() == LyXFont::ON) {
2845 // "TeX"-Mode on == > SGML-Mode on.
2851 if (linuxDocConvertChar(c, sgml_string)
2852 && !style.free_spacing) {
2853 // in freespacing mode, spaces are
2854 // non-breaking characters
2859 file += "</term><listitem><para>";
2865 file += sgml_string;
2869 // we have only to control for emphasis open here!
2871 file += "</emphasis>";
2874 font1 = font2 = getFont(-1);
2875 cell = table->CellHasContRow(current_cell_number);
2877 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
2881 void LyXParagraph::SimpleTeXBlanks(string & file, TexRow & texrow,
2882 LyXParagraph::size_type const i,
2883 int & column, LyXFont const & font,
2884 LyXLayout const & style)
2886 if (column > tex_code_break_column
2888 && GetChar(i - 1) != ' '
2890 // In LaTeX mode, we don't want to
2891 // break lines since some commands
2893 && ! (font.latex() == LyXFont::ON)
2894 // same in FreeSpacing mode
2895 && !style.free_spacing
2896 // In typewriter mode, we want to avoid
2897 // ! . ? : at the end of a line
2898 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
2899 && (GetChar(i-1) == '.'
2900 || GetChar(i-1) == '?'
2901 || GetChar(i-1) == ':'
2902 || GetChar(i-1) == '!'))) {
2903 if (tex_code_break_column == 0) {
2904 // in batchmode we need LaTeX to still
2905 // see it as a space not as an extra '\n'
2911 texrow.start(this, i+1);
2913 } else if (font.latex() == LyXFont::OFF) {
2914 if (style.free_spacing) {
2923 void LyXParagraph::SimpleTeXSpecialChars(string & file, TexRow & texrow,
2925 LyXFont & running_font,
2928 LyXLayout const & style,
2929 LyXParagraph::size_type & i,
2930 int & column, char const c)
2932 // Two major modes: LaTeX or plain
2933 // Handle here those cases common to both modes
2934 // and then split to handle the two modes separately.
2936 case LyXParagraph::META_INSET: {
2937 Inset * inset = GetInset(i);
2940 int len = file.length();
2941 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
2942 || inset->LyxCode() == Inset::MATH_CODE
2943 || inset->LyxCode() == Inset::URL_CODE)
2944 && running_font.getFontDirection()
2945 == LYX_DIR_RIGHT_TO_LEFT) {
2949 int tmp = inset->Latex(file, style.isCommand());
2956 column += file.length() - len;
2965 case LyXParagraph::META_NEWLINE:
2967 column += running_font.latexWriteEndChanges(file,
2968 basefont, basefont);
2971 basefont = getFont(-1);
2972 running_font = basefont;
2975 case LyXParagraph::META_HFILL:
2976 file += "\\hfill{}";
2981 // And now for the special cases within each mode
2982 // Are we in LaTeX mode?
2983 if (font.latex() == LyXFont::ON) {
2984 // at present we only have one option
2985 // but I'll leave it as a switch statement
2986 // so its simpler to extend. (ARRae)
2988 case LyXParagraph::META_PROTECTED_SEPARATOR:
2993 // make sure that we will not print
2994 // error generating chars to the tex
2995 // file. This test would not be needed
2996 // if it were done in the buffer
3004 // Plain mode (i.e. not LaTeX)
3006 case LyXParagraph::META_PROTECTED_SEPARATOR:
3011 file += "\\textbackslash{}";
3015 case '°': case '±': case '²': case '³':
3016 case '×': case '÷': case '¹': case 'ª':
3017 case 'º': case '¬': case 'µ':
3018 if (current_view->buffer()->params.inputenc == "latin1") {
3019 file += "\\ensuremath{";
3028 case '|': case '<': case '>':
3029 // In T1 encoding, these characters exist
3030 if (lyxrc->fontenc == "T1") {
3032 //... but we should avoid ligatures
3033 if ((c == '>' || c == '<')
3035 && GetChar(i+1) == c){
3036 file += "\\textcompwordmark{}";
3041 // Typewriter font also has them
3042 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3046 // Otherwise, we use what LaTeX
3050 file += "\\textless{}";
3054 file += "\\textgreater{}";
3058 file += "\\textbar{}";
3064 case '-': // "--" in Typewriter mode -> "-{}-"
3066 && GetChar(i + 1) == '-'
3067 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3076 file += "\\char`\\\"{}";
3081 if (current_view->buffer()->params.inputenc == "default") {
3082 file += "\\pounds{}";
3090 case '%': case '#': case '{':
3098 file += "\\textasciitilde{}";
3103 file += "\\textasciicircum{}";
3107 case '*': case '[': case ']':
3108 // avoid being mistaken for optional arguments
3116 // Blanks are printed before font switching.
3117 // Sure? I am not! (try nice-latex)
3118 // I am sure it's correct. LyX might be smarter
3119 // in the future, but for now, nothing wrong is
3124 /* idea for labels --- begin*/
3128 && font.family() != LyXFont::TYPEWRITER_FAMILY
3129 && GetChar(i + 1) == 'y'
3130 && GetChar(i + 2) == 'X') {
3138 && font.family() != LyXFont::TYPEWRITER_FAMILY
3139 && GetChar(i + 1) == 'e'
3140 && GetChar(i + 2) == 'X') {
3145 // Check for "LaTeX2e"
3148 && font.family() != LyXFont::TYPEWRITER_FAMILY
3149 && GetChar(i + 1) == 'a'
3150 && GetChar(i + 2) == 'T'
3151 && GetChar(i + 3) == 'e'
3152 && GetChar(i + 4) == 'X'
3153 && GetChar(i + 5) == '2'
3154 && GetChar(i + 6) == 'e') {
3155 file += "\\LaTeXe{}";
3159 // Check for "LaTeX"
3162 && font.family() != LyXFont::TYPEWRITER_FAMILY
3163 && GetChar(i + 1) == 'a'
3164 && GetChar(i + 2) == 'T'
3165 && GetChar(i + 3) == 'e'
3166 && GetChar(i + 4) == 'X') {
3167 file += "\\LaTeX{}";
3170 /* idea for labels --- end*/
3171 } else if (c != '\0') {
3181 bool LyXParagraph::RoffContTableRows(ostream & os,
3182 LyXParagraph::size_type i,
3188 LyXFont font1 = LyXFont(LyXFont::ALL_INHERIT);
3193 string fname2 = TmpFileName(string(), "RAT2");
3195 int cell = table->CellHasContRow(actcell);
3198 // first find the right position
3200 for (; i < size() && actcell < cell; ++i) {
3202 if (c == LyXParagraph::META_NEWLINE)
3207 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3210 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3212 font2 = GetFontSettings(i);
3213 if (font1.latex() != font2.latex()) {
3214 if (font2.latex() != LyXFont::OFF)
3219 case LyXParagraph::META_INSET:
3220 if ((inset = GetInset(i))) {
3221 fstream fs(fname2.c_str(),
3224 WriteAlert(_("LYX_ERROR:"),
3225 _("Cannot open temporary file:"),
3229 inset->Latex(fs, -1);
3242 case LyXParagraph::META_NEWLINE:
3244 case LyXParagraph::META_HFILL:
3246 case LyXParagraph::META_PROTECTED_SEPARATOR:
3255 lyxerr.debug() << "RoffAsciiTable: "
3256 "NULL char in structure."
3261 cell = table->CellHasContRow(actcell);
3267 LyXParagraph * LyXParagraph::TeXDeeper(string & file, TexRow & texrow,
3268 string & foot, TexRow & foot_texrow,
3271 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3272 LyXParagraph * par = this;
3274 while (par && par->depth == depth) {
3276 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3277 if (textclasslist.Style(current_view->buffer()->params.textclass,
3278 par->layout).isEnvironment()
3279 || par->pextra_type != PEXTRA_NONE)
3281 par = par->TeXEnvironment(file, texrow,
3285 par = par->TeXOnePar(file, texrow,
3290 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3296 LyXParagraph * LyXParagraph::TeXEnvironment(string & file, TexRow & texrow,
3298 TexRow & foot_texrow,
3301 bool eindent_open = false;
3302 bool foot_this_level = false;
3303 // flags when footnotetext should be appended to file.
3304 static bool minipage_open = false;
3305 static int minipage_open_depth = 0;
3306 char par_sep = current_view->buffer()->params.paragraph_separation;
3308 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3310 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3312 LyXLayout const & style =
3313 textclasslist.Style(current_view->buffer()->params.textclass,
3316 if (pextra_type == PEXTRA_INDENT) {
3317 if (!pextra_width.empty()) {
3318 file += "\\begin{LyXParagraphIndent}{"
3319 + pextra_width + "}\n";
3321 //float ib = atof(pextra_widthp.c_str())/100;
3322 // string can't handle floats at present (971109)
3323 // so I'll do a conversion by hand knowing that
3324 // the limits are 0.0 to 1.0. ARRae.
3325 file += "\\begin{LyXParagraphIndent}{";
3326 switch (pextra_widthp.length()) {
3332 file += pextra_widthp;
3336 file += pextra_widthp;
3338 file += "\\columnwidth}\n";
3341 eindent_open = true;
3343 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3344 if (pextra_hfill && Previous() &&
3345 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3346 file += "\\hfill{}\n";
3349 if (par_sep == BufferParams::PARSEP_INDENT) {
3350 file += "{\\setlength\\parindent{0pt}\n";
3353 file += "\\begin{minipage}";
3354 switch(pextra_alignment) {
3355 case MINIPAGE_ALIGN_TOP:
3358 case MINIPAGE_ALIGN_MIDDLE:
3361 case MINIPAGE_ALIGN_BOTTOM:
3365 if (!pextra_width.empty()) {
3367 file += pextra_width + "}\n";
3369 //float ib = atof(par->pextra_width.c_str())/100;
3370 // string can't handle floats at present
3371 // so I'll do a conversion by hand knowing that
3372 // the limits are 0.0 to 1.0. ARRae.
3374 switch (pextra_widthp.length()) {
3380 file += pextra_widthp;
3384 file += pextra_widthp;
3386 file += "\\columnwidth}\n";
3389 if (par_sep == BufferParams::PARSEP_INDENT) {
3390 file += "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3393 minipage_open = true;
3394 minipage_open_depth = depth;
3397 #ifdef WITH_WARNINGS
3398 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3399 //I disabled it because it breaks when lists span on several
3402 if (style.isEnvironment()){
3403 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3404 #ifdef FANCY_FOOTNOTE_CODE
3405 if (foot_count < 0) {
3406 // flag that footnote[mark][text] should be
3407 // used for any footnotes from now on
3409 foot_this_level = true;
3412 file += "\\begin{" + style.latexname() + "}{"
3413 + labelwidthstring + "}\n";
3414 } else if (style.labeltype == LABEL_BIBLIO) {
3416 file += "\\begin{" + style.latexname() + "}{"
3418 + bibitemWidthest(current_view->painter())
3421 + bibitemWidthest() + "}\n";
3423 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3424 #ifdef FANCY_FOOTNOTE_CODE
3425 if (foot_count < 0) {
3426 // flag that footnote[mark][text] should be
3427 // used for any footnotes from now on
3429 foot_this_level = true;
3432 file += "\\begin{" + style.latexname() + '}'
3433 + style.latexparam() + '\n';
3435 file += "\\begin{" + style.latexname() + '}'
3436 + style.latexparam() + '\n';
3439 LyXParagraph * par = this;
3441 par = par->TeXOnePar(file, texrow,
3442 foot, foot_texrow, foot_count);
3444 if (minipage_open && par && !style.isEnvironment() &&
3445 (par->pextra_type == PEXTRA_MINIPAGE) &&
3446 par->pextra_start_minipage) {
3447 file += "\\end{minipage}\n";
3449 if (par_sep == BufferParams::PARSEP_INDENT) {
3453 minipage_open = false;
3455 if (par && par->depth > depth) {
3456 if (textclasslist.Style(current_view->buffer()->params.textclass,
3457 par->layout).isParagraph()
3459 && !suffixIs(file, "\n\n")) {
3460 // There should be at least one '\n' already
3461 // but we need there to be two for Standard
3462 // paragraphs that are depth-increment'ed to be
3463 // output correctly. However, tables can
3464 // also be paragraphs so don't adjust them.
3469 par = par->TeXDeeper(file, texrow,
3470 foot, foot_texrow, foot_count);
3472 if (par && par->layout == layout && par->depth == depth &&
3473 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3474 if (par->pextra_hfill && par->Previous() &&
3475 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3476 file += "\\hfill{}\n";
3479 if (par_sep == BufferParams::PARSEP_INDENT) {
3480 file += "{\\setlength\\parindent{0pt}\n";
3483 file += "\\begin{minipage}";
3484 switch(par->pextra_alignment) {
3485 case MINIPAGE_ALIGN_TOP:
3488 case MINIPAGE_ALIGN_MIDDLE:
3491 case MINIPAGE_ALIGN_BOTTOM:
3495 if (!par->pextra_width.empty()) {
3497 file += par->pextra_width;
3500 //float ib = atof(par->pextra_widthp.c_str())/100;
3501 // string can't handle floats at present
3502 // so I'll do a conversion by hand knowing that
3503 // the limits are 0.0 to 1.0. ARRae.
3505 switch (par->pextra_widthp.length()) {
3511 file += par->pextra_widthp;
3515 file += par->pextra_widthp;
3517 file += "\\columnwidth}\n";
3520 if (par_sep == BufferParams::PARSEP_INDENT) {
3521 file += "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3524 minipage_open = true;
3525 minipage_open_depth = par->depth;
3528 && par->layout == layout
3529 && par->depth == depth
3530 && par->pextra_type == pextra_type);
3532 if (style.isEnvironment()) {
3533 file += "\\end{" + style.latexname() + '}';
3534 // maybe this should go after the minipage closes?
3535 if (foot_this_level) {
3536 if (foot_count >= 1) {
3537 if (foot_count > 1) {
3538 file += "\\addtocounter{footnote}{-";
3539 file += tostr(foot_count - 1);
3543 texrow += foot_texrow;
3545 foot_texrow.reset();
3550 if (minipage_open && (minipage_open_depth == depth) &&
3551 (!par || par->pextra_start_minipage ||
3552 par->pextra_type != PEXTRA_MINIPAGE)) {
3553 file += "\\end{minipage}\n";
3555 if (par_sep == BufferParams::PARSEP_INDENT) {
3559 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3560 file += "\\medskip\n\n";
3564 minipage_open = false;
3567 file += "\\end{LyXParagraphIndent}\n";
3570 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3571 && par->pextra_hfill)) {
3575 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3576 return par; // ale970302
3580 LyXParagraph * LyXParagraph::TeXFootnote(string & file, TexRow & texrow,
3581 string & foot, TexRow & foot_texrow,
3583 LyXDirection par_direction)
3585 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3586 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3587 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3588 "No footnote!" << endl;
3590 LyXParagraph * par = this;
3591 LyXLayout const & style = textclasslist.Style(current_view->buffer()->params.textclass,
3592 previous->GetLayout());
3594 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3595 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3596 "Float other than footnote in command"
3597 " with moving argument is illegal" << endl;
3600 if (footnotekind != LyXParagraph::FOOTNOTE
3601 && footnotekind != LyXParagraph::MARGIN
3603 && !suffixIs(file, '\n')) {
3604 // we need to ensure that real floats like tables and figures
3605 // have their \begin{} on a new line otherwise we can get
3606 // incorrect results when using the endfloat.sty package
3607 // especially if two floats follow one another. ARRae 981022
3608 // NOTE: if the file is length 0 it must have just been
3609 // written out so we assume it ended with a '\n'
3614 BufferParams * params = ¤t_view->buffer()->params;
3615 bool footer_in_body = true;
3616 switch (footnotekind) {
3617 case LyXParagraph::FOOTNOTE:
3618 if (style.intitle) {
3619 file += "\\thanks{\n";
3620 footer_in_body = false;
3622 if (foot_count == -1) {
3623 // we're at depth 0 so we can use:
3624 file += "\\footnote{%\n";
3625 footer_in_body = false;
3627 file += "\\footnotemark{}%\n";
3629 // we only need this when there are
3630 // multiple footnotes
3631 foot += "\\stepcounter{footnote}";
3633 foot += "\\footnotetext{%\n";
3634 foot_texrow.start(this, 0);
3635 foot_texrow.newline();
3640 case LyXParagraph::MARGIN:
3641 file += "\\marginpar{\n";
3643 case LyXParagraph::FIG:
3644 if (pextra_type == PEXTRA_FLOATFLT
3645 && (!pextra_width.empty()
3646 || !pextra_widthp.empty())) {
3648 if (!pextra_width.empty())
3649 sprintf(bufr, "\\begin{floatingfigure}{%s}\n",
3650 pextra_width.c_str());
3653 "\\begin{floatingfigure}{%f\\textwidth}\n",
3654 atoi(pextra_widthp.c_str())/100.0);
3657 file += "\\begin{figure}";
3658 if (!params->float_placement.empty()) {
3660 file += params->float_placement;
3667 case LyXParagraph::TAB:
3668 file += "\\begin{table}";
3669 if (!params->float_placement.empty()) {
3671 file += params->float_placement;
3677 case LyXParagraph::WIDE_FIG:
3678 file += "\\begin{figure*}";
3679 if (!params->float_placement.empty()) {
3681 file += params->float_placement;
3687 case LyXParagraph::WIDE_TAB:
3688 file += "\\begin{table*}";
3689 if (!params->float_placement.empty()) {
3691 file += params->float_placement;
3697 case LyXParagraph::ALGORITHM:
3698 file += "\\begin{algorithm}\n";
3704 LyXDirection direction = getParDirection();
3705 if (direction != par_direction) {
3706 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3707 file += "\\unsethebrew\n";
3709 file += "\\sethebrew\n";
3713 if (footnotekind != LyXParagraph::FOOTNOTE
3714 || !footer_in_body) {
3715 // Process text for all floats except footnotes in body
3717 LyXLayout const & style =
3718 textclasslist.Style(current_view->buffer()->params.textclass,
3721 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3723 if (style.isEnvironment()
3724 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3725 // Allows the use of minipages within float
3726 // environments. Shouldn't be circular because
3727 // we don't support footnotes inside
3728 // floats (yet). ARRae
3729 par = par->TeXEnvironment(file, texrow,
3733 par = par->TeXOnePar(file, texrow,
3738 if (par && !par->IsDummy() && par->depth > depth) {
3739 par = par->TeXDeeper(file, texrow,
3743 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3745 // process footnotes > depth 0 or in environments separately
3746 // NOTE: Currently don't support footnotes within footnotes
3747 // even though that is possible using the \footnotemark
3749 TexRow dummy_texrow;
3750 int dummy_count = 0;
3752 LyXLayout const & style =
3753 textclasslist.Style(current_view->buffer()->params.textclass,
3756 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3758 if (style.isEnvironment()
3759 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3760 // Allows the use of minipages within float
3761 // environments. Shouldn't be circular because
3762 // we don't support footnotes inside
3763 // floats (yet). ARRae
3764 par = par->TeXEnvironment(foot, foot_texrow,
3765 dummy, dummy_texrow,
3768 par = par->TeXOnePar(foot, foot_texrow,
3769 dummy, dummy_texrow,
3773 if (par && !par->IsDummy() && par->depth > depth) {
3774 par = par->TeXDeeper(foot, foot_texrow,
3775 dummy, dummy_texrow,
3779 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3781 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3782 "Footnote in a Footnote -- not supported"
3787 switch (footnotekind) {
3788 case LyXParagraph::FOOTNOTE:
3789 if (footer_in_body) {
3790 // This helps tell which of the multiple
3791 // footnotetexts an error was in.
3793 foot_texrow.newline();
3798 case LyXParagraph::MARGIN:
3801 case LyXParagraph::FIG:
3802 if (pextra_type == PEXTRA_FLOATFLT
3803 && (!pextra_width.empty()
3804 || !pextra_widthp.empty()))
3805 file += "\\end{floatingfigure}";
3807 file += "\\end{figure}";
3809 case LyXParagraph::TAB:
3810 file += "\\end{table}";
3812 case LyXParagraph::WIDE_FIG:
3813 file += "\\end{figure*}";
3815 case LyXParagraph::WIDE_TAB:
3816 file += "\\end{table*}";
3818 case LyXParagraph::ALGORITHM:
3819 file += "\\end{algorithm}";
3823 if (footnotekind != LyXParagraph::FOOTNOTE
3824 && footnotekind != LyXParagraph::MARGIN) {
3825 // we need to ensure that real floats like tables and figures
3826 // have their \end{} on a line of their own otherwise we can
3827 // get incorrect results when using the endfloat.sty package.
3832 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
3837 void LyXParagraph::SetPExtraType(int type, char const * width,
3838 char const * widthp)
3841 pextra_width = width;
3842 pextra_widthp = widthp;
3844 if (textclasslist.Style(current_view->buffer()->params.textclass,
3845 layout).isEnvironment()) {
3850 while (par && (par->layout == layout)
3851 && (par->depth == depth)) {
3853 par = par->Previous();
3855 par = par->FirstPhysicalPar();
3856 while (par && par->depth > depth) {
3857 par = par->Previous();
3859 par = par->FirstPhysicalPar();
3863 while (par && (par->layout == layout)
3864 && (par->depth == depth)) {
3865 par->pextra_type = type;
3866 par->pextra_width = width;
3867 par->pextra_widthp = widthp;
3868 par = par->NextAfterFootnote();
3869 if (par && (par->depth > depth))
3870 par->SetPExtraType(type, width, widthp);
3871 while (par && ((par->depth > depth) || par->IsDummy()))
3872 par = par->NextAfterFootnote();
3878 void LyXParagraph::UnsetPExtraType()
3880 if (pextra_type == PEXTRA_NONE)
3883 pextra_type = PEXTRA_NONE;
3884 pextra_width.clear();
3885 pextra_widthp.clear();
3887 if (textclasslist.Style(current_view->buffer()->params.textclass,
3888 layout).isEnvironment()) {
3893 while (par && (par->layout == layout)
3894 && (par->depth == depth)) {
3896 par = par->Previous();
3898 par = par->FirstPhysicalPar();
3899 while (par && par->depth > depth) {
3900 par = par->Previous();
3902 par = par->FirstPhysicalPar();
3906 while (par && (par->layout == layout)
3907 && (par->depth == depth)) {
3908 par->pextra_type = PEXTRA_NONE;
3909 par->pextra_width.clear();
3910 par->pextra_widthp.clear();
3911 par = par->NextAfterFootnote();
3912 if (par && (par->depth > depth))
3913 par->UnsetPExtraType();
3914 while (par && ((par->depth > depth) || par->IsDummy()))
3915 par = par->NextAfterFootnote();
3921 bool LyXParagraph::IsHfill(size_type pos) const
3923 return IsHfillChar(GetChar(pos));
3927 bool LyXParagraph::IsInset(size_type pos) const
3929 return IsInsetChar(GetChar(pos));
3933 bool LyXParagraph::IsFloat(size_type pos) const
3935 return IsFloatChar(GetChar(pos));
3939 bool LyXParagraph::IsNewline(size_type pos) const
3943 tmp = IsNewlineChar(GetChar(pos));
3948 bool LyXParagraph::IsSeparator(size_type pos) const
3950 return IsSeparatorChar(GetChar(pos));
3954 bool LyXParagraph::IsLineSeparator(size_type pos) const
3956 return IsLineSeparatorChar(GetChar(pos));
3960 bool LyXParagraph::IsKomma(size_type pos) const
3962 return IsKommaChar(GetChar(pos));
3966 /// Used by the spellchecker
3967 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
3969 unsigned char c = GetChar(pos);
3970 if (IsLetterChar(c))
3972 // '\0' is not a letter, allthough every string contains "" (below)
3975 // We want to pass the ' and escape chars to ispell
3976 string extra = lyxrc->isp_esc_chars + '\'';
3980 return contains(extra, ch);
3984 bool LyXParagraph::IsWord(size_type pos ) const
3986 return IsWordChar(GetChar(pos)) ;