]> git.lyx.org Git - features.git/commitdiff
Implement "key only" citation style
authorJuergen Spitzmueller <spitz@lyx.org>
Fri, 13 Jan 2017 10:53:22 +0000 (11:53 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Fri, 13 Jan 2017 10:53:22 +0000 (11:53 +0100)
File format change.

development/FORMAT
lib/citeengines/basic.citeengine
lib/citeengines/biblatex-natbib.citeengine
lib/citeengines/biblatex.citeengine
lib/citeengines/jurabib.citeengine
lib/citeengines/natbib.citeengine
lib/lyx2lyx/lyx_2_3.py
src/insets/InsetCitation.cpp
src/version.h

index 37b8eba942a422153a3dcf077085fb302055e060..eb6057221609d443e56246e11f4b5966572a4442 100644 (file)
@@ -7,6 +7,12 @@ changes happened in particular if possible. A good example would be
 
 -----------------------
 
+2017-01-13 Jürgen Spitzmüller <spitz@lyx.org>
+       * 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 <spitz@lyx.org>
        * Format incremented to 528: Biblatex support
          - New buffer param options:
index 49e67f4d04f05bdff30a9485379e5ec8f49150c9..2163641bfef34cf036a7f24428096d32b71fc1d5 100644 (file)
@@ -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
index 0f8545e53165f776d8e8b38bf115cf218224dbb2..ffcd9e60af17765be17568f8e0892b23e48741c2 100644 (file)
@@ -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
index 2a473df074cfda909c2749eab4587bd1cc8e5c0c..657547e403649294afe1770de8f6470fad61b09f 100644 (file)
@@ -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
index 34f6e07af223fc5a2e3415275fb5f6adf8f5c1d9..0cf07b93596826b1878b5f0e6f0221d6e1ae2141 100644 (file)
@@ -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
index e92209e4c7db96c658055895a687547df203afea..49b84138c1dbd88586191568070ef509b005e1df 100644 (file)
@@ -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
index 4c2eedb4dea45f3bed2fc445eb6b753574e28438..a2adde7339a48cebfad4112c61a2e583b77354ff 100644 (file)
@@ -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]],
index 768eb35e8b036eeed4c5a1545da8a09886811707..cb98aae19bedbce0af48e521976df7e46d8bc04d 100644 (file)
@@ -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<CitationStyle> 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));
 
index 1c9922ffb1aef67a8f1d74a3090cd7d00ac48115..140811fae621afc1bf32b19b93a07ddf073028bf 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 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