]> git.lyx.org Git - features.git/commitdiff
Fix bug #11410.
authorRichard Kimberly Heck <rikiheck@lyx.org>
Sun, 4 Dec 2022 23:33:58 +0000 (18:33 -0500)
committerRichard Kimberly Heck <rikiheck@lyx.org>
Sun, 4 Dec 2022 23:33:58 +0000 (18:33 -0500)
Main part of patch from Daniel, adapted by me.
I also added the lyx2lyx code.

lib/lyx2lyx/lyx_2_4.py
lib/ui/stdcontext.inc
src/frontends/qt/GuiRef.cpp
src/frontends/qt/ui/RefUi.ui
src/insets/InsetCommandParams.cpp
src/insets/InsetCommandParams.h
src/insets/InsetRef.cpp
src/tex2lyx/TODO.txt
src/version.h

index 5c0507a5af78618612ed85b3d7c44630908d0022..e10475bc76df96b0466723e397e434b262ca5391 100644 (file)
@@ -4550,6 +4550,81 @@ def revert_index_macros(document):
             document.body[pl:pl+1] = document.body[pl:pl] + sortkey + put_cmd_in_ert("@")
             
 
+def revert_starred_refs(document):
+    i = find_token(document.header, "\\use_hyperref true", 0)
+    use_hyperref = (i != -1)
+    i = 0
+    in_inset = False
+    cmd = ref = ""
+    plural = caps = noprefix = nolink = False
+    nolinkline = -1
+    while True:
+        if not in_inset:
+            i = find_token(document.body, "\\begin_inset CommandInset ref", i)
+            if i == -1:
+                break
+            start = i
+            end = find_end_of_inset(document.body, i)
+            if end == -1:
+                document.warning("Malformed LyX document: Can't find end of inset at line %d" % i)
+                i += 1
+                continue
+            # If we are not using hyperref, then we just need to delete the line
+            if not use_hyperref:
+                i = find_token(document.body, "nolink", i, e)
+                if i == -1:
+                    continue
+                del document.body[i]
+                i = e - 1
+                continue
+            # If we are using hyperref, then we'll need to do more.
+            in_inset = True
+            i += 1
+            continue
+        # so we are in an InsetRef
+        if i == end:
+            in_inset = False
+            # If nolink is False, just remove that line
+            if nolink == False or cmd == "formatted":
+                # document.warning("Skipping " + cmd + " " + ref)
+                if nolinkline != -1:
+                    del document.body[nolinkline]
+                continue
+            # We need to construct a new command and put it in ERT
+            newcmd = "\\" + cmd + "*{" + ref + "}"
+            # document.warning(newcmd)
+            newlines = put_cmd_in_ert(newcmd)
+            document.body[start:end+1] = newlines
+            i += len(newlines) - (end - start) + 1
+            # reset variables
+            cmd = ref = ""
+            plural = caps = noprefix = nolink = False
+            nolinkline = -1
+            continue
+        l = document.body[i]
+        if l.startswith("LatexCommand"):
+            cmd = l[13:]
+        elif l.startswith("reference"):
+            ref = l[11:-1]
+        elif l.startswith("caps"):
+            tmp = l[6:-1]
+            caps = (tmp == "true")
+        elif l.startswith("plural"):
+            tmp = l[8:-1]
+            plural = (tmp == "true")
+        elif l.startswith("noprefix"):
+            tmp = l[10:-1]
+            noprefix = (tmp == "true")
+        elif l.startswith("nolink"):
+            tmp = l[8:-1]
+            nolink  = (tmp == "true")
+            nolinkline = i
+        i += 1
+            
+        
+            
+            
+        
 ##
 # Conversion hub
 #
@@ -4622,10 +4697,12 @@ convert = [
            [608, []],
            [609, []],
            [610, []],
-           [611, []]
+           [611, []],
+           [612, []]
           ]
 
