commit 489cdae255294f760b9814a17f8571f2410f6548
Author: Uwe Stöhr <[email protected]>
Date: Sun Nov 23 04:56:47 2014 +0100
tex2lyx: support relative lengths in \vspace and \hspace
diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt
index f7118e1..2196789 100644
--- a/src/tex2lyx/TODO.txt
+++ b/src/tex2lyx/TODO.txt
@@ -36,7 +36,6 @@ Format LaTeX feature LyX feature
358 custom makeindex command \index_command
363 horizontal longtable alignment InsetTabular
364 branch file name suffix \filename_suffix
-367 relative lengths for h and v space InsetSpace, InsetVSpace
368 glue lengths InsetSpace
371 automatic mhchem loading \use_mhchem
375 \includeonly \{begin,end}_includeonly
diff --git a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
index 2b74bb9..c8bef4e 100644
--- a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
+++ b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
@@ -1694,11 +1694,16 @@ in the middle. Lines can have a downbrace fill
\end_inset
-in the middle. Lines can have space
+in the middle. Lines can have absolute space
\begin_inset space \hspace{}
\length 2cm
\end_inset
+ in the middle. Lines can have relative space
+\begin_inset space \hspace{}
+\length 12text%
+\end_inset
+
in the middle. Lines can have protected space
\begin_inset space \hspace*{}
\length 2cm
@@ -2006,10 +2011,14 @@ in the middle. Lines can have a vfill
\begin_inset VSpace vfill*
\end_inset
- in the middle. Lines can have vertical space
+ in the middle. Lines can have vertical absolute space
\begin_inset VSpace 2cm
\end_inset
+ in the middle. Lines can have vertical relative space
+\begin_inset VSpace 9col%
+\end_inset
+
in the middle. Lines can have protected vertical space
\begin_inset VSpace 2cm*
\end_inset
diff --git a/src/tex2lyx/test/box-color-size-space-align.tex
b/src/tex2lyx/test/box-color-size-space-align.tex
index e0428fd..009fcc0 100644
--- a/src/tex2lyx/test/box-color-size-space-align.tex
+++ b/src/tex2lyx/test/box-color-size-space-align.tex
@@ -357,7 +357,8 @@ Lines can have a left arrow fill \leftarrowfill in the
middle.
Lines can have a right arrow fill \rightarrowfill in the middle.
Lines can have a upbrace fill \upbracefill in the middle.
Lines can have a downbrace fill \downbracefill in the middle.
-Lines can have space \hspace{2cm} in the middle.
+Lines can have absolute space \hspace{2cm} in the middle.
+Lines can have relative space \hspace{0.12\textwidth} in the middle.
Lines can have protected space \hspace*{2cm} in the middle.
We also handle defined spaces:
@@ -421,7 +422,8 @@ interword: $a\ b$
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 vertical absolute space \vspace{2cm} in the middle.
+Lines can have vertical relative space \vspace{0.09\columnwidth} in the middle.
Lines can have protected vertical space \vspace*{2cm} in the middle.
We also handle skips:
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index 2c212a4..36efcae 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -4395,8 +4395,15 @@ void parse_text(Parser & p, ostream & os, unsigned
flags, bool outer,
case Length::MU:
known_unit = true;
break;
- default:
+ default: {
+ //unitFromString(unit) fails
for relative units like Length::PCW
+ // therefore handle them
separately
+ if (unit == "\\paperwidth" ||
unit == "\\columnwidth"
+ || unit ==
"\\textwidth" || unit == "\\linewidth"
+ || unit ==
"\\textheight" || unit == "\\paperheight")
+ known_unit = true;
break;
+ }
}
}
}
@@ -4420,9 +4427,10 @@ void parse_text(Parser & p, ostream & os, unsigned
flags, bool outer,
// Literal vertical length or known variable
context.check_layout(os);
begin_inset(os, "VSpace ");
- if (known_unit)
- os << value;
- os << unit;
+ if (known_vspace)
+ os << unit;
+ if (known_unit && !known_vspace)
+ os << translate_len(length);
if (starred)
os << '*';
end_inset(os);