The branch, 2.0.x, has been updated.

- Log -----------------------------------------------------------------

commit cdee2a16528bb9a3b41e71012d05182623932f77
Author: Georg Baum <[email protected]>
Date:   Wed Nov 28 22:17:00 2012 +0100

    Document backported fix for bug #4468

diff --git a/status.20x b/status.20x
index 5adafb5..4517802 100644
--- a/status.20x
+++ b/status.20x
@@ -101,6 +101,8 @@ What's new
 
 - correct import of the command \framebox (bug 8223).
 
+- Import \verb+\+ correctly (bug 4468).
+
 
 * ADVANCED FIND AND REPLACE
 

commit b4150f1f82fa511405cb646de250c6da0c04bb58
Author: Georg Baum <[email protected]>
Date:   Thu Oct 18 20:57:03 2012 +0200

    Forgot to remove obsolete comment

diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index 3a2e493..3e38367 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -1375,8 +1375,6 @@ void parse_environment(Parser & p, ostream & os, bool 
outer,
        else if (name == "lstlisting") {
                eat_whitespace(p, os, parent_context, false);
                // FIXME handle listings with parameters
-               //       If this is added, don't forgot to handle the
-               //       automatic color package loading
                if (p.hasOpt())
                        parse_unknown_environment(p, name, os, FLAG_END,
                                                  outer, parent_context);

commit a47e4a3766b7f864d1cbdebf0faace7e0e14763e
Author: Georg Baum <[email protected]>
Date:   Thu Oct 18 20:41:23 2012 +0200

    Add automatic color package loading for listings
    
    The listings inset does automatically load the color package if any 
parameter
    contains \color. As mentioned in bug #8066 tex2lyx needs to be aware of 
this,
    so the \usepckage{color} is automatically skipped in these cases.

diff --git a/src/tex2lyx/test/test-insets.tex b/src/tex2lyx/test/test-insets.tex
index 487effa..8052c72 100644
--- a/src/tex2lyx/test/test-insets.tex
+++ b/src/tex2lyx/test/test-insets.tex
@@ -169,7 +169,7 @@ parser test (escaped):\href{http://www.test.test}{a brace 
\} and another one \{
 
 \section{Listings}
 
-Inline: \lstinline[language={C++}]!int a=5;!\\
+Inline: \lstinline[language={C++},keywordstyle={\color{green}}]!int a=5;!\\
 Float:
 
 \begin{lstlisting}[caption={Example Listing 
float},label={lst:Example-Listing},language=Python]
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index 4d01a0e..3a2e493 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -1114,6 +1114,12 @@ void parse_listings(Parser & p, ostream & os, Context & 
parent_context)
 {
        parent_context.check_layout(os);
        begin_inset(os, "listings\n");
+       if (p.hasOpt()) {
+               string arg = p.verbatimOption();
+               os << "lstparams " << '"' << arg << '"' << '\n';
+               if (arg.find("\\color") != string::npos)
+                       preamble.registerAutomaticallyLoadedPackage("color");
+       }
        os << "inline false\n"
           << "status collapsed\n";
        Context context(true, parent_context.textclass);

commit 847f8014ca0abbc144472c322dec78f5e3c0b5a7
Author: Georg Baum <[email protected]>
Date:   Fri Oct 5 00:12:18 2012 +0200

    Really fix bug #4468.
    
    The old fix was incomplete (\verb~\~ was translated to \verb~~ in 
roundtrip).
    The real cause for this bug (and also the mistranslation of \href{...}{\}})
    was the misbehaviour of Token::character() (see comment in Parser.h): This
    method even returns a character if the category is catEscape, and this is 
not
    wanted in most (all?) cases.

diff --git a/src/tex2lyx/Parser.cpp b/src/tex2lyx/Parser.cpp
index 0cadab9..3d09e01 100644
--- a/src/tex2lyx/Parser.cpp
+++ b/src/tex2lyx/Parser.cpp
@@ -383,7 +383,7 @@ bool Parser::hasOpt()
 }
 
 
-Parser::Arg Parser::getFullArg(char left, char right)
+Parser::Arg Parser::getFullArg(char left, char right, bool allow_escaping)
 {
        skip_spaces(true);
 
@@ -393,36 +393,40 @@ Parser::Arg Parser::getFullArg(char left, char right)
                return make_pair(false, string());
 
        string result;
-       char c = getChar();
+       Token t = get_token();
 
-       if (c != left) {
+       if (t.cat() == catComment || t.cat() == catEscape ||
+           t.character() != left) {
                putback();
                return make_pair(false, string());
        } else {
-               // a single '\' is only allowed within \verb, no matter what 
the delimiter is,
-               // for example "\verb+\+" (reported as bug #4468)
-               // To support this, we allow single '\' if it is the only 
character
-               // within equal delimiters
-               if (next_token().cat() == catEscape)
-                       if (next_token().character() == right && right == left)
-                               result += '\\';
-               while ((c = getChar()) != right && good()) {
+               for (t = get_token(); good(); t = get_token()) {
                        // Ignore comments
-                       if (curr_token().cat() == catComment) {
-                               if (!curr_token().cs().empty())
-                                       cerr << "Ignoring comment: " << 
curr_token().asInput();
+                       if (t.cat() == catComment) {
+                               if (!t.cs().empty())
+                                       cerr << "Ignoring comment: " << 
t.asInput();
+                               continue;
                        }
-                       else
-                               result += curr_token().asInput();
+                       if (allow_escaping) {
+                               if (t.cat() != catEscape && t.character() == 
right)
+                                       break;
+                       } else {
+                               if (t.character() == right) {
+                                       if (t.cat() == catEscape)
+                                               result += '\\';
+                                       break;
+                               }
+                       }
+                       result += t.asInput();
                }
        }
        return make_pair(true, result);
 }
 
 
-string Parser::getArg(char left, char right)
+string Parser::getArg(char left, char right, bool allow_escaping)
 {
-       return getFullArg(left, right).second;
+       return getFullArg(left, right, allow_escaping).second;
 }
 
 
diff --git a/src/tex2lyx/Parser.h b/src/tex2lyx/Parser.h
index 5e749e3..3ddb9df 100644
--- a/src/tex2lyx/Parser.h
+++ b/src/tex2lyx/Parser.h
@@ -87,8 +87,8 @@ public:
         *        ../mathed/MathParser.cpp (which is the anchestor of this
         *        class) uses a separate char member for this method. I
         *        believe that the intended usage is to not cover tokens with
-        *        catEscape, e.g. \code
-        *        return (cs_.empty() || cat_ == catEscape) ? 0 : cs_[0];
+        *        catEscape or catComment, e.g. \code
+        *        return (cs_.empty() || cat_ == catEscape || cat_ == 
catComment) ? 0 : cs_[0];
         *        \endcode
         *        All usages of this method should be checked. gb 2011-01-05
         */
@@ -157,18 +157,24 @@ public:
        typedef std::pair<bool, std::string> Arg;
        /*!
         * Get an argument enclosed by \p left and \p right.
+        * If \p allow_escaping is true, a right delimiter escaped by a
+        * backslash does not count as delimiter, but is included in the
+        * argument.
         * \returns wether an argument was found in \p Arg.first and the
         * argument in \p Arg.second. \see getArg().
         */
-       Arg getFullArg(char left, char right);
+       Arg getFullArg(char left, char right, bool allow_escaping = true);
        /*!
         * Get an argument enclosed by \p left and \p right.
+        * If \p allow_escaping is true, a right delimiter escaped by a
+        * backslash does not count as delimiter, but is included in the
+        * argument.
         * \returns the argument (without \p left and \p right) or the empty
         * string if the next non-space token is not \p left. Use
         * getFullArg() if you need to know wether there was an empty
         * argument or no argument at all.
         */
-       std::string getArg(char left, char right);
+       std::string getArg(char left, char right, bool allow_escaping = true);
        /*!
         * Like getOpt(), but distinguishes between a missing argument ""
         * and an empty argument "[]".
diff --git a/src/tex2lyx/test/test-insets.tex b/src/tex2lyx/test/test-insets.tex
index 227fecc..487effa 100644
--- a/src/tex2lyx/test/test-insets.tex
+++ b/src/tex2lyx/test/test-insets.tex
@@ -158,6 +158,8 @@ ftp2:\href{ftp://www.test.test}{www.test.test}
 
 parser test (stupid, but valid):\href{http://www.test.test}{\}}
 
+parser test (escaped):\href{http://www.test.test}{a brace \} and another one 
\{ and something}
+
 
 \section{Lists\index{Lists}}
 
diff --git a/src/tex2lyx/test/test-structure.tex 
b/src/tex2lyx/test/test-structure.tex
index 89fa589..79989fc 100644
--- a/src/tex2lyx/test/test-structure.tex
+++ b/src/tex2lyx/test/test-structure.tex
@@ -321,6 +321,7 @@ zzz \section{
 \end{verbatim}
 \verb~\~
 \verb+\item[ABC] first item+
+\verb+something\+ bug 4468
 
 and bibliography:
 \begin{thebibliography}{9}
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index 9ca67c0..4d01a0e 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -2953,8 +2953,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, 
bool outer,
 
                else if (t.cs() == "href") {
                        context.check_layout(os);
-                       string target = p.getArg('{', '}');
-                       string name = p.getArg('{', '}');
+                       string target = 
convert_command_inset_arg(p.verbatim_item());
+                       string name = 
convert_command_inset_arg(p.verbatim_item());
                        string type;
                        size_t i = target.find(':');
                        if (i != string::npos) {
@@ -3469,7 +3469,11 @@ void parse_text(Parser & p, ostream & os, unsigned 
flags, bool outer,
                else if (t.cs() == "verb") {
                        context.check_layout(os);
                        char const delimiter = p.next_token().character();
-                       string const arg = p.getArg(delimiter, delimiter);
+                       // \verb is special: The usual escaping rules do not
+                       // apply, e.g. "\verb+\+" is valid and denotes a single
+                       // backslash (bug #4468). Therefore we do not allow
+                       // escaping in getArg().
+                       string const arg = p.getArg(delimiter, delimiter, 
false);
                        ostringstream oss;
                        oss << "\\verb" << delimiter << arg << delimiter;
                        handle_ert(os, oss.str(), context);

commit 74a196c4f435d8dbd56f8dd9b18ab7afdcc3f8d0
Author: Georg Baum <[email protected]>
Date:   Tue Sep 25 22:25:55 2012 +0200

    Add test for Parser::getFullArg()
    
    It shows that the special handling of a single backslash in the argument
    (whcih is supposed to fix bug #4468) does not work.

diff --git a/src/tex2lyx/test/test-insets.tex b/src/tex2lyx/test/test-insets.tex
index 2955031..227fecc 100644
--- a/src/tex2lyx/test/test-insets.tex
+++ b/src/tex2lyx/test/test-insets.tex
@@ -156,6 +156,8 @@ ftp:\href{ftp://www.test.test}{ftp://www.test.test}
 
 ftp2:\href{ftp://www.test.test}{www.test.test}
 
+parser test (stupid, but valid):\href{http://www.test.test}{\}}
+
 
 \section{Lists\index{Lists}}
 

commit 562848a96eacc4bd45ac64a7a057a0d400c9f106
Author: Uwe Stöhr <[email protected]>
Date:   Tue Jul 3 00:39:41 2012 +0200

    tex2lyx: update a command
    
    Parser.cpp: improve a command as discussed

diff --git a/src/tex2lyx/Parser.cpp b/src/tex2lyx/Parser.cpp
index e8337f4..0cadab9 100644
--- a/src/tex2lyx/Parser.cpp
+++ b/src/tex2lyx/Parser.cpp
@@ -399,7 +399,7 @@ Parser::Arg Parser::getFullArg(char left, char right)
                putback();
                return make_pair(false, string());
        } else {
-               // for \verb a single '\' is allowed no matter what the 
delimiter is
+               // a single '\' is only allowed within \verb, no matter what 
the delimiter is,
                // for example "\verb+\+" (reported as bug #4468)
                // To support this, we allow single '\' if it is the only 
character
                // within equal delimiters

commit f5f053ff86fcb409145e8b1db0ca8cdc4501698c
Author: Uwe Stöhr <[email protected]>
Date:   Sun Jul 1 02:12:56 2012 +0200

    tex2lyx/Parser.cpp: refine \verb handling

diff --git a/src/tex2lyx/Parser.cpp b/src/tex2lyx/Parser.cpp
index ec48e01..e8337f4 100644
--- a/src/tex2lyx/Parser.cpp
+++ b/src/tex2lyx/Parser.cpp
@@ -402,9 +402,9 @@ Parser::Arg Parser::getFullArg(char left, char right)
                // for \verb a single '\' is allowed no matter what the 
delimiter is
                // for example "\verb+\+" (reported as bug #4468)
                // To support this, we allow single '\' if it is the only 
character
-               // within the delimiters
+               // within equal delimiters
                if (next_token().cat() == catEscape)
-                       if (next_token().character() == c)
+                       if (next_token().character() == right && right == left)
                                result += '\\';
                while ((c = getChar()) != right && good()) {
                        // Ignore comments

commit bd1776bd6aab235444b762e7a255991075443420
Author: Uwe Stöhr <[email protected]>
Date:   Sat Jun 30 15:29:53 2012 +0200

    test-structure.tex: add checks for \verb

diff --git a/src/tex2lyx/test/test-structure.tex 
b/src/tex2lyx/test/test-structure.tex
index b935634..89fa589 100644
--- a/src/tex2lyx/test/test-structure.tex
+++ b/src/tex2lyx/test/test-structure.tex
@@ -299,12 +299,29 @@ What else? Well, we have descriptions:
 [{x y % bla
 z}] and with comments
 \end{description}
+
 labelings:
 \begin{lyxlist}{00.00.0000}
 \item [label~1] first item
 \item [label~2] second item
 \item [{$\left[\textrm{ }\right]^{x}$}] Label with space, math and ] in it
 \end{lyxlist}
+
+verbatim:
+\begin{verbatim}
+verbat  im % $ 02/19/12
+hjkh
+jkh \ blah
+\begin{centering}
+
+
+zzz \section{
+\end{raggedleft}
+
+\end{verbatim}
+\verb~\~
+\verb+\item[ABC] first item+
+
 and bibliography:
 \begin{thebibliography}{9}
 \bibitem{FOO} Edward Bar. \emph{The Foo Book}. (1999)

commit cb284b18d4be6f8af1d59dbbf56bc087b16b3d4f
Author: Uwe Stöhr <[email protected]>
Date:   Sat Jun 30 03:25:19 2012 +0200

    tex2lyx: fix handling of \verb
    
    - Parser.cpp: \verb can have any character as delimiter (except of ASCII 
letters) not only '+', therefore partly revert [3943b887/lyxgit] and fix it for 
all cases

diff --git a/src/tex2lyx/Parser.cpp b/src/tex2lyx/Parser.cpp
index 2de4333..ec48e01 100644
--- a/src/tex2lyx/Parser.cpp
+++ b/src/tex2lyx/Parser.cpp
@@ -399,12 +399,12 @@ Parser::Arg Parser::getFullArg(char left, char right)
                putback();
                return make_pair(false, string());
        } else {
-               // in case of the '+' as delimiter single a '\' is allowed
-               // as content, for example "\verb+\+" (reported as bug #4468)
-               // we need special handling because single \ are normally 
ignored
-               // or taken as start of a command
-               if (c == '+')
-                       if (next_token().cat() == catEscape)
+               // for \verb a single '\' is allowed no matter what the 
delimiter is
+               // for example "\verb+\+" (reported as bug #4468)
+               // To support this, we allow single '\' if it is the only 
character
+               // within the delimiters
+               if (next_token().cat() == catEscape)
+                       if (next_token().character() == c)
                                result += '\\';
                while ((c = getChar()) != right && good()) {
                        // Ignore comments

commit 7fedb3f21dca192d5b8c70529eae0399af1c2e5b
Author: Uwe Stöhr <[email protected]>
Date:   Sat Jun 23 20:00:49 2012 +0200

    tex2lyx/Parser.cpp: fix bug #4468: single '\' are allowed in the special 
case of '+' as comment argument delimiter

diff --git a/src/tex2lyx/Parser.cpp b/src/tex2lyx/Parser.cpp
index c483012..2de4333 100644
--- a/src/tex2lyx/Parser.cpp
+++ b/src/tex2lyx/Parser.cpp
@@ -398,7 +398,14 @@ Parser::Arg Parser::getFullArg(char left, char right)
        if (c != left) {
                putback();
                return make_pair(false, string());
-       } else
+       } else {
+               // in case of the '+' as delimiter single a '\' is allowed
+               // as content, for example "\verb+\+" (reported as bug #4468)
+               // we need special handling because single \ are normally 
ignored
+               // or taken as start of a command
+               if (c == '+')
+                       if (next_token().cat() == catEscape)
+                               result += '\\';
                while ((c = getChar()) != right && good()) {
                        // Ignore comments
                        if (curr_token().cat() == catComment) {
@@ -408,7 +415,7 @@ Parser::Arg Parser::getFullArg(char left, char right)
                        else
                                result += curr_token().asInput();
                }
-
+       }
        return make_pair(true, result);
 }
 

-----------------------------------------------------------------------

Summary of changes:
 src/tex2lyx/Parser.cpp              |   37 ++++++++++++++++++++++------------
 src/tex2lyx/Parser.h                |   14 +++++++++---
 src/tex2lyx/test/test-insets.tex    |    6 ++++-
 src/tex2lyx/test/test-structure.tex |   18 +++++++++++++++++
 src/tex2lyx/text.cpp                |   18 ++++++++++++----
 status.20x                          |    2 +
 6 files changed, 72 insertions(+), 23 deletions(-)


hooks/post-receive
-- 
The LyX Source Repository

Reply via email to