-revert =  [[610, []],
+revert =  [[611, [revert_starred_refs]],
+           [610, []],
            [609, [revert_index_macros]],
            [608, [revert_document_metadata]],
            [607, [revert_docbook_mathml_prefix]],
index 210e555c8cd9266607b3d18076ff746c3ebc2554..0b0d32f49b5434ce62bc6dfe922b46bf8121729d 100644 (file)
@@ -124,6 +124,7 @@ Menuset
                OptItem "Plural|a" "inset-modify ref toggle-plural"
                OptItem "Capitalize|C" "inset-modify ref toggle-caps"
                OptItem "No Prefix" "inset-modify ref toggle-noprefix"
+               OptItem "No Hyperlink" "inset-modify ref toggle-nolink"
                Separator
                Item "Settings...|S" "inset-settings"
        End
index eff09173d39cfa82b6312036dc48517d9cc82c9f..d5a551eefae888f4ab16686328a6b403d1987071 100644 (file)
@@ -22,6 +22,7 @@
 #include "Cursor.h"
 #include "FancyLineEdit.h"
 #include "FuncRequest.h"
+#include "PDFOptions.h"
 
 #include "qt_helpers.h"
 
@@ -109,6 +110,8 @@ GuiRef::GuiRef(GuiView & lv)
                this, SLOT(changed_adaptor()));
        connect(noprefixCB, SIGNAL(clicked()),
                this, SLOT(changed_adaptor()));
+       connect(nolinkCB, SIGNAL(clicked()),
+               this, SLOT(changed_adaptor()));
 
        enableBoxes();
 
@@ -142,9 +145,12 @@ void GuiRef::enableBoxes()
        bool const isLabelOnly = (reftype == "labelonly");
        bool const usingRefStyle = buffer().params().use_refstyle;
        bool const intext = bufferview()->cursor().inTexted();
+       bool const hyper_on = buffer().params().pdfoptions().use_hyperref;
        pluralCB->setEnabled(intext && isFormatted && usingRefStyle);
        capsCB->setEnabled(intext && isFormatted && usingRefStyle);
        noprefixCB->setEnabled(intext && isLabelOnly);
+       // disabling of hyperlinks not supported by formatted references
+       nolinkCB->setEnabled(hyper_on && intext && !isFormatted && !isLabelOnly);
 }
 
 
@@ -338,6 +344,7 @@ void GuiRef::updateContents()
        pluralCB->setChecked(params_["plural"] == "true");
        capsCB->setChecked(params_["caps"] == "true");
        noprefixCB->setChecked(params_["noprefix"] == "true");
+       nolinkCB->setChecked(params_["nolink"] == "true");
 
        // insert buffer list
        bufferCO->clear();
@@ -380,6 +387,8 @@ void GuiRef::applyView()
              from_ascii("true") : from_ascii("false");
        params_["noprefix"] = noprefixCB->isChecked() ?
              from_ascii("true") : from_ascii("false");
+       params_["nolink"] = nolinkCB->isChecked() ?
+             from_ascii("true") : from_ascii("false");
        restored_buffer_ = bufferCO->currentIndex();
 }
 
index 0f4a7d351ae5b70f4f59f97ac74358b11bb2311e..a8391e0542bc2488b4f0d04cc0a5faac4927b95a 100644 (file)
        </property>
       </widget>
      </item>
+     <item>
+      <widget class="QCheckBox" name="nolinkCB">
+       <property name="text">
+        <string>No Hyperlink</string>
+       </property>
+      </widget>
+     </item>
      <item>
       <spacer name="horizontalSpacer_2">
        <property name="orientation">
index bff358f13d26bedbbe284d27847a017b4600381a..94b9a2c8a2e7897be9fce2d393e36be3ea1db3b0 100644 (file)
@@ -553,9 +553,11 @@ docstring InsetCommandParams::prepareCommand(OutputParams const & runparams,
 }
 
 
-docstring InsetCommandParams::getCommand(OutputParams const & runparams) const
+docstring InsetCommandParams::getCommand(OutputParams const & runparams, bool starred) const
 {
        docstring s = '\\' + from_ascii(cmdName_);
+       if (starred)
+               s += from_utf8("*");
        bool noparam = true;
        ParamInfo::const_iterator it  = info_.begin();
        ParamInfo::const_iterator end = info_.end();
index 7ed182ae976e8fa0f16941116c296e0a6bf51e86..134b46a6041b90b8ccf48185eeeb283232f9f6e5 100644 (file)
@@ -136,7 +136,7 @@ public:
        ///
        void Write(std::ostream & os, Buffer const * buf) const;
        /// Build the complete LaTeX command
-       docstring getCommand(OutputParams const &) const;
+       docstring getCommand(OutputParams const &, bool starred = false) const;
        /// Return the command name
        std::string const & getCmdName() const { return cmdName_; }
        /// Set the name to \p n. This must be a known name. All parameters
index eab3e69c1c840adc8d79b16ef86c846d4cd00159..ed193f71c79c62fb8d69985447c52cda712a23a9 100644 (file)
@@ -23,6 +23,7 @@
 #include "output_xhtml.h"
 #include "Paragraph.h"
 #include "ParIterator.h"
+#include "PDFOptions.h"
 #include "xml.h"
 #include "texstream.h"
 #include "TocBackend.h"
@@ -74,6 +75,7 @@ ParamInfo const & InsetRef::findInfo(string const & /* cmdName */)
                param_info_.add("plural", ParamInfo::LYX_INTERNAL);
                param_info_.add("caps", ParamInfo::LYX_INTERNAL);
                param_info_.add("noprefix", ParamInfo::LYX_INTERNAL);
+               param_info_.add("nolink", ParamInfo::LYX_INTERNAL);
        }
        return param_info_;
 }
