[LyX/master] Support MLA's \autocite variants

Juergen Spitzmueller spitz at lyx.org
Sat Jul 13 15:33:24 UTC 2024


commit 369c871609638ece498ce0aea3cea9cd4be346c5
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Sat Jul 13 17:32:54 2024 +0200

    Support MLA's \autocite variants
---
 lib/citeengines/biblatex-natbib.citeengine |  8 +++++++-
 lib/citeengines/biblatex.citeengine        |  8 +++++++-
 lib/lyx2lyx/lyx_2_5.py                     | 13 ++++++++++---
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/lib/citeengines/biblatex-natbib.citeengine b/lib/citeengines/biblatex-natbib.citeengine
index c487810b90..7baf77aa61 100644
--- a/lib/citeengines/biblatex-natbib.citeengine
+++ b/lib/citeengines/biblatex-natbib.citeengine
@@ -92,7 +92,8 @@ CiteEngine authoryear
 	citeyear[][]=cite*
 	citebyear[][]=citeyear
 	Footcite$[][]=smartcite
-	Autocite$[][]
+	!mla,mla-strict,mla-new,mla7 at Autocite$|mlaautocite[][]
+	mla,mla-strict,mla-new,mla7 at Mlaautocite|autocite*<!_mlaautocitestar!_mlaautocitetooltip>$[][]=autocite
 	citetitle*<!_citetitlestar!_citetitlestartooltip>[][]
 	!mla,mla-strict,mla-new,mla7 at fullcite[][]
 	footfullcite[][]
@@ -154,6 +155,8 @@ CiteFormat default
 	# GUI strings for the starred commands
 	_citetitlestar F&orce full title[[Possible substitute to All aut&hors]]
 	_citetitlestartooltip Use full title even if shorttitle exists
+	_mlaautocitestar Omit aut&hors[[Possible substitute to All aut&hors]]
+	_mlaautocitestartooltip Omit authors or editors in the citation
 	# The following are handled by BiblioInfo
 	B_etal  et al.
 	B_namesep , [[separate author names in citation, except for last name]]
@@ -314,6 +317,9 @@ CiteFormat authoryear
 	# 1. APA
 	# "cf. Author A Year; Author B Year, p. xx"
 	nptextcite %!textbefore%%!makepcite%%!textafter%
+	# 2. MLA
+	# "Auto: (cf. Author A Year; Author B Year, p. xx)"
+	mlaautocite {%dialog%[[%_autocite%]][[%_auto%]]}: %!open%%!textbefore%%!makepcite%%!textafter%%!close%
 End
 
 CiteFormat numerical
diff --git a/lib/citeengines/biblatex.citeengine b/lib/citeengines/biblatex.citeengine
index 92199df9fc..f039962a40 100644
--- a/lib/citeengines/biblatex.citeengine
+++ b/lib/citeengines/biblatex.citeengine
@@ -84,7 +84,8 @@ CiteEngine authoryear
 	citeyear[][]=cite*
 	citebyear[][]=citeyear
 	Footcite$[][]=smartcite
-	Autocite$[][]
+	!mla,mla-strict,mla-new,mla7 at Autocite$|mlaautocite[][]
+	mla,mla-strict,mla-new,mla7 at Mlaautocite|autocite*<!_mlaautocitestar!_mlaautocitetooltip>$[][]=autocite
 	citetitle*<!_citetitlestar!_citetitlestartooltip>[][]
 	!mla,mla-strict,mla-new,mla7 at fullcite[][]
 	footfullcite[][]
@@ -146,6 +147,8 @@ CiteFormat default
 	_citeauthorstartooltip Force a short author list (using et al.)
 	_citetitlestar F&orce full title[[Possible substitute to All aut&hors]]
 	_citetitlestartooltip Use full title even if shorttitle exists
+	_mlaautocitestar Omit aut&hors[[Possible substitute to All aut&hors]]
+	_mlaautocitestartooltip Omit authors or editors in the citation
 	# The following are handled by BiblioInfo
 	B_etal  et al.
 	B_namesep , [[separate author names in citation, except for last name]]
@@ -300,6 +303,9 @@ CiteFormat authoryear
 	# 1. APA
 	# "cf. Author A Year; Author B Year, p. xx"
 	nptextcite %!textbefore%%!makepcite%%!textafter%
+	# 2. MLA
+	# "Auto: (cf. Author A Year; Author B Year, p. xx)"
+	mlaautocite {%dialog%[[%_autocite%]][[%_auto%]]}: %!open%%!textbefore%%!makepcite%%!textafter%%!close%
 End
 
 CiteFormat numerical
diff --git a/lib/lyx2lyx/lyx_2_5.py b/lib/lyx2lyx/lyx_2_5.py
index 3550464cae..e76bed5d37 100644
--- a/lib/lyx2lyx/lyx_2_5.py
+++ b/lib/lyx2lyx/lyx_2_5.py
@@ -379,7 +379,7 @@ def revert_biblatex_chicago(document):
 
 
 def revert_nptextcite(document):
-    """Revert \\nptextcite to ERT"""
+    """Revert \\nptextcite and MLA's autocite variants to ERT"""
 
     # 1. Get cite engine
     engine = "basic"
@@ -400,6 +400,13 @@ def revert_nptextcite(document):
         return
 
     # 4. Convert \nptextcite to ERT
+    new_citations = {
+        "nptextcite": "nptextcite",
+        "mlaautocite": "autocite",
+        "Mlaautocite": "Autocite",
+        "mlaautocite*": "autocite*",
+        "Mlaautocite*": "Autocite*",
+    }
     i = 0
     while True:
         i = find_token(document.body, "\\begin_inset CommandInset citation", i)
@@ -416,7 +423,7 @@ def revert_nptextcite(document):
             i = j + 1
             continue
         cmd = get_value(document.body, "LatexCommand", k)
-        if cmd == "nptextcite":
+        if cmd in list(new_citations.keys()):
             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)
@@ -424,7 +431,7 @@ def revert_nptextcite(document):
                 document.warning("Citation inset at line %d does not have a key!" % (i))
                 key = "???"
             # Replace known new commands with ERT
-            res = "\\nptextcite"
+            res = "\\" + new_citations[cmd]
             if pre:
                 res += "[" + pre + "]"
             if post:


More information about the lyx-cvs mailing list