Main part of patch from Daniel, adapted by me.
I also added the lyx2lyx code.
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
#
[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]],
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
#include "Cursor.h"
#include "FancyLineEdit.h"
#include "FuncRequest.h"
+#include "PDFOptions.h"
#include "qt_helpers.h"
this, SLOT(changed_adaptor()));
connect(noprefixCB, SIGNAL(clicked()),
this, SLOT(changed_adaptor()));
+ connect(nolinkCB, SIGNAL(clicked()),
+ this, SLOT(changed_adaptor()));
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);
}
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();
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();
}
</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">
}
-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();
///
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
#include "output_xhtml.h"
#include "Paragraph.h"
#include "ParIterator.h"
+#include "PDFOptions.h"
#include "xml.h"
#include "texstream.h"
#include "TocBackend.h"
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_;
}
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);
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);
}
{
string const & cmd = getCmdName();
docstring const & data = getEscapedLabel(rp);
+ bool const hyper_on = buffer().params().pdfoptions().use_hyperref;
if (rp.inulemcmd > 0)
os << "\\mbox{";
// 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;
}
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)
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";
443 unicode-math.sty InsetMath*
453 automatic stmaryrd loading \use_package stmaryrd
457 automatic stackrel loading \use_package stackrel
-
+612 starred reference commands
General
// 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