@@ -120,6 +122,8 @@ void InsetRef::doDispatch(Cursor & cur, FuncRequest & cmd)
                        pstring = "caps";
                else if (arg == "toggle-noprefix")
                        pstring = "noprefix";
+               else if (arg == "toggle-nolink")
+                       pstring = "nolink";
                else if (arg == "changetarget") {
                        string const oldtarget = cmd.getArg(2);
                        string const newtarget = cmd.getArg(3);
@@ -170,6 +174,12 @@ bool InsetRef::getStatus(Cursor & cur, FuncRequest const & cmd,
                status.setOnOff(isSet);
                return true;
        }
+       if (arg == "toggle-nolink") {
+               status.setEnabled(params().getCmdName() != "formatted" && params().getCmdName() != "labelonly");
+               bool const isSet = (getParam("nolink") == "true");
+               status.setOnOff(isSet);
+               return true;
+       }
        // otherwise not for us
        return InsetCommand::getStatus(cur, cmd, status);
 }
@@ -250,6 +260,7 @@ void InsetRef::latex(otexstream & os, OutputParams const & rp) const
 {
        string const & cmd = getCmdName();
        docstring const & data = getEscapedLabel(rp);
+       bool const hyper_on = buffer().params().pdfoptions().use_hyperref;
 
        if (rp.inulemcmd > 0)
                os << "\\mbox{";
@@ -259,7 +270,11 @@ void InsetRef::latex(otexstream & os, OutputParams const & rp) const
                // for refstyle, since refstlye's own \eqref prints, by default,
                // "equation n". if one wants \eqref, one can get it by using a
                // formatted label in this case.
-               os << '(' << from_ascii("\\ref{") << data << from_ascii("})");
+               bool const use_nolink = hyper_on && getParam("nolink") == "true";
+               os << '(' << from_ascii("\\ref")   +
+                       // no hyperlink version?
+                       (use_nolink ? from_utf8("*") : from_utf8("")) +
+                       from_ascii("{") << data << from_ascii("})");
        }
        else if (cmd == "formatted") {
                docstring label;
@@ -291,9 +306,10 @@ void InsetRef::latex(otexstream & os, OutputParams const & rp) const
        }
        else {
                InsetCommandParams p(REF_CODE, cmd);
+               bool const use_nolink = hyper_on && getParam("nolink") == "true";
                docstring const ref = getParam("reference");
                p["reference"] = ref;
-               os << p.getCommand(rp);
+               os << p.getCommand(rp, use_nolink);
        }
 
        if (rp.inulemcmd > 0)
@@ -461,6 +477,12 @@ void InsetRef::updateBuffer(ParIterator const & it, UpdateType, bool const /*del
        for (int i = 0; !types[i].latex_name.empty(); ++i) {
                if (cmd == types[i].latex_name) {
                        label = _(types[i].short_gui_name);
+                       // indicate no hyperlink (starred)
+                       if (cmd != "formatted" && cmd != "labelonly") {
+                               bool const isNoLink = getParam("nolink") == "true";
+                               if (isNoLink)
+                                       label += from_ascii("*");
+                       }
                        // indicate plural and caps
                        if (cmd == "formatted") {
                                bool const isPlural = getParam("plural") == "true";
index 3c6693e3150d3cc2d6cc85faacfe3e36059e0a79..001d6cf8c8e2b502b2077e0faa28860b589cac9f 100644 (file)
@@ -34,7 +34,7 @@ Format LaTeX feature                        LyX feature
 443    unicode-math.sty                     InsetMath*
 453    automatic stmaryrd loading           \use_package stmaryrd
 457    automatic stackrel loading           \use_package stackrel
-
+612    starred reference commands
 
 General
 
index bfcd9869aedf325408184b2e7bad75db5d96565c..a643509834c62a3328ef549b7041b74548eef4ce 100644 (file)
@@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 611 // Yuriy Skalko: semantic linefeeds
-#define LYX_FORMAT_TEX2LYX 611
+#define LYX_FORMAT_LYX 612 // RKH & DR: Starred cross-references
+#define LYX_FORMAT_TEX2LYX 612
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER