Angus Leeming wrote:

> The various natbib citation commands \citet, \citeauthor get translated to
> ERT.


The attached patch fixes that, but:

\citeyearpar[after][before]{article-full}

in lyx becomes

\citeyearpar[before][after]{article-full}

in tex, and tex2lyx translates it to

\citeyearpar[before][after]{article-full}

in lyx. Why are the arguments in lyx reversed? Is this the case for all
LatexCommand insets, or only for citations? IMHO we should change the file
format so that the order is the same in lyx and in tex, the current
situation is confusing. If we do this, tex2lyx does automatically the right
thing ;-)


Georg
Index: src/tex2lyx/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/tex2lyx/ChangeLog,v
retrieving revision 1.53
diff -u -r1.53 ChangeLog
--- src/tex2lyx/ChangeLog	28 Jun 2004 06:53:12 -0000	1.53
+++ src/tex2lyx/ChangeLog	16 Jul 2004 16:13:12 -0000
@@ -1,3 +1,10 @@
+2004-07-16  Georg Baum  <[EMAIL PROTECTED]>
+
+	* preamble.C (handle_package): handle natbib package
+	* text.C: add natbib citation commands to known_latex_commands
+	* preamble.C (handle_package): output packages that have options
+	even if they are handled by lyx to preserve the options
+
 2004-06-28  Georg Baum  <[EMAIL PROTECTED]>
 
 	* math.C, preamble.C, tex2lyx.[Ch], text.C: const fixes
Index: src/tex2lyx/preamble.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/tex2lyx/preamble.C,v
retrieving revision 1.22
diff -u -r1.22 preamble.C
--- src/tex2lyx/preamble.C	28 Jun 2004 06:53:12 -0000	1.22
+++ src/tex2lyx/preamble.C	16 Jul 2004 16:13:12 -0000
@@ -105,6 +105,7 @@
 
 void handle_package(string const & name, string const & options)
 {
+	bool options_handled = false;
 	//cerr << "handle_package: '" << name << "'\n";
 	if (name == "a4wide") {
 		h_papersize = "a4paper";
@@ -121,21 +122,32 @@
 		; // ignore this
 	else if (name == "fontenc")
 		; // ignore this
-	else if (name == "inputenc")
+	else if (name == "inputenc") {
 		h_inputencoding = options;
-	else if (name == "makeidx")
+		options_handled = true;
+	} else if (name == "makeidx")
 		; // ignore this
 	else if (name == "verbatim")
 		; // ignore this
 	else if (is_known(name, known_languages)) {
 		h_language = name;
 		h_quotes_language = name;
-	} else {
-		if (!options.empty())
-			h_preamble << "\\usepackage[" << options << "]{" << name << "}\n";
-		else
-			h_preamble << "\\usepackage{" << name << "}\n";
-	}
+	} else if (name == "natbib") {
+		h_use_natbib = "1";
+		if (options == "authoryear") {
+			h_use_numerical_citations = "0";
+			options_handled = true;
+		} else if (options == "numbers") {
+			h_use_numerical_citations = "1";
+			options_handled = true;
+		}
+	} else if (options.empty())
+		h_preamble << "\\usepackage{" << name << "}\n";
+
+	// We need to output this package even if lyx knows it to preserve
+	// the options
+	if (!options_handled && !options.empty())
+		h_preamble << "\\usepackage[" << options << "]{" << name << "}\n";
 }
 
 
Index: src/tex2lyx/text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/tex2lyx/text.C,v
retrieving revision 1.38
diff -u -r1.38 text.C
--- src/tex2lyx/text.C	28 Jun 2004 06:53:12 -0000	1.38
+++ src/tex2lyx/text.C	16 Jul 2004 16:13:12 -0000
@@ -77,6 +77,8 @@
 namespace {
 
 char const * const known_latex_commands[] = { "ref", "cite", "label", "index",
+// natbib
+"citet", "citep", "citealt", "citealp", "citeauthor", "citeyear", "citeyearpar",
 "printindex", "pageref", "url", "vref", "vpageref", "prettyref", "eqref", 0 };
 
 /// LaTeX names for quotes

Reply via email to