The branch, master, has been updated.

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

commit b59547ebd5cc16c749fe761ff46f0e2c4b45fcbf
Author: Georg Baum <[email protected]>
Date:   Fri Feb 22 21:59:23 2013 +0100

    Improve texl2yx refstyle support
    
    - Convert prettyref to the autopackage mechanism
    - Do not load refstyle automatically if some refstyle preamble code of LyX
      is found, since LyX will only load the package if an actual reference
      command is used. This is needed for mixed refstyle/prettyref documents.
    - Only recognize refstyle commands if refstyle was detected in the preamble
    - Only recognize prettyref commands if prettyref was detected in the 
preamble
    - Add a mixed refstyle/prettyref test case

diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index 9d72a5e..72800ec 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -181,9 +181,9 @@ const char * const known_xetex_packages[] = {"arabxetex", 
"fixlatvian",
 const char * const known_lyx_packages[] = {"amsbsy", "amsmath", "amssymb",
 "amstext", "amsthm", "array", "babel", "booktabs", "calc", "CJK", "color",
 "float", "fontspec", "graphicx", "hhline", "ifthen", "longtable", "makeidx",
-"multirow", "nomencl", "pdfpages", "refstyle", "rotating", "rotfloat", 
"splitidx",
-"setspace", "subscript", "textcomp", "tipa", "tipx", "tone", "ulem", "url",
-"varioref", "verbatim", "wrapfig", "xunicode", 0};
+"multirow", "nomencl", "pdfpages", "prettyref", "refstyle", "rotating",
+"rotfloat", "splitidx", "setspace", "subscript", "textcomp", "tipa", "tipx",
+"tone", "ulem", "url", "varioref", "verbatim", "wrapfig", "xunicode", 0};
 
 // used for the handling of \newindex
 int index_number = 0;
@@ -522,7 +522,7 @@ Preamble::Preamble() : one_language(true), 
explicit_babel(false),
        h_use_geometry            = "false";
        h_use_default_options     = "false";
        h_use_hyperref            = "false";
-       h_use_refstyle            = "0";
+       h_use_refstyle            = false;
        h_use_packages["amsmath"]    = "1";
        h_use_packages["amssymb"]    = "0";
        h_use_packages["esint"]      = "1";
@@ -897,9 +897,6 @@ void Preamble::handle_package(Parser &p, string const & 
name,
                h_language_package = "\\usepackage{" + name + "}";
        }
 
