]> git.lyx.org Git - lyx.git/commitdiff
Add support for biblatex-apa's \nptextcite
authorJuergen Spitzmueller <spitz@lyx.org>
Thu, 11 Jul 2024 08:28:38 +0000 (10:28 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Thu, 11 Jul 2024 08:28:38 +0000 (10:28 +0200)
lib/citeengines/biblatex-chicago.citeengine
lib/citeengines/biblatex-natbib.citeengine
lib/citeengines/biblatex.citeengine
lib/lyx2lyx/lyx_2_5.py
src/tex2lyx/text.cpp
src/version.h

index dbfc2802eb2d516aabb6db732a594e87d271e3cc..2a5b8171a1d3a2d7a07c311b45f19111cb3e013e 100644 (file)
@@ -29,7 +29,8 @@ MaxCiteNames 3
 # The syntax of the cite command definitions below is:
 # style@LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
 # 
-# * style:    (Optional) citestyle to which this command is specific.
+# * style:    A (comma-separated) list of citestyles to which
+#             this command is specific.
 # * LyXName:  The LyX name as output in the LyX file. For
 #             portability reasons, we try to use the same
 #             name for same-formatted commands in the
@@ -40,7 +41,7 @@ MaxCiteNames 3
 #             This is a bit like "ObsoletedBy" in the layouts.
 # * latexcmd: The actual LaTeX command that is output.
 #
-# Alias and latexcmd are optional. If no latexcmd is given, the
+# Style, alias and latexcmd are optional. If no latexcmd is given, the
 # LyXName will be output to LaTeX.
 #
 # Note further:
index 78d597ba0c6e8e6f635a80df8fb70c21efdf120b..b0848f51080f975b7d7318ee6a424a24d5b94e5f 100644 (file)
@@ -33,7 +33,8 @@ MaxCiteNames 3
 # The syntax of the cite command definitions below is:
 # style@LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
 # 
-# * style:    (Optional) citestyle to which this command is specific.
+# * style:    A (comma-separated) list of citestyles to which
+#             this command is specific.
 # * LyXName:  The LyX name as output in the LyX file. For
 #             portability reasons, we try to use the same
 #             name for same-formatted commands in the
@@ -44,7 +45,7 @@ MaxCiteNames 3
 #             This is a bit like "ObsoletedBy" in the layouts.
 # * latexcmd: The actual LaTeX command that is output.
 #
-# Alias and latexcmd are optional. If no latexcmd is given, the
+# Style, alias and latexcmd are optional. If no latexcmd is given, the
 # LyXName will be output to LaTeX.
 #
 # Note further:
@@ -81,6 +82,7 @@ MaxCiteNames 3
 CiteEngine authoryear
        Citet|textcite*[][]
        Citep|parencite*[][]
+       apa,apa6@nptextcite$[][]
        Citealt|cite*[][]
        Citealp*[][]
        Citeauthor*[][]
@@ -299,6 +301,11 @@ CiteFormat authoryear
 
        # Fallback style: "Author A (cf. Year),[ and] Author B (Year, p. xx)"
        cite %!makecitet%%!textafter%%!close%
+       
+       # Style-specifics
+       # 1. APA
+       # "cf. Author A Year; Author B Year, p. xx"
+       nptextcite %!textbefore%%!makepcite%%!textafter%
 End
 
 CiteFormat numerical
index 00b86691fd3f8508751cc29617c1601df664a81d..c69806d1535982a6bfeaec4385d688c4528297c1 100644 (file)
@@ -29,7 +29,8 @@ MaxCiteNames 3
 # The syntax of the cite command definitions below is:
 # style@LyXName|alias*<!_stardesc!_stardesctooltip>[][]=latexcmd
 # 
-# * style:    (Optional) citestyle to which this command is specific.
+# * style:    A (comma-separated) list of citestyles to which
+#             this command is specific.
 # * LyXName:  The LyX name as output in the LyX file. For
 #             portability reasons, we try to use the same
 #             name for same-formatted commands in the
@@ -40,7 +41,7 @@ MaxCiteNames 3
 #             This is a bit like "ObsoletedBy" in the layouts.
 # * latexcmd: The actual LaTeX command that is output.
 #
-# Alias and latexcmd are optional. If no latexcmd is given, the
+# Style, alias and latexcmd are optional. If no latexcmd is given, the
 # LyXName will be output to LaTeX.
 #
 # Note further:
@@ -75,6 +76,7 @@ CiteEngine authoryear
        Cite$|citealt,citealp[][]
        Citet$[][]=textcite
        Citep$[][]=parencite
+       apa,apa6@nptextcite$[][]
        Citeauthor*<!_citeauthorstar!_citeauthorstartooltip>[][]
        citeyearpar[][]=parencite*
        citeyear[][]=cite*
@@ -285,6 +287,11 @@ CiteFormat authoryear
        footcite {%dialog%[[%_footnote%]][[%_foot%]]}: %!textbefore%%!makecite%%!textafter%.
        # "Auto: (cf. Author A Year; Author B Year, p. xx)"
        autocite {%dialog%[[%_autocite%]][[%_auto%]]}: %!open%%!textbefore%%!makepcite%%!textafter%%!close%
+       
+       # Style-specifics
+       # 1. APA
+       # "cf. Author A Year; Author B Year, p. xx"
+       nptextcite %!textbefore%%!makepcite%%!textafter%
 End
 
 CiteFormat numerical
index 2c90d465d0e88b1a575b1077291ea42ac366891b..3550464cae21868608e8dececf99cc6f42b78324 100644 (file)
@@ -377,6 +377,64 @@ def revert_biblatex_chicago(document):
             document.body[i : j + 1] = put_cmd_in_ert([res])
         i = j + 1
 
+
+def revert_nptextcite(document):
+    """Revert \\nptextcite to ERT"""
+
+    # 1. Get cite engine
+    engine = "basic"
+    i = find_token(document.header, "\\cite_engine", 0)
+    if i == -1:
+        document.warning("Malformed document! Missing \\cite_engine")
+    else:
+        engine = get_value(document.header, "\\cite_engine", i)
+
+    # 2. Do we use biblatex?
+    if engine != "biblatex" and engine != "biblatex-natbib":
+        return
+    
+    # 3. and APA?
+    cetype = "authoryear"
+    i = find_token(document.header, "\\biblatex_citestyle", 0)
+    if i == -1:
+        return
+
+    # 4. Convert \nptextcite 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 == "nptextcite":
+            pre = get_quoted_value(document.body, "before", i, j)
+            post = get_quoted_value(document.body, "after", i, j)
+            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))
+                key = "???"
+            # Replace known new commands with ERT
+            res = "\\nptextcite"
+            if pre:
+                res += "[" + pre + "]"
+            if post:
+                res += "[" + post + "]"
+            elif pre:
+                res += "[]"
+            res += "{" + key + "}"
+            document.body[i : j + 1] = put_cmd_in_ert([res])
+        i = j + 1
+
 ##
 # Conversion hub
 #
