]> git.lyx.org Git - features.git/commitdiff
Add a document-wide default bibliography style \biblio_style.
authorJulien Rioux <jrioux@lyx.org>
Mon, 12 Dec 2011 14:40:34 +0000 (14:40 +0000)
committerJulien Rioux <jrioux@lyx.org>
Mon, 12 Dec 2011 14:40:34 +0000 (14:40 +0000)
This holds the name of a BibTeX style file for now. Any BibTeX inset
can set the style to "default" to use the document-wide style.

LyX format incremented to 420.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40484 a592a061-630c-0410-9148-cb99ea01b6c8

development/FORMAT
lib/lyx2lyx/lyx_2_1.py
src/BufferParams.cpp
src/BufferParams.h
src/insets/InsetBibtex.cpp
src/version.h

index 965dfd8fe3a490b1e793afc37cc727b5ab6d5175..d133dea45e93ce90b0bfb87aa3346fc1bfbdfb49 100644 (file)
@@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
 
 -----------------------
 
+2011-12-12 Julien Rioux <jrioux@lyx.org>
+       * Format incremented to 420 (r40484)
+         New buffer param \biblio_style to specify a document-wide
+         default bibliography style (BibTeX style for the moment).
+
 2011-12-09 Uwe Stöhr <uwestoehr@web.de>
        * Format incremented to 419 (r40452)
          support for the document languages australian and newzealand
index 15e02ca8f858fbfd7922687d556ba763f0fe750f..fccea99ef748b1392d7f137cffe9a1927cf2aae3 100644 (file)
@@ -25,8 +25,8 @@ import sys, os
 
 # Uncomment only what you need to import, please.
 
-from parser_tools import find_token, find_end_of_inset, get_value, \
-   del_token
+from parser_tools import del_token, find_token, find_end_of_inset, get_value, \
+    get_quoted_value
 
 #from parser_tools import find_token, find_end_of, find_tokens, \
   #find_token_exact, find_end_of_inset, find_end_of_layout, \
@@ -222,6 +222,45 @@ def revert_australian(document):
         j += 1
     
 
+def convert_biblio_style(document):
+    "Add a sensible default for \\biblio_style based on the citation engine."
+    i = find_token(document.header, "\\cite_engine", 0)
+    if i != -1:
+        engine = get_value(document.header, "\\cite_engine", i).split("_")[0]
+        style = {"basic": "plain", "natbib": "plainnat", "jurabib": "jurabib"}
+        document.header.insert(i + 1, "\\biblio_style " + style[engine])
+
+
+def revert_biblio_style(document):
+    "BibTeX insets with default option use the style defined by \\biblio_style."
+    i = find_token(document.header, "\\biblio_style" , 0)
+    if i == -1:
+        document.warning("No \\biblio_style line. Nothing to do.")
+        return
+
+    default_style = get_value(document.header, "\\biblio_style", i)
+    del document.header[i]
+
+    # We are looking for bibtex insets having the default option
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_inset CommandInset bibtex", i)
+        if i == -1:
+            return
+        j = find_end_of_inset(document.body, i)
+        if j == -1:
+            document.warning("Malformed LyX document: Can't find end of bibtex inset at line " + str(i))
+            i += 1
+            return
+        k = find_token(document.body, "options", i, j)
+        if k != -1:
+            options = get_quoted_value(document.body, "options", k)
+            if "default" in options.split(","):
+                document.body[k] = 'options "%s"' \
+                    % options.replace("default", default_style)
+        i = j
+
+
 ##
 # Conversion hub
 #
@@ -233,10 +272,12 @@ convert = [
            [416, []],
            [417, [convert_japanese_encodings]],
            [418, []],
-           [419, []]
+           [419, []],
+           [420, [convert_biblio_style]],
           ]
 
 revert =  [
+           [419, [revert_biblio_style]],
            [418, [revert_australian]],
            [417, [revert_justification]],
            [416, [revert_japanese_encodings]],
index e709cc61679ff16447088179e6bc2282002090d5..38f298c76fa4a0a0a04b2e918ca2fc9e46c30516 100644 (file)
@@ -367,6 +367,7 @@ BufferParams::BufferParams()
        use_mathdots = package_auto;
        use_undertilde = package_auto;
        cite_engine_ = ENGINE_BASIC;
+       biblio_style = "plain";
        use_bibtopic = false;
        use_indices = false;
        trackChanges = false;
@@ -698,6 +699,9 @@ string BufferParams::readToken(Lexer & lex, string const & token,
                string engine;
                lex >> engine;
                cite_engine_ = citeenginetranslator().find(engine);
+       } else if (token == "\\biblio_style") {
+               lex.eatLine();
+               biblio_style = lex.getString();
        } else if (token == "\\use_bibtopic") {
                lex >> use_bibtopic;
        } else if (token == "\\use_indices") {
@@ -1001,6 +1005,7 @@ void BufferParams::writeFile(ostream & os) const
           << "\n\\use_mathdots " << use_mathdots
           << "\n\\use_undertilde " << use_undertilde
           << "\n\\cite_engine " << citeenginetranslator().find(cite_engine_)
+          << "\n\\biblio_style " << biblio_style
           << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
           << "\n\\use_indices " << convert<string>(use_indices)
           << "\n\\paperorientation " << string_orientation[orientation]
index 4a483b99483e156c8026bdab00ba812b1fe03b0c..5432a094efed15104679f7dba910e4caebec5429 100644 (file)
@@ -413,6 +413,9 @@ public:
        ///
        void setCiteEngine(CiteEngine const);
 
+       /// the default BibTeX style file for the document
+       std::string biblio_style;
+
        /// options for pdf output
        PDFOptions & pdfoptions();
        PDFOptions const & pdfoptions() const;
index 9f85e2db6a2445b7a1a0db43a5a3b85098e30410..bd956330d802d213aea1835bf0fdd4858e1577e9 100644 (file)
@@ -336,6 +336,9 @@ void InsetBibtex::latex(otexstream & os, OutputParams const & runparams) const
                        style = split(style, bibtotoc, ',');
        }
 
+       if (style == "default")
+               style = buffer().params().biblio_style;
+
        if (!style.empty()) {
                string base = normalizeName(buffer(), runparams, style, ".bst");
                FileName const try_in_file =
index 3beaf9c4aaddc5517b419cf88b2c20d07211035a..92e2958b44907c6661ad5e63f0176e82fe1e1469 100644 (file)
@@ -30,8 +30,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 419 // uwestoehr: support for the languages australian and newzealand
-#define LYX_FORMAT_TEX2LYX 419
+#define LYX_FORMAT_LYX 420 // jrioux : document-wide bibliography style
+#define LYX_FORMAT_TEX2LYX 420 // jrioux : document-wide bibliography style
 
 #if LYX_FORMAT_FOR_TEX2LYX != LYX_FORMAT_FOR_LYX
 #warning "tex2lyx produces an out of date file format."