]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/text.cpp
tex2lyx/text.cpp: cosmetic
[lyx.git] / src / tex2lyx / text.cpp
index 2a38b07e53dfdfe52b530e8875612a6d9ac4031d..88a08d7e043e0bf536cff627028d3c3ae29d7294 100644 (file)
@@ -133,7 +133,7 @@ char const * const known_coded_quotes[] = { "prd", "ard", "ard", "ard",
 char const * const known_sizes[] = { "tiny", "scriptsize", "footnotesize",
 "small", "normalsize", "large", "Large", "LARGE", "huge", "Huge", 0};
 
-/// the same as known_sizes with .lyx names
+/// the same as known_sizes with .lyx names plus a default entry
 char const * const known_coded_sizes[] = { "default", "tiny", "scriptsize", "footnotesize",
 "small", "normal", "large", "larger", "largest", "huge", "giant", 0};
 
@@ -1536,22 +1536,44 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        eat_whitespace(p, os, context, true);
                }
 
+               // Starred section headings
                // Must attempt to parse "Section*" before "Section".
                else if ((p.next_token().asInput() == "*") &&
                         context.new_layout_allowed &&
-                        // The single '=' is meant here.
                         (newlayout = findLayout(context.textclass, t.cs() + '*')) &&
-                         newlayout->isCommand()) {
+                        newlayout->isCommand()) {
+                       TeXFont const oldFont = context.font;
+                       // save the current font size
+                       string const size = oldFont.size;
+                       // reset the font size to default, because the font size switches don't
+                       // affect section headings and the like
+                       context.font.size = known_coded_sizes[0];
+                       output_font_change(os, oldFont, context.font);
+                       // write the layout
                        p.get_token();
                        output_command_layout(os, p, outer, context, newlayout);
+                       // set the font size to the original value
+                       context.font.size = size;
+                       output_font_change(os, oldFont, context.font);
                        p.skip_spaces();
                }
 
-               // The single '=' is meant here.
+               // Section headings and the like
                else if (context.new_layout_allowed &&
                         (newlayout = findLayout(context.textclass, t.cs())) &&
                         newlayout->isCommand()) {
+                       TeXFont const oldFont = context.font;
+                       // save the current font size
+                       string const size = oldFont.size;
+                       // reset the font size to default, because the font size switches don't
+                       // affect section headings and the like
+                       context.font.size = known_coded_sizes[0];
+                       output_font_change(os, oldFont, context.font);
+                       // write the layout
                        output_command_layout(os, p, outer, context, newlayout);
+                       // set the font size to the original value
+                       context.font.size = size;
+                       output_font_change(os, oldFont, context.font);
                        p.skip_spaces();
                }
 
@@ -2610,7 +2632,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                        }
                                }
                        }
-
                        if (known_unit || known_vspace) {
                                // Literal length or known variable
                                context.check_layout(os);
@@ -2638,6 +2659,79 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        }
                }
 
+               else if (t.cs() == "hspace") {
+                       bool starred = false;
+                       if (p.next_token().asInput() == "*") {
+                               p.get_token();
+                               starred = true;
+                       }
+                       string const length = p.verbatim_item();
+                       string unit;
+                       string valstring;
+                       bool valid = splitLatexLength(length, valstring, unit);
+                       bool known_unit = false;
+                       bool fill = false;
+                       double value;
+                       if (valid) {
+                               istringstream iss(valstring);
+                               iss >> value;
+                               if (value == 1.0)
+                                       if (unit == "\\fill") {
+                                               known_unit = true;
+                                               fill = true;
+                                       }
+                               switch (unitFromString(unit)) {
+                               case Length::SP:
+                               case Length::PT:
+                               case Length::BP:
+                               case Length::DD:
+                               case Length::MM:
+                               case Length::PC:
+                               case Length::CC:
+                               case Length::CM:
+                               case Length::IN:
+                               case Length::EX:
+                               case Length::EM:
+                               case Length::MU:
+                                       known_unit = true;
+                                       break;
+                               default:
+                                       break;
+                               }
+                       }
+                       if (known_unit) {
+                               // Literal length or known variable
+                               context.check_layout(os);
+                               begin_inset(os, "Space ");
+                               if (known_unit) {
+                                       os << "\\hspace";
+                                       if (starred)
+                                               os << '*';
+                                       if (fill)
+                                               os << "{" + unit + "}";
+                                       else {
+                                               os << "{}\n";
+                                               os << "\\length " << value << unit;
+                                       }
+                               }                               
+                               end_inset(os);
+                       } else {
+                               // LyX can't handle other length variables in Inset HSpace
+                               string name = t.asInput();
+                               if (starred)
+                                       name += '*';
+                               if (valid) {
+                                       if (value == 1.0)
+                                               handle_ert(os, name + '{' + unit + '}', context);
+                                       else if (value == -1.0)
+                                               handle_ert(os, name + "{-" + unit + '}', context);
+                                       else
+                                               handle_ert(os, name + '{' + valstring + unit + '}', context);
+                               } else
+                                       handle_ert(os, name + '{' + length + '}', context);
+                       }
+               }
+
                else {
                        //cerr << "#: " << t << " mode: " << mode << endl;
                        // heuristic: read up to next non-nested space