-       else if (name == "prettyref")
-               ; // ignore this FIXME: Use the package separator mechanism 
instead
-
        else if (name == "lyxskak") {
                // ignore this and its options
                const char * const o[] = {"ps", "mover", 0};
@@ -910,7 +907,9 @@ void Preamble::handle_package(Parser &p, string const & 
name,
                if (name == "splitidx")
                        h_use_indices = "true";
                if (name == "refstyle")
-                       h_use_refstyle = "1";
+                       h_use_refstyle = true;
+               else if (name == "prettyref")
+                       h_use_refstyle = false;
                if (!in_lyx_preamble) {
                        h_preamble << package_beg_sep << name
                                   << package_mid_sep << "\\usepackage{"
@@ -1417,7 +1416,6 @@ void Preamble::parse(Parser & p, string const & 
forceclass,
                                || name == "thmref"
                                || name == "lemref") {
                                p.skip_spaces();
-                               
preamble.registerAutomaticallyLoadedPackage("refstyle");
                                in_lyx_preamble = true;
                        }
                        // only non-lyxspecific stuff
@@ -1453,7 +1451,6 @@ void Preamble::parse(Parser & p, string const & 
forceclass,
                                || name == 
"\\providecommand\\corref[1]{\\ref{cor:#1}}"
                                || name == 
"\\providecommand\\propref[1]{\\ref{prop:#1}}") {
                                p.skip_spaces();
-                               
preamble.registerAutomaticallyLoadedPackage("refstyle");
                                in_lyx_preamble = true;
                        }
                        // only non-lyxspecific stuff
diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h
index ecb0be1..3216c3c 100644
--- a/src/tex2lyx/Preamble.h
+++ b/src/tex2lyx/Preamble.h
@@ -39,7 +39,7 @@ public:
        ///
        std::string notefontcolor() const { return h_notefontcolor; }
        ///
-       std::string refstyle() const { return h_use_refstyle; }
+       bool refstyle() const { return h_use_refstyle; }
        ///
        bool fontCJKSet() const { return h_font_cjk_set; }
        ///
@@ -192,7 +192,7 @@ private:
        std::map<std::string, std::string> h_use_packages;
        std::string h_use_default_options;
        std::string h_use_hyperref;
-       std::string h_use_refstyle;
+       bool h_use_refstyle;
 
        /*!
         * Add package \p name with options \p options to used_packages.
diff --git a/src/tex2lyx/test/test-insets.lyx.lyx 
b/src/tex2lyx/test/test-insets.lyx.lyx
index d0d2da9..3d58cd7 100644
--- a/src/tex2lyx/test/test-insets.lyx.lyx
+++ b/src/tex2lyx/test/test-insets.lyx.lyx
@@ -5,6 +5,11 @@
 \textclass article
 \begin_preamble
 
+% Load refstyle before prettyref so that prettyref wins.
+% The real refstyle tests are in test-refstyle-theorems.tex.
+\usepackage{refstyle}
+
+
 \def\mycommand{\textquestiondown}
 
 
@@ -245,7 +250,49 @@ reference "lab:test"
 
 \end_inset
 
-.
+. The command 
+\begin_inset ERT
+status collapsed
+
+\begin_layout Plain Layout
+
+\backslash
+secref
+\end_layout
+
+\end_inset
+
+
+\begin_inset ERT
+status collapsed
+
+\begin_layout Plain Layout
+{
+\end_layout
+
+\end_inset
+
+lab:test
+\begin_inset ERT
+status collapsed
+
+\begin_layout Plain Layout
+}
+\end_layout
+
+\end_inset
+
+ will be parsed in ERT, since 
+\begin_inset ERT
+status collapsed
+
+\begin_layout Plain Layout
+LyX
+\end_layout
+
+\end_inset
+
+ does not support refstyle and prettyref natively at the same time.
 \end_layout
 
 \begin_layout Section
diff --git a/src/tex2lyx/test/test-insets.tex b/src/tex2lyx/test/test-insets.tex
index 28d4301..0feb452 100644
--- a/src/tex2lyx/test/test-insets.tex
+++ b/src/tex2lyx/test/test-insets.tex
@@ -18,7 +18,6 @@
 \providecommand{\makenomenclature}{\makeglossary}
 \makenomenclature
 \usepackage{varioref}
-\usepackage{prettyref}
 \usepackage{splitidx}
 \makeindex
 \newindex[Index]{idx}
@@ -54,6 +53,12 @@
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
 
+% Load refstyle before prettyref so that prettyref wins.
+% The real refstyle tests are in test-refstyle-theorems.tex.
+\usepackage{refstyle}
+\AtBeginDocument{\providecommand\secref[1]{\ref{sec:#1}}}
+\usepackage{prettyref}
+
 \def\mycommand{\textquestiondown}
 
 \begin{document}
@@ -82,6 +87,8 @@ reference~\pageref{lab:test}, but also equation
 reference~\eqref{lab:test} (from amsmath package), or varioref's
 equivalents~\vref{lab:test} and~\vpageref{lab:test}, without
 forgetting pretty references like~\prettyref{lab:test}.
+The command \secref{lab:test} will be parsed in ERT, since LyX
+does not support refstyle and prettyref natively at the same time.
 
 \section{Cites\index{Cites}}
 
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index d3ceb58..2a988bc 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -3407,40 +3407,13 @@ void parse_text(Parser & p, ostream & os, unsigned 
flags, bool outer,
                        skip_spaces_braces(p);
                }
 
-               else if ((where = is_known(t.cs(), known_ref_commands))) {
-                       // \eqref can also occur if refstyle is used
-                       if (t.cs() == "eqref" && preamble.refstyle() == "1") {
-                               context.check_layout(os);
-                               begin_command_inset(os, "ref", "formatted");
-                               os << "reference \"eq:"
-                                  << 
convert_command_inset_arg(p.verbatim_item())
-                                  << "\"\n";
-                               end_inset(os);
-                               
preamble.registerAutomaticallyLoadedPackage("refstyle");
-                       } else {
-                               string const opt = p.getOpt();
-                               if (opt.empty()) {
-                                       context.check_layout(os);
-                                       begin_command_inset(os, "ref",
-                                               known_coded_ref_commands[where 
- known_ref_commands]);
-                                       os << "reference \""
-                                          << 
convert_command_inset_arg(p.verbatim_item())
-                                          << "\"\n";
-                                       end_inset(os);
-                                       if (t.cs() == "vref" || t.cs() == 
"vpageref")
-                                               
preamble.registerAutomaticallyLoadedPackage("varioref");
-                               } else {
-                                       // LyX does not yet support optional 
arguments of ref commands
-                                       output_ert_inset(os, t.asInput() + '[' 
+ opt + "]{" +
-                                              p.verbatim_item() + "}", 
context);
-                               }
-                       }
-               }
-
-               else if ((where = is_known(t.cs(), known_refstyle_commands))) {
+               // handle refstyle first to catch \eqref which can also occur
+               // without refstyle. Only recognize these commands if
+               // refstyle.sty was found in the preamble (otherwise \eqref
+               // and user defined ref commands could be misdetected).
+               else if ((where = is_known(t.cs(), known_refstyle_commands)) &&
+                        preamble.refstyle()) {
                        context.check_layout(os);
-                       // \eqref can also occur if refstyle is not used
-                       // this case is already handled in the previous else if
                        begin_command_inset(os, "ref", "formatted");
                        os << "reference \"";
                        os << known_refstyle_prefixes[where - 
known_refstyle_commands]
@@ -3451,6 +3424,30 @@ void parse_text(Parser & p, ostream & os, unsigned 
flags, bool outer,
                        preamble.registerAutomaticallyLoadedPackage("refstyle");
                }
 
+               // if refstyle is used, we must not convert \prettyref to a
+               // formatted reference, since that would result in a refstyle 
command.
+               else if ((where = is_known(t.cs(), known_ref_commands)) &&
+                        (t.cs() != "prettyref" || !preamble.refstyle())) {
+                       string const opt = p.getOpt();
+                       if (opt.empty()) {
+                               context.check_layout(os);
+                               begin_command_inset(os, "ref",
+                                       known_coded_ref_commands[where - 
known_ref_commands]);
+                               os << "reference \""
+                                  << 
convert_command_inset_arg(p.verbatim_item())
+                                  << "\"\n";
+                               end_inset(os);
+                               if (t.cs() == "vref" || t.cs() == "vpageref")
+                                       
preamble.registerAutomaticallyLoadedPackage("varioref");
+                               else if (t.cs() == "prettyref")
+                                       
preamble.registerAutomaticallyLoadedPackage("prettyref");
+                       } else {
+                               // LyX does not yet support optional arguments 
of ref commands
+                               output_ert_inset(os, t.asInput() + '[' + opt + 
"]{" +
+                                      p.verbatim_item() + '}', context);
+                       }
+               }
+
                else if (use_natbib &&
                         is_known(t.cs(), known_natbib_commands) &&
                         ((t.cs() != "citefullauthor" &&

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

Summary of changes:
 src/tex2lyx/Preamble.cpp             |   17 ++++-----
 src/tex2lyx/Preamble.h               |    4 +-
 src/tex2lyx/test/test-insets.lyx.lyx |   49 ++++++++++++++++++++++++++-
 src/tex2lyx/test/test-insets.tex     |    9 ++++-
 src/tex2lyx/text.cpp                 |   63 ++++++++++++++++------------------
 5 files changed, 95 insertions(+), 47 deletions(-)


hooks/post-receive
-- 
The LyX Source Repository

Reply via email to