@@ -386,11 +444,13 @@ convert = [
     [621, [convert_url_escapes, convert_url_escapes2]],
     [622, []],
     [623, [convert_he_letter]],
-    [624, [convert_biblatex_chicago]]
+    [624, [convert_biblatex_chicago]],
+    [625, []]
 ]
 
 
 revert = [
+    [624, [revert_nptextcite]],
     [623, [revert_biblatex_chicago]],
     [622, []],
     [621, [revert_glue_parskip]],
index 29d5ac73dc7d9d01cc4fb01ef59b8f8994d91b81..c7c86ffef990947cffe843ff1954ab16c82d003b 100644 (file)
@@ -215,7 +215,7 @@ char const * const known_biblatex_commands[] = { "cite", "Cite", "textcite", "Te
 "parencite", "Parencite", "citeauthor", "Citeauthor", "citeyear", "smartcite", "Smartcite",
  "footcite", "Footcite", "autocite", "Autocite", "citetitle", "fullcite", "footfullcite",
 "supercite", "cites", "Cites", "textcites", "Textcites", "parencites", "Parencites",
-"smartcites", "Smartcites", "autocites", "Autocites", 0 };
+"smartcites", "Smartcites", "autocites", "Autocites", "nptextcite", 0 };
 
 /*!
  * biblatex-chicago commands.
index 8cc6144718519173a3e882c73388899cc403fffb..5fea4b14644905d0a509aca6af26852b2362473e 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 624 // spitz: support biblatex-chicago
-#define LYX_FORMAT_TEX2LYX 624
+#define LYX_FORMAT_LYX 625 // spitz: \nptextcite (APA)
+#define LYX_FORMAT_TEX2LYX 625
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER