From 300cd0dedde67cf32cdcd2ebb07ff6d4760a2012 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sun, 19 Dec 2010 21:24:24 +0000 Subject: [PATCH] Increase tex2lyx output format to 320. 320: Support protected hfill Detect other horizontal spaces that are already part of format 319 Add forgotton use_parbox tag to boxes (confuses lyx2lyx, but no lyx) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36949 a592a061-630c-0410-9148-cb99ea01b6c8 --- .../test/box-color-size-space-align.tex | 4 +- src/tex2lyx/tex2lyx.h | 2 +- src/tex2lyx/text.cpp | 63 +++++++++++++------ 3 files changed, 49 insertions(+), 20 deletions(-) diff --git a/src/tex2lyx/test/box-color-size-space-align.tex b/src/tex2lyx/test/box-color-size-space-align.tex index c97ccc92f5..019b2461c6 100644 --- a/src/tex2lyx/test/box-color-size-space-align.tex +++ b/src/tex2lyx/test/box-color-size-space-align.tex @@ -284,6 +284,7 @@ raggedleft 2 raggedleft 2 raggedleft 2 raggedleft 2 raggedleft 2 \subsection{Horizontal spaces} Lines can have an hfill \hfill in the middle. +Lines can have an hfill \hspace{\fill} in the middle. Lines can have a protected hfill \hspace*{\fill} in the middle. Lines can have a dotted fill \dotfill in the middle. Lines can have a rule fill \hrulefill in the middle. @@ -320,7 +321,8 @@ qquad\qquad{}a \subsection{Vertical spaces} -Lines can have an vfill \vfill in the middle. +Lines can have a vfill \vfill in the middle. +Lines can have a vfill \vspace{\fill} in the middle. Lines can have a protected vfill \vspace*{\fill} in the middle. Lines can have vertical space \vspace{2cm} in the middle. Lines can have protected vertical space \vspace*{2cm} in the middle. diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h index ec88d582fd..d63cae7107 100644 --- a/src/tex2lyx/tex2lyx.h +++ b/src/tex2lyx/tex2lyx.h @@ -114,7 +114,7 @@ extern CommandMap known_math_environments; /// extern bool noweb_mode; /// LyX format that is created by tex2lyx -int const LYX_FORMAT = 319; +int const LYX_FORMAT = 320; /// path of the master .tex file extern std::string getMasterFilePath(); diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 637a609197..4e525fd0d6 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -831,6 +831,7 @@ void parse_environment(Parser & p, ostream & os, bool outer, "hor_pos \"c\"\n" "has_inner_box 0\n" "inner_pos \"t\"\n" + "use_parbox 0\n" "width \"100col%\"\n" "special \"none\"\n" "height \"1in\"\n" @@ -2729,16 +2730,18 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, } } - else if (t.cs() == "vspace") { + else if (t.cs() == "hspace" || t.cs() == "vspace") { bool starred = false; if (p.next_token().asInput() == "*") { p.get_token(); starred = true; } + string name = t.asInput(); string const length = p.verbatim_item(); string unit; string valstring; bool valid = splitLatexLength(length, valstring, unit); + bool known_hspace = false; bool known_vspace = false; bool known_unit = false; double value; @@ -2746,21 +2749,31 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, istringstream iss(valstring); iss >> value; if (value == 1.0) { - if (unit == "\\smallskipamount") { - unit = "smallskip"; - known_vspace = true; - } else if (unit == "\\medskipamount") { - unit = "medskip"; - known_vspace = true; - } else if (unit == "\\bigskipamount") { - unit = "bigskip"; - known_vspace = true; - } else if (unit == "\\fill") { - unit = "vfill"; - known_vspace = true; + if (t.cs()[0] == 'h') { + if (unit == "\\fill") { + if (!starred) { + unit = ""; + name = "hfill"; + } + known_hspace = true; + } + } else { + if (unit == "\\smallskipamount") { + unit = "smallskip"; + known_vspace = true; + } else if (unit == "\\medskipamount") { + unit = "medskip"; + known_vspace = true; + } else if (unit == "\\bigskipamount") { + unit = "bigskip"; + known_vspace = true; + } else if (unit == "\\fill") { + unit = "vfill"; + known_vspace = true; + } } } - if (!known_vspace) { + if (!known_hspace && !known_vspace) { switch (unitFromString(unit)) { case Length::SP: case Length::PT: @@ -2782,8 +2795,23 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, } } - if (known_unit || known_vspace) { - // Literal length or known variable + if (t.cs()[0] == 'h' && (known_unit || known_hspace)) { + // Literal horizontal length or known variable + context.check_layout(os); + begin_inset(os, "Space \\"); + os << name; + if (starred) + os << '*'; + os << '{'; + if (known_hspace) + os << unit; + os << "}\n"; + if (known_unit && !known_hspace) + os << "\\length " + << translate_len(length) << '\n'; + end_inset(os); + } else if (known_unit || known_vspace) { + // Literal vertical length or known variable context.check_layout(os); begin_inset(os, "VSpace "); if (known_unit) @@ -2793,8 +2821,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, os << '*'; end_inset(os); } else { - // LyX can't handle other length variables in Inset VSpace - string name = t.asInput(); + // LyX can't handle other length variables in Inset V?Space if (starred) name += '*'; if (valid) { -- 2.39.2