]> git.lyx.org Git - lyx.git/commitdiff
tex2lyx: support for plural and capitalized refstyle
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 26 Aug 2018 07:48:23 +0000 (09:48 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Tue, 11 Sep 2018 06:07:03 +0000 (08:07 +0200)
Also fix a glitch in non-refstyle import (getOpt() returns the option
with delimiter, so do not add them in ERT once more)

Candidate for stable

(cherry picked from commit faf40fb4084e10848bbb33ec6d892c05843cd179)

src/tex2lyx/TODO.txt
src/tex2lyx/text.cpp
status.23x

index a5f4f8ac3e9a5b1fe0f4c337661eb31ffc5f5f19..7244a6b4f7865ba44bf1c0884c04a6375ce53f18 100644 (file)
@@ -34,8 +34,6 @@ Format LaTeX feature                        LyX feature
 443    unicode-math.sty                     InsetMath*
 453    automatic stmaryrd loading           \use_package stmaryrd
 457    automatic stackrel loading           \use_package stackrel
-526    Plural and capitalized refstyles      InsetRef
-
 
 
 General
index 2e10421b730246a6c3091c925a9244cd87769d7f..38b03d91793f29dbab834e819492a968837f3e64 100644 (file)
@@ -539,6 +539,24 @@ string const fromPolyglossiaEnvironment(string const s)
 }
 
 
+string uncapitalize(string const s)
+{
+       docstring in = from_ascii(s);
+       char_type t = lowercase(s[0]);
+       in[0] = t;
+       return to_ascii(in);
+}
+
+
+bool isCapitalized(string const s)
+{
+       docstring in = from_ascii(s);
+       char_type t = uppercase(s[0]);
+       in[0] = t;
+       return to_ascii(in) == s;
+}
+
+
 } // namespace
 
 
@@ -4041,21 +4059,37 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        continue;
                }
 
-               // handle refstyle first to catch \eqref which can also occur
-               // without refstyle. Only recognize these commands if
+               // Handle refstyle first in order to to catch \eqref, because this
+               // 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).
-               if ((where = is_known(t.cs(), known_refstyle_commands))
+               // We uncapitalize the input in order to catch capitalized commands
+               // such as \Eqref.
+               if ((where = is_known(uncapitalize(t.cs()), known_refstyle_commands))
                     && preamble.refstyle()) {
+                       string const cap = isCapitalized(t.cs()) ? "true" : "false";
+                       string plural = "false";
+                       // Catch the plural option [s]
+                       if (p.hasOpt()) {
+                               string const opt = p.getOpt();
+                               if (opt == "[s]")
+                                       plural = "true";
+                               else {
+                                       // LyX does not yet support other optional arguments of ref commands
+                                       output_ert_inset(os, t.asInput() + opt + "{" +
+                                              p.verbatim_item() + '}', context);
+                                       continue;
+                               }
+                       }
                        context.check_layout(os);
                        begin_command_inset(os, "ref", "formatted");
                        os << "reference \"";
                        os << known_refstyle_prefixes[where - known_refstyle_commands]
                           << ":";
-                       os << convert_literate_command_inset_arg(p.verbatim_item())
+                       os << convert_literate_command_inset_arg(p.getArg('{', '}'))
                           << "\"\n";
-                       os << "plural \"false\"\n";
-                       os << "caps \"false\"\n";
+                       os << "plural \"" << plural << "\"\n";
+                       os << "caps \"" << cap << "\"\n";
                        os << "noprefix \"false\"\n";
                        end_inset(os);
                        preamble.registerAutomaticallyLoadedPackage("refstyle");
@@ -4084,8 +4118,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                        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);
+                               output_ert_inset(os, t.asInput() + opt + "{" +
+                                                p.verbatim_item() + '}', context);
                        }
                        continue;
                }
index 81a153c0c115abd2421771b113fb53939f05d378..b0c95fde1973ca7e42c6ab4b2bbd6fac913b8ab8 100644 (file)
@@ -43,6 +43,8 @@ What's new
 
 - Add support for decimal alignment in table cells.
 
+- Add support for plural and capitalized refstyle references.
+
 
 
 * USER INTERFACE