From 327602d01d0760c4f801f128f8b6e636afe424b7 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Fri, 13 Jan 2017 11:53:22 +0100 Subject: [PATCH] Implement "key only" citation style File format change. --- development/FORMAT | 6 ++++ lib/citeengines/basic.citeengine | 5 ++++ lib/citeengines/biblatex-natbib.citeengine | 8 +++++ lib/citeengines/biblatex.citeengine | 8 +++++ lib/citeengines/jurabib.citeengine | 7 +++++ lib/citeengines/natbib.citeengine | 8 +++++ lib/lyx2lyx/lyx_2_3.py | 35 +++++++++++++++++++++- src/insets/InsetCitation.cpp | 11 ++++++- src/version.h | 4 +-- 9 files changed, 88 insertions(+), 4 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index 37b8eba942..eb60572216 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -7,6 +7,12 @@ changes happened in particular if possible. A good example would be ----------------------- +2017-01-13 Jürgen Spitzmüller + * Format incremented to 529: + \begin_inset CommandInset citation + New LatexCommand value: keyonly -> outputs only the key, + without any cite command. + 2017-01-08 Jürgen Spitzmüller * Format incremented to 528: Biblatex support - New buffer param options: diff --git a/lib/citeengines/basic.citeengine b/lib/citeengines/basic.citeengine index 49e67f4d04..2163641bfe 100644 --- a/lib/citeengines/basic.citeengine +++ b/lib/citeengines/basic.citeengine @@ -26,6 +26,7 @@ DefaultBiblio plain CiteEngine default cite[] nocite + keyonly End @@ -46,6 +47,8 @@ CiteFormat default # _notcited not cited _addtobib Add to bibliography only. + _keyonly Key only. + _key Key # # 2. Macros re-used in the style definitions @@ -80,4 +83,6 @@ CiteFormat default cite %!open%{%dialog%[[#ID]][[%!makecite%]]}%!textafter%%!close% # "Add to bibliography only." (dialog) / "[ID] (not cited)" (button) nocite {%dialog%[[%_addtobib%]][[%key%%!nextkey% (%_notcited%)]]} + # Output only the key + keyonly {%dialog%[[%_keyonly%]][[%_key%: %key%%!nextkey%]]} End diff --git a/lib/citeengines/biblatex-natbib.citeengine b/lib/citeengines/biblatex-natbib.citeengine index 0f8545e531..ffcd9e60af 100644 --- a/lib/citeengines/biblatex-natbib.citeengine +++ b/lib/citeengines/biblatex-natbib.citeengine @@ -48,6 +48,8 @@ MaxCiteNames 3 # # Note further: # +# * The LyXName "keyonly" has a special meaning: only the citation key, +# without any latex command, is output. # * Capitalization indicates that the command also has a capitalized # form (\Latexcmd vs. \latexcmd). These usually enforce upcasing of # name prefixes (von Goethe => Von Goethe). @@ -88,6 +90,7 @@ CiteEngine authoryear fullcite[][] footfullcite[][] nocite + keyonly End CiteEngine numerical @@ -103,6 +106,7 @@ CiteEngine numerical fullcite[][] footfullcite[][] nocite + keyonly End @@ -126,6 +130,8 @@ CiteFormat default # _notcited not cited _addtobib Add to bibliography only. + _keyonly Key only. + _key Key _finaland , and _footnote Footnote _foot Foot @@ -221,6 +227,8 @@ CiteFormat default footfullcite {%dialog%[[%_footnote%]][[%_foot%]]}: {%dialog%[[%_bibentry%]][[{%label%[[%!fullcite%]][[%key%%!nextkey% (%_fullcite%)]]}]]} # "Add to bibliography only." (dialog) / "[ID] (not cited)" (button) nocite {%dialog%[[%_addtobib%]][[%key%%!nextkey% (%_notcited%)]]} + # Output only the key + keyonly {%dialog%[[%_keyonly%]][[%_key%: %key%%!nextkey%]]} End CiteFormat authoryear diff --git a/lib/citeengines/biblatex.citeengine b/lib/citeengines/biblatex.citeengine index 2a473df074..657547e403 100644 --- a/lib/citeengines/biblatex.citeengine +++ b/lib/citeengines/biblatex.citeengine @@ -44,6 +44,8 @@ MaxCiteNames 3 # # Note further: # +# * The LyXName "keyonly" has a special meaning: only the citation key, +# without any latex command, is output. # * Capitalization indicates that the command also has a capitalized # form (\Latexcmd vs. \latexcmd). These usually enforce upcasing of # name prefixes (von Goethe => Von Goethe). @@ -80,6 +82,7 @@ CiteEngine authoryear fullcite[][] footfullcite[][] nocite + keyonly End CiteEngine numerical @@ -94,6 +97,7 @@ CiteEngine numerical fullcite[][] footfullcite[][] nocite + keyonly End @@ -117,6 +121,8 @@ CiteFormat default # _notcited not cited _addtobib Add to bibliography only. + _keyonly Key only. + _key Key _footnote Footnote _foot Foot _fullcite bibliography entry @@ -209,6 +215,8 @@ CiteFormat default footfullcite {%dialog%[[%_footnote%]][[%_foot%]]}: {%dialog%[[%_bibentry%]][[{%label%[[%!fullcite%]][[%key%%!nextkey% (%_fullcite%)]]}]]} # "Add to bibliography only." (dialog) / "[ID] (not cited)" (button) nocite {%dialog%[[%_addtobib%]][[%key%%!nextkey% (%_notcited%)]]} + # Output only the key + keyonly {%dialog%[[%_keyonly%]][[%_key%: %key%%!nextkey%]]} End CiteFormat authoryear diff --git a/lib/citeengines/jurabib.citeengine b/lib/citeengines/jurabib.citeengine index 34f6e07af2..0cf07b9359 100644 --- a/lib/citeengines/jurabib.citeengine +++ b/lib/citeengines/jurabib.citeengine @@ -43,6 +43,8 @@ MaxCiteNames 3 # # Note further: # +# * The LyXName "keyonly" has a special meaning: only the citation key, +# without any latex command, is output. # * Capitalization indicates that the command also has a capitalized # form (\Latexcmd vs. \latexcmd). These usually enforce upcasing of # name prefixes (von Goethe => Von Goethe). @@ -93,6 +95,7 @@ CiteEngine authoryear citeyearpar [][] fullcite [][] nocite + keyonly End # @@ -112,6 +115,8 @@ CiteFormat authoryear # _notcited not cited _addtobib Add to bibliography only. + _keyonly Key only. + _key Key _fullcite bibliography entry _bibentry Bibliography entry. _before before @@ -225,4 +230,6 @@ CiteFormat authoryear fullcite {%dialog%[[%_bibentry%]][[{%label%[[%!fullcite%]][[%key%%!nextkey% (%_fullcite%)]]}]]} # "Add to bibliography only." (dialog) / "Key; Key ... (not cited)" (button) nocite {%dialog%[[%_addtobib%]][[%key%%!nextkey% (%_notcited%)]]} + # Output only the key + keyonly {%dialog%[[%_keyonly%]][[%_key%: %key%%!nextkey%]]} End diff --git a/lib/citeengines/natbib.citeengine b/lib/citeengines/natbib.citeengine index e92209e4c7..49b84138c1 100644 --- a/lib/citeengines/natbib.citeengine +++ b/lib/citeengines/natbib.citeengine @@ -44,6 +44,8 @@ MaxCiteNames 2 # # Note further: # +# * The LyXName "keyonly" has a special meaning: only the citation key, +# without any latex command, is output. # * Capitalization indicates that the command also has a capitalized # form (\Latexcmd vs. \latexcmd). These usually enforce upcasing of # name prefixes (von Goethe => Von Goethe). @@ -75,6 +77,7 @@ CiteEngine authoryear citeyear[] citeyearpar[][] nocite + keyonly End CiteEngine numerical @@ -86,6 +89,7 @@ CiteEngine numerical citeyearpar[][] citeyear nocite + keyonly End @@ -109,6 +113,8 @@ CiteFormat default # _notcited not cited _addtobib Add to bibliography only. + _keyonly Key only. + _key Key # The following are handled by BiblioInfo _etal et al. _namesep , [[separate author names in citation, except for last name]] @@ -155,6 +161,8 @@ CiteFormat default citeyearpar %!open%%!textbefore%%!startlink%%!year%%!endlink%%!nextyear%%!textafter%%!close% # "Add to bibliography only." (dialog) / "[ID] (not cited)" (button) nocite {%dialog%[[%_addtobib%]][[%key%%!nextkey% (%_notcited%)]]} + # Output only the key + keyonly {%dialog%[[%_keyonly%]][[%_key%: %key%%!nextkey%]]} End CiteFormat authoryear diff --git a/lib/lyx2lyx/lyx_2_3.py b/lib/lyx2lyx/lyx_2_3.py index 4c2eedb4de..a2adde7339 100644 --- a/lib/lyx2lyx/lyx_2_3.py +++ b/lib/lyx2lyx/lyx_2_3.py @@ -1369,6 +1369,37 @@ def revert_biblatex(document): ] +def revert_citekeyonly(document): + " Revert keyonly cite command to ERT " + + i = 0 + while (True): + i = find_token(document.body, "\\begin_inset CommandInset citation", i) + if i == -1: + break + j = find_end_of_inset(document.body, i) + if j == -1: + document.warning("Can't find end of citation inset at line %d!!" %(i)) + i += 1 + continue + k = find_token(document.body, "LatexCommand", i, j) + if k == -1: + document.warning("Can't find LatexCommand for citation inset at line %d!" %(i)) + i = j + 1 + continue + cmd = get_value(document.body, "LatexCommand", k) + if cmd != "keyonly": + i = j + 1 + continue + + key = get_quoted_value(document.body, "key", i, j) + if not key: + document.warning("Citation inset at line %d does not have a key!" %(i)) + # Replace known new commands with ERT + document.body[i:j+1] = put_cmd_in_ert([key]) + i = j + 1 + + ## # Conversion hub # @@ -1394,10 +1425,12 @@ convert = [ [525, []], [526, []], [527, []], - [528, []] + [528, []], + [529, []] ] revert = [ + [528, [revert_citekeyonly]], [527, [revert_biblatex]], [526, [revert_noprefix]], [525, [revert_plural_refs]], diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp index 768eb35e8b..cb98aae19b 100644 --- a/src/insets/InsetCitation.cpp +++ b/src/insets/InsetCitation.cpp @@ -508,9 +508,18 @@ void InsetCitation::forOutliner(docstring & os, size_t const, bool const) const // engine, e.g. \cite[]{} for the basic engine. void InsetCitation::latex(otexstream & os, OutputParams const & runparams) const { + BiblioInfo const & bi = buffer().masterBibInfo(); + if (getCmdName() == "keyonly") { + // Special command to only return the key + if (!bi.isBibtex(getParam("key"))) + // escape chars with bibitems + os << escape(cleanupWhitespace(getParam("key"))); + else + os << cleanupWhitespace(getParam("key")); + return; + } vector citation_styles = buffer().params().citeStyles(); CitationStyle cs = asValidLatexCommand(buffer().params(), getCmdName(), citation_styles); - BiblioInfo const & bi = buffer().masterBibInfo(); // FIXME UNICODE docstring const cite_str = from_utf8(citationStyleToString(cs, true)); diff --git a/src/version.h b/src/version.h index 1c9922ffb1..140811fae6 100644 --- a/src/version.h +++ b/src/version.h @@ -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 528 // spitz: biblatex -#define LYX_FORMAT_TEX2LYX 528 +#define LYX_FORMAT_LYX 529 // spitz: keyonly cite type +#define LYX_FORMAT_TEX2LYX 529 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #ifndef _MSC_VER